Skip to content

Instantly share code, notes, and snippets.

View mguterl's full-sized avatar

Mike Guterl mguterl

View GitHub Profile
class ApplicationController < ActionController::Base
# various html/form generation shortcuts
#
def authenticity_token
@authenticity_token || helper.form_authenticity_token
end
helper_method :authenticity_token
end
@jimweirich
jimweirich / fic
Created March 15, 2011 21:46
Find in Code
#!/usr/bin/env ruby
# -*- ruby -*-
begin
require 'rubygems'
rescue LoadError
end
exts = ['.rb', '.rhtml', '.erb', '.builder', '.haml', '.css', '.coffee' ]
if ARGV[0] =~ /^(\+|\.[a-zA-Z0-9]+)$/

Run this closure as a patch to jQuery.fn.show to make it fire an event when called:

(function(show) { jQuery.fn.show = function() { return show.apply(this, arguments).trigger('showing'); } })(jQuery.fn.show)

E.g.:

$('h1:first')
  .bind('showing', function() { console.log('yeah'); });
  .hide()

.show();

@tobi
tobi / gist:911797
Created April 9, 2011 21:32
wtf.js
var ary = ['a', 'b', 'c'];
var funcs = [];
for (var i = 0; i < ary.length; i++) {
var c = ary[i]
funcs.push(function() { console.log(c) })
};
for (var i = 0; i < funcs.length; i++) {
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
@searls
searls / jasmine-ajax-example-spec.coffee
Created April 28, 2011 16:32
A simple Jasmine Ajax spying example
window.context = window.describe
describe ".googlePandaStatus", ->
Given -> @ajaxCaptor = jasmine.captor()
Given -> spyOn($, "get")
When -> googlePandaStatus("Happy")
And -> expect($.get).toHaveBeenCalledWith("http://google.com", @ajaxCaptor.capture())
describe "~ the AJAX success handler", ->
Given -> spyOn(window, "printMessage")
# load a gem/lib into irb in a way that is durable to bundler LOAD_PATH
# hackery
#
# inspired by
# https://github.com/aniero/dotfiles/blob/master/irbrc#L4-35
#
# IRB.gem('irbcp')
# IRB.gem('awesome_print', :lib => 'ap')
#
@bobbrez
bobbrez / gist:993344
Created May 26, 2011 15:15
MySQL on OS X using Homebrew

Change Permissions

You'll need to change the permissions for /usr/local for your local user.

sudo chown -R whoami /usr/local

Homebrew

The easiest way to get everything setup is to use Homebrew. To do this, you'll need to first install XCode from the standard XCode from Apple Developer site. Afterwards you can just install Homebrew though its normal installation

ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"

@avdi
avdi / throw-catch.rb
Created July 11, 2011 05:55
throw/catch demo code for RubyLearning article
require 'rubygems'
require 'mechanize'
MAX_PAGES = 6
def each_google_result_page(query, max_pages=MAX_PAGES)
i = 0
a = Mechanize.new do |a|
a.get('http://google.com/') do |page|
search_result = page.form_with(:name => 'f') do |search|
# to use this limited full-text search facility in your mongo models just do
#
# class Page
#
# include Search::Mixin
#
# search :fields => %w( title description )
#
# after_save do |doc|
# Search.index! doc