Skip to content

Instantly share code, notes, and snippets.

View dholdren's full-sized avatar

Dean Holdren dholdren

View GitHub Profile
@dholdren
dholdren / slack-custom.css
Created March 20, 2019 14:49
Slack Dark theme from widget-
/*
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 September 18, 2017 21:49
Rails session decoding and CSRF testing
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)
#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 / Default (OSX).sublime-keymap
Created August 2, 2012 21:36 — forked from coldnebo/Default (Linux).sublime-keymap
simple scripts to prettify your xml and json in sublime text 2 - Add files to ~/Library/Application Support/Sublime Text 2/Packages/User
[
{ "keys": ["super+shift+x"], "command": "tidy_xml" },
{ "keys": ["super+shift+j"], "command": "prettify_json" }
]
@dholdren
dholdren / csrf.js
Created September 30, 2015 15:11
CSRF in all ajax requests
$.ajaxSetup( {
beforeSend: function ( xhr ) {
var token = $( 'meta[name="csrf-token"]' ).attr('content');
xhr.setRequestHeader( 'X-CSRF-Token', token );
}
});
@dholdren
dholdren / .slate
Created September 23, 2015 20:20
slate config
# 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 July 16, 2015 19:35
Fun with named parameters
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 July 10, 2015 18:11
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) {
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');
gemset_empty_bug
@dholdren
dholdren / heroku-github-aliases
Created March 17, 2015 16:27
diff production heroku with master
#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'