This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Used like this in your model: validates_format_of :email, :with => RFC822::EmailAddress | |
# | |
# RFC822 Email Address Regex | |
# -------------------------- | |
# | |
# Originally written by Cal Henderson | |
# c.f. http://iamcal.com/publish/articles/php/parsing_email/ | |
# | |
# Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume a Post belongs to a Blog. | |
# Django does this with one SQL statement: | |
posts = Post.objects.filter(blog__name="My Blog") | |
# Rails: | |
posts = Blog.find_by_name("My Blog").posts | |
# Rails? | |
posts = Post.where(:blog__name => 'My Blog') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
</style><!-- Prematurely close the opening <style> tag FJ inserts --> | |
<!-- Add your custom stuff --> | |
<link rel="stylesheet" href="http://example.com/my-custom.css" type="text/css" charset="utf-8" /> | |
<script src="http://example.com/my-awesome-script.js" type="text/javascript" charset="utf-8"></script> | |
<!-- Re-open the <style> tag (FJ will automatically add the closing tag) --> | |
<style type="text/css" media="screen"> | |
#header.container { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PIL Patch to access/retain embedded ICC profiles doesn't save ICC Profiles | |
# when saving the image to a StringIO instead of a file-object. | |
# (patch at http://www.mail-archive.com/image-sig@python.org/msg01936.html) | |
# An Image with an ICC Profile | |
>>> img = Image.open('fuzz.jpg') | |
>>> img.info.has_key('icc_profile') | |
True | |
# Save that same Image to a StringIO and write it to a file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" | |
} | |
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" | |
} | |
export PS1='\[\033[0;35m\]\w\[\033[0;36m\]$(parse_git_branch)\[\e[0m\]: ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fakefs/safe' | |
class SiteTest < ActiveSupport::TestCase | |
def setup | |
FakeFS.activate! | |
@site = Factory(:site) | |
end | |
def teardown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Renders a menu: http://gist.github.com/368818 | |
# Returns a symbol indicating which of the main tabs is active, based on the current controller. | |
def get_main_tab | |
subtab = controller_name.to_sym | |
tab = case subtab | |
when :landing then :home | |
when :users then :users | |
when :exams, :items, :topics then :exams | |
when :pages, :menus, :files, :email_templates then :content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How do I get Paperclip's post processor callbacks to run? | |
# The methods below don't seem to work. | |
# http://groups.google.com/group/paperclip-plugin/browse_thread/thread/d4ee841d5a7e00b2 | |
#################################### | |
# Define `after_post_process` in the model | |
class Photo < ActiveRecord::Base | |
has_attached_file :image | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sweet sugar for jQuery's $.data API. | |
* http://yehudakatz.com/2009/04/20/evented-programming-with-jquery/ | |
* | |
* Instead of this: | |
* | |
* $("#foo").data("foo"); // Get foo | |
* $("#foo").data("foo", 'bar'); // Set foo | |
* | |
* Do this: |