Skip to content

Instantly share code, notes, and snippets.

View adamkirkwood's full-sized avatar
🏠
Working from home

Adam Kirkwood adamkirkwood

🏠
Working from home
View GitHub Profile
@neerajsingh0101
neerajsingh0101 / jquery_plugin_base.js
Created July 24, 2009 15:43
a jQuery plugin base to create new jQuery plugins
// app.js
$(document).ready(function(){
$('#calendar').calendarize({
param2: 'custom param2'
});
});
//calendarize.js
(function($){
@defunkt
defunkt / mini.rb
Created February 18, 2010 13:29
test/spec/mini 5 - nested contexts, stacked setups
##
# test/spec/mini 5
# http://gist.github.com/307649
# chris@ozmm.org
#
def context(*args, &block)
return super unless (name = args.first) && block
require 'test/unit'
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
def self.test(name, &block)
# include this in application controller
module Authentication
protected
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
end
# Returns true or false if the user is signed in.
@nz
nz / post csv to solr with curl.sh
Created October 21, 2010 22:27
An example of how to POST CSV data to Solr with curl
curl http://index.websolr.com/solr/yourindex/update/csv --data-binary @mydata.csv -H 'Content-type:text/plain; charset=utf-8'
anonymous
anonymous / wait.js
Created December 13, 2010 20:34
Use this function to unlock super-asynchronous goodness
/*
* Creates a callback to be called after multiple functions are done
* Usage:
* var wait = Q.wait(function (params, subjects) {
* // arguments that were passed are in params.user, params.stream
* // this objects that were passed are in subjects.user, subjects.stream
* }, ['user', 'stream]);
* mysql("SELECT * FROM user WHERE user_id = 2", wait.fill('user'));
* mysql("SELECT * FROM stream WHERE publisher_id = 2", wait.fill('stream'));
*
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@gildo
gildo / THEexamples.rb
Created February 8, 2011 15:02
a tiny rest client dressed in a DSL
require './minirest'
on "https://convore.com" do
conf do
@user = "fyskij"
@pass = "mypass"
end
get "/api/account/verify.json"
@txus
txus / serialize_matcher.rb
Created February 24, 2011 10:05
RSpec matcher for serialized ActiveRecord columns
# RSpec matcher to spec serialized ActiveRecord attributes.
#
# Usage:
#
# describe Post do
# it { should serialize(:data) } # serialize :data
# it { should serialize(:registers).as(Array) } # serialize :registers, Array
# it { should serialize(:options).as(Hash) } # serialize :options, Hash
# end
@briancavalier
briancavalier / simple-promise-retry.js
Created February 24, 2011 18:35
A few general patterns for retries using promises
function keepTrying(otherArgs, promise) {
promise = promise||new Promise();
// try doing the important thing
if(success) {
promise.resolve(result);
} else {
setTimeout(function() {
keepTrying(otherArgs, promise);
@mikebaldry
mikebaldry / gist:994924
Created May 27, 2011 09:24
TagCloud map/reduce Mongo Mapper
class TagCloud
MAP = <<-JS
function () {
this.tags.forEach(function (tag) {
emit(tag, 1);
});
}
JS
REDUCE = <<-JS