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($){
# 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.
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"
@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
@gijs
gijs / example-user.js
Created May 4, 2012 10:53 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@tlivings
tlivings / results.md
Last active December 30, 2015 12:59
Node.js outbound SSL testing

Overview

Testing out fedor's SSL enhancements. You don't notice the difference... At first!

Once you adjust ciphers to disable ECDH, then you get the nice surprise.

Test Description

Running an http server that acts as a proxy to an SSL server, all running on localhost.

@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
@adamkirkwood
adamkirkwood / adamkirkwood.sketchpack
Last active April 20, 2017 19:45
Favorite Sketch.app Plugins
{
"name": "Adam Kirkwood's SKetchpack",
"schema_version": "0.1.0",
"locked": false,
"plugins": {
"AnimaApp/auto-layout": {
"name": "auto-layout",
"owner": "AnimaApp",
"version": "0.2.3",
"version_range": [