Skip to content

Instantly share code, notes, and snippets.

Jason Campbell jxson

Block or report user

Report or block jxson

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 _articles_by_month.liquid
<!-- =============================================== -->
<!-- = Quick reference for adding a list of = -->
<!-- = articles by month for a section in Mephisto = -->
<!-- =============================================== -->
<h2>Archive By Month</h2>
{% if section.months.size > 0 %}
<ul class="archive">
{% for month in section.months %}
View activerecord.rb
# Notes on ActiveRecord methods and idioms
# Raises an exception if there is a problem
Model.create!(attrs)
# Returns true or false (no exceptions are raised)
Model.create(attrs)
@jxson
jxson / nested-layout.rb
Created Apr 21, 2009
Rails nested layout example
View nested-layout.rb
# This is an example of how to use nested layouts in rails per the guide:
# http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts
# in app/views/layouts/application.html.erb (instead of the standard yield)
yield(:content) or yield
# in app/views/layouts/special.html.erb
content_for :content do
# content..
end
@jxson
jxson / env.rb
Created Jun 26, 2009
Special before filter for adding logging to cucumber, similar to http://bitly.com/pFAxD
View env.rb
# Special before filter for adding logging to cucumber, similar to http://bitly.com/pFAxD
Before do |scenario|
Rails.logger.info "\n\n Scenario(s): #{scenario.to_sexp[3]}\n#{'-' * 78}"
end
@jxson
jxson / gist:227501
Created Nov 5, 2009 — forked from atmos/gist:227332
Spec for enforcing whitespace
View gist:227501
require File.dirname(__FILE__) + '/spec_helper'
describe "The library itself" do
Spec::Matchers.define :have_no_tab_characters do
match do |filename|
@failing_lines = []
File.readlines(filename).each_with_index do |line,number|
@failing_lines << number + 1 if line =~ /\t/
end
@failing_lines.empty?
@jxson
jxson / post-receive.py
Created Dec 8, 2009
git post-recieve hook for a ci setup using integrity
View post-receive.py
#! /usr/bin/env python
import httplib
conn = httplib.HTTPConnection("http://ci.wherever.com")
conn.request("POST", "/project/builds")
# http://ci.example.org/push/TOKEN
View ruby_191_hacks.rb
# Drop this file in config/initializers to run your Rails project on Ruby 1.9.
# This is three separate monkey patches -- see comments in code below for the source of each.
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects.
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9.
#
# Andre Lewis 1/2010
# encoding: utf-8
View checkout.md

Old way:

$ git checkout -b preandpost_fork_hooks  scotttam/preandpost_fork_hooks
Branch preandpost_fork_hooks set up to track remote branch preandpost_fork_hooks from scotttam.
Switched to a new branch 'preandpost_fork_hooks'

New way:

$ git checkout preandpost_fork_hooks
Branch preandpost_fork_hooks set up to track remote branch preandpost_fork_hooks from scotttam.
View I choo choo choose you.js
// Usage:
//
// $('#the-select').choose('Some Option');
//
// It'll throw an error if the option doesn't exist.
$.fn.choose = function(name) {
var elem = $(this);
if (elem.is(':not(select)')) { return elem; }
var option = elem.find('option').filter(function() {
View grit-example.rb
require 'rubygems'
require 'grit'
include Grit
repo = Repo.new(".git")
head = repo.head
puts "branch: " + head.name
puts "sha: " + head.commit
You can’t perform that action at this time.