Skip to content

Instantly share code, notes, and snippets.

View adtaylor's full-sized avatar

Ad Taylor adtaylor

  • Birmingham, England
View GitHub Profile
@adtaylor
adtaylor / AMD_CoffeeScript_jQuery_Plugin_Pattern.coffee
Created August 9, 2012 14:08
This is an AMD CoffeeScript implementation of Twitter Bootstrap's approach to jQuery plugin development
# ============================================================
# PluginName v0.0.0
# http://URL
# ============================================================
# Copyright 2012 The Beans Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@adtaylor
adtaylor / gist:3264663
Created August 5, 2012 13:06
Adding yadr-customisations using dropbox or google drive
#!/bin/bash
#
# Usage: curl -L https://raw.github.com/gist/3264663/570727e122e8ebec1f6b6cc98fd2ee07d75bf7f9/gistfile1.sh | sh
#
# ad@adtaylor.co.uk
function link_zsh {
ln -s ~/Google\ Drive/yadr-customisations/zsh ~/.yadr/custom/zsh
}
@adtaylor
adtaylor / Celsius_To_Fahrenheit_Converter.coffee
Created July 19, 2012 11:54
http://wevther.com is about the coolest idea I have seen for a while but being from the other side of the pond I couldn't understand the temps in fahrenheit.
# Usage:
# temp_converter.convertTo('f')
# temp_converter.convertTo('c')
temp_converter =
temps: ['.temphigh', '.templow']
currentUnit: 'f'
toCelsius: (f)->
@currentUnit = 'c'
$.ajax({
type: "GET",
url: "/categories.json",
data: {query: { order: "load_order"}}
}).done(function( msg ) {
console.log( "Data: ", msg );
});
@adtaylor
adtaylor / CoffeeScript_jQuery_Plugin_Pattern.coffee
Created April 23, 2012 11:08
This is a CoffeeScript implementation of Twitter Bootstrap's approach to jQuery plugin development
# ============================================================
# PluginName v0.0.0
# http://URL
# ============================================================
# Copyright 2012 The Beans Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
!(( $ ) ->
"use strict"
# CLASSNAME CLASS DEFINITION
# ========================== #
ClassName = ( element, options) ->
process = $.proxy(@.process, this)
$element = if $(element).is('body') then $(window) else $(element)
@adtaylor
adtaylor / channels_controller.coffee
Created March 14, 2012 17:25
Batman Category Problem
edit: (params) ->
@set 'channel', Ems.Channel.find parseInt(params.id), (err) -> throw err if err
Ems.Category.load (err, categories) =>
throw err if err
@set 'categories', categories
console.log 'Categories returned: ', categories
# RETURNS:
#
# > Categories returned: [ Category, Category, Category ]
# Module/Plugin core
# Note: the wrapper code you see around the module is what enables
# us to support multiple module formats and specifications by
# mapping the arguments defined to what a specific format expects
# to be present. Our actual module functionality is defined lower
# down, where a named module and exports are demonstrated.
#
# Note that dependencies can just as easily be declared if required
# and should work as demonstrated earlier with the AMD module examples.
@adtaylor
adtaylor / Responsive-Resize-Event-Handler.js
Created February 23, 2012 11:51
Creates an event,`responsiveResize` , that will fire once the user has finished resizing
// -------------------------- Resize event handler ------------------------------------ //
// Fires an event after resizing has finished
var resizeEvent, resizeTimer = null;
$(window).bind('resize', function() {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(resizeEvent, 100);
});
resizeEvent = function() {
$(window).trigger('responsiveResize');
@adtaylor
adtaylor / object foreach function
Created November 29, 2011 10:20
Comment pulled from node.js google group 'Useful code for "each" on arrays and objects'
// There is *nothing* wrong with changing prototypes in your own code!
// If you're writing a library or framework or a module that has to
// interface with someone else's code then things are a little different,
// but even then some conservative changes can be safe.
// In particular, it's not hard to implement an Object.prototype.forEach
// that works just like Array.prototype.forEach and is very fast.
// See: https://github.com/creationix/proto/blob/master/lib/proto.js#L23-36
// Since it uses Object.defineProperty, the new prototype is not
// enumerable and won't even break people doing for..in loops over
// objects (which is the *slowest* way to iterate over an object)