Skip to content

Instantly share code, notes, and snippets.

Kyle Fox kylefox

Block or report user

Report or block kylefox

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View haircut.py
# A script to calculate some basic stats on Grant Hutchinson's haircuts.
# See http://splorp.com/about/haircut/
#
# Sample output:
# Number of haircuts since December 22, 1998: 53
# Average days between haircuts: 77
# Shortest time between haircuts was April 10, 1999 to May 25, 1999 (45 days)
# Longest time between haircuts was August 11, 2007 to December 09, 2007 (120 days)
# You'll probably want a haircut in about 63 days (March 08, 2010)
View rfc822.rb
# 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.
View gist:284020
# 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')
View fjhack.html
</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 {
View gist:298919
# 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.
View gist:359204
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\]: '
View site_test.rb
require 'fakefs/safe'
class SiteTest < ActiveSupport::TestCase
def setup
FakeFS.activate!
@site = Factory(:site)
end
def teardown
View admin_helper.rb
# 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
View _menu.html.haml
/ 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
View photo.rb
# 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
You can’t perform that action at this time.