Skip to content

Instantly share code, notes, and snippets.

View datapimp's full-sized avatar

Jonathan Soeder datapimp

View GitHub Profile
# Takes an string like "deep.nested.value" and an object like window
# and returns the value of window.deep.nested.value. useful for defining
# references on objects which don't yet exist, as strings, which get
# evaluated at runtime when such references will be available
Luca.util.resolve = (propertyReference, source_object)->
return propertyReference unless _.isString(propertyReference)
try
source_object ||= (window || global)
resolved = _( propertyReference.split(/\./) ).inject (obj,key)->
@datapimp
datapimp / gist:3943455
Created October 24, 2012 03:08
Hack for local development of asset pipeline gems
# Add this in a config/initializer within your Rails Project.
# This makes it easy to package your shared javascript and css assets as Rails::Engine
# for use with the asset pipeline, similarly to how jquery-rails works.
#
# In development, it allows you to edit those gems in their normal project folder and get immediate feedback on the asset pipeline changes.
# Without requiring you to ship the assets to whatever you use to host your gem.
# You will need to set ENV['GEM_PROJECT_ROOT'] to something like /Users/datapimp/Projects
@datapimp
datapimp / gist:3801900
Created September 28, 2012 20:19
DOM Manipuluation
class SectionMarkup extends Backbone.Model
html: ()->
@raw = @get("html")
# we will receive html, doctype, html tag and all, and get a parsed version of the contents
# which will include some tags ( title tags, stylesheets, etc ) that we should leave out.
# also we need to adjust the src attribute of the images to point to the server paths
previewContent: ()->
markup = @html()
# So, I have some class defintiions
# written in coffeescript. I am writing
# an app in coffeescript, which reads these files
# on disk. I have access to the coffeescript compiler
# from inside of my app.
class SomeClass
doSomething: ()->
1 + 1 = 2
#
@datapimp
datapimp / luca-application-router-sample.coffee
Created April 11, 2012 13:53
Sample use of Luca.Router and Luca.Application
MyApplication = Luca.Application.extend
initialize: (@options={})->
@router = new Luca.Router(app: @)
@router.bind "change:navigation", ()=>
@updateYourGoogleAnalytics()
Luca.Router = Backbone.Router.extend
routes:
sample = {}
headers = 20.times.collect {|n| "Header #{n}"}
sample = headers.inject({}) do |memo,header|
memo[ header ] = (rand(8).to_i).times.collect {|j| " item #{ j }"}
memo
end
@datapimp
datapimp / git-branch-capistrano-workflow.sh
Created February 16, 2012 17:14
Multi Stage Capistrano Deployment Workflow for your development team
# Everyone should be committing to master, or to their own respective feature branches.
# When it comes time to deploy, you should do the following:
# check out the staging branch
git checkout staging
# sync up with whatever is currently there
git pull origin staging
# merge your master branch into staging
@datapimp
datapimp / general-architecture-considerations.js
Created December 2, 2011 16:13
base architecture for backbone.js / socket.io driven app
(function() {
var Application, LocalStore, SocketManager, StateMachine, Viewport;
/*
There should be a viewport class
which watches over the whole area
of your single page app. global events
can be handled here.
*/
Viewport = Backbone.View.extend({
@datapimp
datapimp / general-architecture-considerations.coffee
Created December 2, 2011 00:03
General Architecture Considerations for a Backbone.js / Socket.IO App
# There should be a viewport class
# which watches over the whole area
# of your single page app. global events
# can be handled here.
Viewport = Backbone.View.extend
el: "#top-most-container"
StateMachine = Backbone.Model.extend
initialize: (@attributes)->
@datapimp
datapimp / gist:1301586
Created October 20, 2011 16:22
Cakefile for watching src, compiling coffee to lib, handling sass etc
{spawn, exec} = require 'child_process'
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
async = require "async"
fs = require "fs"
path = require "fs"
_ = require "underscore"
stdout_handler = (data)->