Thursday, November 12, 2009
MySecrets
I developed MySecrets to manages my personal secrets/passwords. I had a lot of fun doing BDD with cucumber. Pickle works very nicely with Machinist to reduce step definition code. I used authlogic for authentication and formtastic to reduce the boiler plate code in my views.
I had some trouble integrating cucumber, pickle, machinist, and authlogic. A user has 0 to many secrets and secrets are protected by authlogic. So cucumber features that needed to add secrets and validate them were a little tricky.
This scenario creates a user, login in, creates a secret, shows the secret, and finally validates the secret.
The show pages are handled with a polymorphic_path.
The actual user creation and login steps are handled here.
The secret is validated with:
All of the coded can be found at http://github.com/perry3819/mysecrets
I had some trouble integrating cucumber, pickle, machinist, and authlogic. A user has 0 to many secrets and secrets are protected by authlogic. So cucumber features that needed to add secrets and validate them were a little tricky.
This scenario creates a user, login in, creates a secret, shows the secret, and finally validates the secret.
The show pages are handled with a polymorphic_path.
The actual user creation and login steps are handled here.
The secret is validated with:
All of the coded can be found at http://github.com/perry3819/mysecrets
pwfoo - Ruby Gem
pwfoo is a gemcutter.org hosted gem that I developed to generate random passwords, score the strength of passwords, and generate random seeds.
Generate password
Determine password strength
The SrandSeedGenerator is interesting because it uses the current time and currently running processes to generate random seeds.
pwfoo can be installed from gemcutter.org.
Generate password
Determine password strength
The SrandSeedGenerator is interesting because it uses the current time and currently running processes to generate random seeds.
pwfoo can be installed from gemcutter.org.
Monday, October 26, 2009
Interval Rails Caching
Feedpoint (source) is a blog aggregator written with Ruby on Rails deployed on a linux server. It retrieves RSS content from blogs and displays them sorted by date at http://feedpoint.hertler.org. Retrieving the RSS content is an expensive step and caching is needed to speed up HTTP requests. Google searching for a way to expire page caching on a timed interval did not yield promising results so I developed a very easy custom strategy through the use of Linux cron jobs.
The Rails code for the page caching is in home_controller.rb.
caches_page and expire_page are ActionController methods. caches_page caches the the :index and :planet_redpoint actions and expire_page expires them.
With this setup, http://feedpoint.hertler.org/home/ will load the :index into page cache and http://feedpoint.hertler.org/home/expire_cache will expire the cache. At this point, monkeys could be trained to navigate to the expire_cache URL every ten minutes or a cron job could be set up. This post will focus on setting up the cron job.
The cron job was configured by entering crontab -e from a terminal and then adding the following line:
This job uses cURL to call the expire_page action every ten minutes. Good cron tutorials are all over the web and beyond the scope of this post.
One added benefit of this approach is that if a blogger is anxious for a recently posted blog to show up on the world famous http://feedpoint.hertler.org site, it can manually be refreshed right away!
The Rails code for the page caching is in home_controller.rb.
caches_page and expire_page are ActionController methods. caches_page caches the the :index and :planet_redpoint actions and expire_page expires them.
With this setup, http://feedpoint.hertler.org/home/ will load the :index into page cache and http://feedpoint.hertler.org/home/expire_cache will expire the cache. At this point, monkeys could be trained to navigate to the expire_cache URL every ten minutes or a cron job could be set up. This post will focus on setting up the cron job.
The cron job was configured by entering crontab -e from a terminal and then adding the following line:
This job uses cURL to call the expire_page action every ten minutes. Good cron tutorials are all over the web and beyond the scope of this post.
One added benefit of this approach is that if a blogger is anxious for a recently posted blog to show up on the world famous http://feedpoint.hertler.org site, it can manually be refreshed right away!
Monday, August 10, 2009
Install mysql gem on OS X 10.5
I had a little trouble installing the mysql gem on OS X 10.5 this morning so I thought I would post the solution.
1) Download the mysql binaries from apple http://support.apple.com/kb/TA25017?viewlocale=en_US
2) Unpack the binaries.
3) sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config (be sure to give an absolute path to the config file)
4) done
1) Download the mysql binaries from apple http://support.apple.com/kb/TA25017?viewlocale=en_US
2) Unpack the binaries.
3) sudo gem install mysql -- --with-mysql-config=
4) done
Monday, July 20, 2009
AES Encryption Wrapper for Ruby
I thought I would share my AES encryption wrapper for Ruby. The attached code utilizes openssl.
require 'openssl' module AESCrypt DEFAULT_CIPHER_TYPE = 'aes-256-cbc' CRYPT_STRUCT = Struct.new(:encrypted_data, :key, :iv) def AESCrypt.encrypt(plain_text, opts={}) cipher = OpenSSL::Cipher::Cipher.new(DEFAULT_CIPHER_TYPE) cipher.encrypt opts.reverse_merge! :key => cipher.random_key, :iv => cipher.random_iv cipher.key = random_key = opts[:key] cipher.iv = random_iv = opts[:iv] encrypted_data = cipher.update(plain_text) encrypted_data << cipher.final CRYPT_STRUCT.new(encrypted_data, random_key, random_iv) end def AESCrypt.decrypt(crypt_struct) cipher = OpenSSL::Cipher::Cipher.new(DEFAULT_CIPHER_TYPE) cipher.decrypt cipher.key = crypt_struct.key cipher.iv = crypt_struct.iv cipher.update(crypt_struct.encrypted_data) + cipher.final end end
This code is pretty straightforward. One thing of interest is that we are using a random AES key and initialization vector on lines 10 and 11 respectively. This results in consumers of this API needing to store the key and initialization vector in order to decrypt, which is why a CRYPT_STRUCT is returned on line 14.
The source and test files are available at the my_password_manager github site.
Monday, July 6, 2009
FirstMem - a tool for verbatim text memorization
I have recently spent some time learning Ruby and Rails. When I learn a new language I typically write an easy application so that the focus is not on solving a particularly difficult problem, but on learning the new technology. To learn Ruby on Rails, I wrote http://firstmem.hertler.org. The code is hosted at http://code.google.com/p/firstmem/
As I was writing the code I was constantly shocked at how little code it took to perform complex tasks and how easy the Rails framework is to learn. It almost felt like cheating!
Subscribe to Posts [Atom]