Skip to content

Instantly share code, notes, and snippets.

View sulf's full-sized avatar

Ulf Schwekendiek sulf

  • San Francisco, CA
View GitHub Profile
@sulf
sulf / add_parse_relation.rb
Created November 3, 2012 00:47
Parse relation generator command line client
#!/usr/bin/env ruby
# Copyright (c) 2012 Ulf Schwekendiek (sulf@me.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
_.extend Backbone.Router.prototype, {
# load a new fragment, replacing the current history entry with the new fragment
# this is used to prevent a back-button-redirect loop
redirect:(fragment) ->
Backbone.history.redirect(fragment)
}
_.extend Backbone.History.prototype, {
redirect:(fragment) ->
frag = (fragment || '').replace(/^#*/, '')
class BackboneViewGenerator < Rails::Generators::NamedBase
def copy_initializer_file
create_file "app/assets/javascripts/desktop/views/#{file_name}.js.coffee", <<-FILE
class App.Views.#{class_name} extends App.Views.MetodayView
template: -> JST['desktop/templates/#{file_name}']
initialize: ->
super
$(@el).addClass('#{file_name}')
@sulf
sulf / gist:1157909
Created August 19, 2011 20:23
Rails helper time_ago_in_words() and distance_of_time_in_words() translated into JavaScript
var distance_of_time_in_words, time_ago_in_words;
time_ago_in_words = function(from_time, include_seconds) {
if (include_seconds != null) {
include_seconds;
} else {
include_seconds = false;
};
return App.distance_of_time_in_words(from_time, Date.now(), include_seconds);
};
distance_of_time_in_words = function(from_time, to_time, include_seconds) {
@sulf
sulf / time.js.coffee
Created August 19, 2011 20:16
Rails helper time_ago_in_words() and distance_of_time_in_words() translated into coffee script. Check out http://apidock.com/rails/ActionView/Helpers/DateHelper/distance_of_time_in_words for the rails documentation.
time_ago_in_words = (from_time, include_seconds) ->
include_seconds ?= false
App.distance_of_time_in_words(from_time, Date.now(), include_seconds)
distance_of_time_in_words = (from_time, to_time, include_seconds) ->
include_seconds ?= false
to_time ?= 0
distance_in_minutes = Math.round(Math.abs(to_time - from_time) / 60 / 1000)
distance_in_seconds = Math.round(Math.abs(to_time - from_time) / 1000)
@sulf
sulf / gist:1082046
Created July 14, 2011 07:02
Coffee Script Backbone.js AutoBind
AutoBind =
auto_bind: ->
funcs = _.functions(@constructor.prototype)
protoFuncs = ['auto_bind', 'constructor'].concat(
_.functions(Backbone.Collection.prototype),
_.functions(Backbone.Model.prototype),
_.functions(Backbone.View.prototype))
_.each funcs, (f) =>
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
> + . print 'e'