Skip to content

Instantly share code, notes, and snippets.

@dholdren
dholdren / slack-custom.css
Created Mar 20, 2019
Slack Dark theme from widget-
View slack-custom.css
/*
Copyright 2017 Bryan Keller (https://github.com/widget-)
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@dholdren
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 = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)
sign_secret = key_generator.generate_key(signed_salt)
encryptor = ActiveSupport::MessageEncryptor.new(secret, 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)
Object.instance_method(:method).bind(self).call(name)
end
end
Object.include(ObjectMethod)
@dholdren
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
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
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)
[a,b]
end
#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
dholdren / github.com.js
Created Jul 10, 2015
prevent merge when there's multiple commits in a PR
View github.com.js
var num_commits = parseInt($('#commits_tab_counter').text());
var button = $("div.merge-message > button");
if (num_commits > 1) {
console.log("disabling");
button.attr('disabled','disabled');
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
dholdren / heroku-github-aliases
Created Mar 17, 2015
diff production heroku with master
View heroku-github-aliases
#Usage:
#git heroku-prod-diff #display a diff locally
#git compare-heroku #displays a diff on github, requires hub (https://hub.github.com/)
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
dholdren / custom_gemfile_name.sh
Created Feb 25, 2015
persistent local config of custom gemfile name
View custom_gemfile_name.sh
mkdir -p ~/tmp/testapp
cd ~/tmp/testapp
echo "source 'https://rubygems.org'" >> Gemfile
echo "gem 'rake'" >> Gemfile
ln -sf Gemfile MyGemfile
bundle config --local gemfile ~/tmp/testapp/MyGemfile