Skip to content

Instantly share code, notes, and snippets.

@jkarmel
jkarmel / nodepackages.json
Created April 30, 2012 23:46
Node Packages I like
{
"name": "BamPowLabs",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "2.5.5",
"coffeekup": ">= 0.0.1",
"less": ">= 0.0.1",
"coffee-script": ">= 0.0.1",
"now": ">= 0.0.1",
@jkarmel
jkarmel / CoffeeScript Mxins
Last active December 10, 2015 23:08
CoffeeScript Mixins, so easy to implement.
mixin = (Klass, Mixin) ->
# Class methods
Klass[key] = val for key, val of Mixin
# Instance methods
Klass::[key] = val for key, val of Mixin.prototype
class Mixin
@fn: -> alert "class fn"
fn: -> alert "instance fn"
@jkarmel
jkarmel / gist:4506733
Last active December 10, 2015 23:08
CoffeeScript Mixin Class. Extend it to create mixin functionality.
class Mixin
@mixin: (Klass)->
# Class methods
Klass[key] = val for key, val of @ when key != 'mixin'
# Instance methods
Klass::[key] = val for key, val of @prototype
class Extra extends Mixin
@fn: -> alert 'class fn called'
fn: -> alert 'instance fn called'
@jkarmel
jkarmel / gist:5953626
Created July 9, 2013 00:16
Page thorough git diffs
let x=1
# Repeat this command as much as wanted
let x++ && git diff HEAD~$x HEAD~$[x + 1]
@jkarmel
jkarmel / Cheffile
Last active August 29, 2015 14:02
Hired OS-X Setup
#!/usr/bin/env ruby
site 'http://community.opscode.com/api/v1'
cookbook 'sprout-rbenv',
:github => 'pivotal-sprout/sprout-rbenv'
cookbook 'sprout-ruby',
:github => 'pivotal-sprout/sprout-ruby'
module Profiling
class CallStackTracker
cattr_accessor :query_call_stacks do
[]
end
IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/]
def call(name, start, finish, message_id, values)
# FIXME: this seems bad. we should probably have a better way to indicate
# the query was cached
unless 'CACHE' == values[:name]
module Profiling
class CallStackTracker
cattr_accessor :query_call_stacks do
[]
end
IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/]
def call(name, start, finish, message_id, values)
# FIXME: this seems bad. we should probably have a better way to indicate
# the query was cached
unless 'CACHE' == values[:name]
module Profiler
self.singleton_class.instance_eval do
attr_accessor :defaults
end
self.defaults = {
open: true,
path: 'tmp',
name: 'profile'
}
def self.profile options = {}, &block
module Profiler
self.singleton_class.instance_eval do
attr_accessor :defaults
end
self.defaults = {
open: true,
path: 'tmp',
name: 'profile'
}
def self.profile options = {}, &block
class ActiveRecord::Base
descendants.each do |klass|
klass.singleton_class.instance_eval do
attr_accessor :touches, :touched_by
end
klass.touches = []
klass.touched_by = []
klass.reflections.values.each do |reflection|
if reflection.options && reflection.options[:touch]