Skip to content

Instantly share code, notes, and snippets.

View grimen's full-sized avatar

Jonas Grimfelt grimen

View GitHub Profile
@grimen
grimen / common.conf
Last active August 29, 2015 14:26
$ ./mitmiproxy.sh
port = 8085
#!/usr/bin/env ruby
puts "Quack, quack!"
One other cause is your :dependent callbacks.
class Blog < AR::Base
has_many :posts, :dependent => :destroy
end
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
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
grimen / gist:1397536
Created November 27, 2011 13:08
carrierwave-smusher
module CarrierWave
module Smusher
module ClassMethods
def mush( )
process :mush
end
end
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 = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
@grimen
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
grimen / http_cache.js
Created May 31, 2012 12:43
node-http_cache
require('sugar');
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
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 {
// ...so let's break some code of honors! >:)
throw Error();
} catch (err) {
var stack_lines = err.stack.split('\n'),
found_this = false;
@grimen
grimen / USAGE
Created July 22, 2012 19:11
Vagrant: Upgrade "Guest Additions" for a box.
# SOURCE:
# - http://hedgehogshiatus.com/upgrade-virtualbox-guest-additions-in-a-vargr
# - http://software.darrenthetiger.com/2012/01/installing-virtualbox-guest-additions-on-a-vagrant-lucid64-box
$ vagrant ssh
vagrant@box:~$ wget -q -O - https://raw.github.com/gist/3160742/vagrant-guest_additions-upgrade.sh | sh
$ vagrant halt
$ vagrant package