Skip to content

Instantly share code, notes, and snippets.

View grimen's full-sized avatar

Jonas Grimfelt grimen

View GitHub Profile
#!/usr/bin/env ruby
puts "Quack, quack!"
One other cause is your :dependent callbacks.
class Blog < AR::Base
has_many :posts, :dependent => :destroy
This will iterate through every post and call #destroy on it. Use :delete_all if you want to just issue a single delete query. HOWEVER, this won't hit your destroy callbacks on Post.
class Blog < AR::Base
has_many :posts
grimen / gist:1290676
Created October 16, 2011 08:49
FAIL: $ stkr start -fv test
$ stkr start -fv test master ‹ruby-1.9.3›
Initializing the environment.
Cloning repositories
Cloning into /Users/grimen/StackRocket/apps/test...
Verifying VM
Importing VM: 99%
Fowarding ssh port 22 -> 2000
Fowarding web port 80 -> 8000
Starting VM
grimen / gist:1397536
Created November 27, 2011 13:08
module CarrierWave
module Smusher
module ClassMethods
def mush( )
process :mush
def mush( )
manipulate! do |img|
(function() {
var v = "1.7.1";
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
grimen / method_missing_example.js
Created May 31, 2012 01:49
Trying to mimic "method missing" in Node.js. Purpose: Allow snake case always. Problem: Don't seem to be possible to forward argument attributes?
var inspect = require('eyes').inspector({
styles: {
all: 'cyan',
label: 'underline',
other: 'inverted',
key: 'bold',
special: 'grey',
string: 'green',
number: 'magenta',
bool: 'blue',
grimen / http_cache.js
Created May 31, 2012 12:43
var connect = require('connect');
var http_cache = {
http_cache_enabled: true,
http_cached: function(req, res, resource, callback) {
if (this.changed(req, res, resource)) {
grimen / caller_path.js
Last active October 6, 2015 08:08
Get caller file path by throwing error and parse the stack trace (in this example for module "rerequire").
var caller_path = undefined; // ...but...but no known native way in Node.js to know what file that triggered the current method.... ='(
try {
// let's break some code of honors! >:)
throw Error();
} catch (err) {
var stack_lines = err.stack.split('\n'),
found_this = false;
grimen / USAGE
Created July 22, 2012 19:11
Vagrant: Upgrade "Guest Additions" for a box.
# -
# -
$ vagrant ssh
vagrant@box:~$ wget -q -O - | sh
$ vagrant halt
$ vagrant package
grimen /
Created July 24, 2012 01:49
Big L holding it down in the term.
echo "I drive up and down harlem blocks, iced out watch. Knots in my socks, cops think I'm selling rocks. Pulling me over too see if I'm drunk. But I'm sober they wouldn't fuck with me if I drove a nova. Listen columbo you're mad because your money come slow. And what you make in a year I make in one show. Now you wanna frisk me and search my ride. Call me all kinda names try to hurt my pride. You're just mad cause I'm a young cat, pockets dumb fat. Talkin bout where the gun at, I been there and done that. I'm through with that illegal life, I'm stayin legit. I love to see cars come cruisin bye and playin my shit. I walk around with six thou' without a pist-al, my whole click's wild. I'm rich pal, no more sticks I'm makin hits now. I drink cristal, I'm through breakin laws. I don't sell coke anymore, I do tours. So get that flashlight out of my face. To bring me down them jakes'll do whatever it takes. Word up them federals got my phone and my house tapped. Praying that I fall for the mouse trap, I doubt that