Archive for 'Uncategorized'
Rails 3 console and “no such file to load”
Posted on October 10, 2010, under Uncategorized.
If you happen to load gems in your ~/.irbrc , make sure to add a gem dependency on them in your Rails apps’ Gemfile.
For example, I just started using Awesome Print in IRB. However, when I ran rails console , this error occurred:
no such file to load -- ap
After searching Google, I learned that Awesome Print needs to be listed in my Gemfile . Easy enough:
## ~/.irbrc require 'rubygems' require 'ap' ## ~/src/rails_3_app/Gemfile group :development do gem 'awesome_print' end
Matching Printable Characters
Posted on November 30, 2009, under Coding, GNU/Linux, Uncategorized.
Who doesn’t love regular expressions? They’re fucking awesome. I use’em at least 10 times per day.
Sometimes, there’re restrictions on what patterns you can use. I wanted to change a regex for validating passwords. Originally, it allowed letters, numbers, and a seemingly random collection of special characters. How lame is this?:
^[A-Za-z0-9]{1}[A-Za-z0-9_\\.\\!\@\#\-]{0,255}$
Not only are the allowed special characters arbitrary, but they’re escaping characters in a character class, and using “{1}”.
I tried changing the regex to this:
^[[:print:]]{0,255}$
Unfortunately, that wasn’t considered “valid” by the system in question. Luckily, there’s a fairly concise alternative:
^[\x20-\x7E]{0,255}$
If you find a system that lacks support for POSIX character classes, check out this Wikipedia article.