Skip to content

Instantly share code, notes, and snippets.

View dholdren's full-sized avatar

Dean Holdren dholdren

View GitHub Profile
@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" }
]
// Style the line numbers, instead of a tiny sliver
.editor .gutter .line-number.git-line-modified {
border-left: none;
padding-left: none;
color: #b58900;
}
.editor .gutter .line-number.git-line-removed {
border-left: none;
padding-left: none;
@dholdren
dholdren / bad_dns_phantom.js
Last active August 29, 2015 13:58
Phantom JS returns html content when there is a DNS failure
var page = require('webpage').create();
var url = "http://nope";
page.onResourceReceived = function(resource) {
console.log('Url: ' + resource.url);
console.log('Code: ' + resource.status);
}
page.open(url, function(status) {
@dholdren
dholdren / tap_alternatives.rb
Last active August 29, 2015 14:02
Ruby Object#tap alternatives
def foo
puts "something"
end
def bar
puts "something else"
end
#current
def pull
transaction_successful?.tap do |success|
@dholdren
dholdren / xmpfilter_example.rb
Created July 10, 2014 19:41
xmpfilter in sublime
#xmpfilter in Sublime Text 2
#Install "Ruby Markers" sublime plugin
#also "gem install rcodetools" (includes xmpfilter)
#Preferences->Package Settings->Ruby Markers->Settings User:
#{
# "check_for_rvm": true,
# "strip_stdout": true
#}
#To evaluate:
@dholdren
dholdren / rspec_hack.rb
Created July 10, 2014 19:43
RSpec hack
#solution for "Get this code to pass RSpec"
require 'rspec'
class Object
def should(*args);end
def should_not(*args);end
def method_missing(method,*args)
if method == :upcase
Object.new
@dholdren
dholdren / slurp_semaphore_commands.sh
Created July 21, 2014 19:08
Pull current commands for your semaphore project (hacky)
function pull_commands() {
#get all projects
project_name_hash_id_map=$(curl -sS -X GET "https://semaphoreapp.com/api/v1/projects?auth_token=${SEMAPHORE_API_TOKEN}" | jq '[.[] | {(.name): .hash_id}] | add')
if [ -z "$project_name_hash_id_map" ]
then
echo "projects call failed"
exit 1
fi
#for each project, get the hash_id of each project
@dholdren
dholdren / stream_and_capture.rb
Created October 6, 2014 13:10
Stream output and capture it and exit status
#Stream output and capture it and exit status as well
require 'open3'
output = ''
exit_status = nil
Open3.popen2e('foobarwhat') {|stdin, stdout_and_stderr, wait_thread|
stdout_and_stderr.each{|line|
puts line
output += line
@dholdren
dholdren / broken_cd.sh
Last active August 29, 2015 14:08
RVM cd broken on a directory with only a Gemfile
#!/bin/bash
set -e
source "$HOME/.rvm/scripts/rvm" #so 'cd' will change gemset when dotfiles present
#setup
rm -rf ~/tmp/dir_with_gemfile
mkdir -p ~/tmp/dir_with_gemfile
echo "source 'https://rubygems.org'" > ~/tmp/dir_with_gemfile/Gemfile
@dholdren
dholdren / map.js
Created December 15, 2014 15:40
map implementations in javascript
Array.prototype.map = function(f) {
res = new Array(this.length);
for (i=0;i < this.length; i++) {
res[i] = f(this[i]);
}
return res;
};
new_a = [1,2,3,4].map(function(ele){ return ele*2; });
console.log("new_a: "+new_a);