Skip to content

Instantly share code, notes, and snippets.

View jedschneider's full-sized avatar

Jed Schneider jedschneider

View GitHub Profile
class Mustachio extends Backbone.View
render: (template_id, context) ->
@templates[template_id].call @, context
@prepare = ->
templates = {}
raw_templates = $('script[type="text/x-handlebars-template"]')
raw_templates.each (i, template) ->
$template = $(template)
// Generated by CoffeeScript 1.3.3
utensils.Bindable = (function() {
function Bindable(context, dataKey) {
if (context == null) {
context = $('body');
}
this.dataKey = dataKey != null ? dataKey : 'bindable';
this.bindables = $("[data-" + this.dataKey + "]", context);
window.utensils = {}
@jedschneider
jedschneider / gist:5434068
Created April 22, 2013 11:29
Abstract for my talk at ConvergeSE

Detangle your jQuery:

using lessons from CoffeeScript to create better design

Despite the explosion of tools and MVC frameworks for JavaScript, jQuery remains the dependency of dependencies for almost every browser based web application. And yet, for most of us, our use of jQuery tends to create the code with the most painful, rambling, and troublesome design.

This is a talk about using CoffeeScript's native language constructs to apply what we have learned from frameworks and tools like Backbone and Bootstrap. Solutions that promise us a better experience, retain relevance and clarity in our code, and respond more easily to change.

# using each with object, no return necessary
irb(main):003:0> [:first_name, :last_name].each_with_object({}) {|x, m| m[x] = x }
=> {:first_name=>:first_name, :last_name=>:last_name}
irb(main):004:0>
# using inject
# doesn't work, without expressly returning memo
irb(main):001:0> [:first_name, :last_name].inject({}){|m, x| m[x] = x }
NoMethodError: undefined method `[]=' for :first_name:Symbol
from (irb):1:in `block in irb_binding'
@jedschneider
jedschneider / .cook
Created August 5, 2012 01:04 — forked from gvarela/.cook
default developer image
{
"imagemagick": {"ghostscript": true},
"redis": {"launchd": true},
"rbenv": {"versions": ["1.9.3-p194"]},
"basic_brew": {"formulae": [
"bash-completion",
"wget",
"android-sdk"
]},
@jedschneider
jedschneider / .cook
Created August 5, 2012 01:01 — forked from gvarela/.cook
default developer image
{
"imagemagick": {"ghostscript": true},
"redis": {"launchd": true},
"rbenv": {"versions": ["1.9.3-p194"]},
"basic_brew": {"formulae": [
"bash-completion",
"wget",
"android-sdk"
]},
pricing_setup :
rates :
federal : "federal"
college : "federal"
federal : 0.6
pricing_setup[pricing_setup.rates["college"]]
@jedschneider
jedschneider / advance_date.coffee
Created June 27, 2012 17:37
advance a date object and deliver obis-common style
# advances date x days and formats as if it is coming from
# obis-common date validated attributes YYYY-MM-DD
# clones the passed in date such to avoid mutating the original.
advance_date: (date, days=0)->
assert date instanceof Date, "date needs to be a Date object"
assert typeof days == 'number', "days need to be an Integer"
d = new Date(date)
d.setDate(d.getDate() + days)
cast_by_two = (v)->
if v < 10 then "0#{v}" else v
@jedschneider
jedschneider / gh-pages-tips.md
Created June 7, 2012 17:59
github pages tips for jekyll wiki

Working With Github Pages

The FAQ maintained by Github covers most stumbling blocks, some other tips and tricks supplied here.

Gitignore

Add _site to .gitignore. The generated site should not be uploaded to Github since its gets generated by github.

Working With Code Partials