Skip to content

Instantly share code, notes, and snippets.

View jedschneider's full-sized avatar

Jed Schneider jedschneider

View GitHub Profile
@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.

class InsertionSort
def initialize(list)
@list = list
@sorted = []
end
def sort
insert(@list.shift) while @list.length > 0
@sorted
end
# 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
{% highlight javascript %}
{% include fxmanager.js %}
{% endhighlight %}
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
{% include attributes.js %}
{% include my_ob.js %}
{% include populate.js %}
{% include fxmanager.js %}
ServiceRequest = Backbone.Model.extend
initialize: (attrs) ->
# Is there a simple way to extract this pseudo-model functionality
# into a superclass?
_.bindAll @, 'set_line_items',
@bind('change', @set_line_items)
@set_line_items()
set_line_items: ->
if(@attributes.line_items and not(@line_items instanceof LineItemList))
Backbone.Collection.define_extension 'ordered_by_attribute', (klazz) ->
klazz::comparator = (model) -> (model.get('order') || 99999)