Skip to content

Instantly share code, notes, and snippets.

dholdren / slack-custom.css
Created Mar 20, 2019
Slack Dark theme from widget-
View slack-custom.css
Copyright 2017 Bryan Keller (
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
dholdren / rails_session_decoding.rb
Last active Sep 18, 2017
Rails session decoding and CSRF testing
View rails_session_decoding.rb
def decrypt_session(session_cookie)
secret_key_base = Rails.application.secrets.secret_key_base
cookie = CGI::unescape(session_cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator =, iterations: 1000)
secret = key_generator.generate_key(salt)
sign_secret = key_generator.generate_key(signed_salt)
encryptor =, sign_secret)
View call_original_method_method.rb
#I want to call @request.method(:remote_ip) to find out where it's defined using Object#method method.
#But that's been overriden so that you can find out which HTTP verb was used (GET/POST/etc)
module ObjectMethod
def object_method(name)
dholdren / csrf.js
Created Sep 30, 2015
CSRF in all ajax requests
View csrf.js
$.ajaxSetup( {
beforeSend: function ( xhr ) {
var token = $( 'meta[name="csrf-token"]' ).attr('content');
xhr.setRequestHeader( 'X-CSRF-Token', token );
dholdren / .slate
Created Sep 23, 2015
slate config
View .slate
# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config windowHintsShowIcons true
#config windowHintsIgnoreHiddenWindows false
config windowHintsDuration 4
dholdren / named_and_not_params.rb
Created Jul 16, 2015
Fun with named parameters
View named_and_not_params.rb
def foo(x=nil, a: x, b: nil)
#one, un-named arg assigns to a
foo("a val") # => ["a val", nil]
#named parameter "a" assigns to a
foo(a: "a val") # => ["a val", nil]
dholdren /
Created Jul 10, 2015
prevent merge when there's multiple commits in a PR
var num_commits = parseInt($('#commits_tab_counter').text());
var button = $("div.merge-message > button");
if (num_commits > 1) {
button.text("Squash those commits!");
div = $("div.merge-message");
div.append("<button class='btn btn-primary' id='enable_merge' style='float:right;' type='button'>Override</button>");
enable_button = $('button#enable_merge');
dholdren / heroku-github-aliases
Created Mar 17, 2015
diff production heroku with master
View heroku-github-aliases
#git heroku-prod-diff #display a diff locally
#git compare-heroku #displays a diff on github, requires hub (
heroku-prod-deployed-commit = !sh -c 'heroku releases -r production | grep Deploy | tr -s \" \" | cut -d \" \" -f 3 | head -n 1' -
heroku-prod-diff = !sh -c 'git diff $(git heroku-prod-deployed-commit)..master'
#requires hub
compare-heroku = !sh -c 'hub compare $(git heroku-prod-deployed-commit)..master'
dholdren /
Created Feb 25, 2015
persistent local config of custom gemfile name
mkdir -p ~/tmp/testapp
cd ~/tmp/testapp
echo "source ''" >> Gemfile
echo "gem 'rake'" >> Gemfile
ln -sf Gemfile MyGemfile
bundle config --local gemfile ~/tmp/testapp/MyGemfile