Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile
# 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.
# 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')
</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 {
# 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.
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\]: '
require 'fakefs/safe'
class SiteTest < ActiveSupport::TestCase
def setup
FakeFS.activate!
@site = Factory(:site)
end
def teardown
# 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
/ get_main_tab is defined in http://gist.github.com/368812
- @tab, @subtab = get_main_tab
#header
.container
%ul#nav.hmenu
%li{:class => @tab == :home ? 'current' : ''}= link_to t('nav.home'), admin_landing_path
%li{:class => @tab == :users ? 'current' : ''}= link_to t('nav.users.tab'), admin_users_path
%li{:class => @tab == :exams ? 'current' : ''}= link_to t('nav.exams.tab'), admin_exams_path
# 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
/*
* 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: