This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Assign and request a review from someone for a pull request | |
# Requires GITHUB_OAUTH_TOKEN environment variable | |
pr_url="" | |
pr_url_pattern="https://github.com/(.+)/(.+)/pull/(.+)" | |
while read url | |
do | |
pr_url=$url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Pipe SQL commands to this command to get them in a format ready for a Google Spreadsheet | |
DB=${1-$USER} | |
shift | |
QUERY=$(cat <&0) | |
psql --field-separator=$'\t' --no-align --pset=footer=off -c "$QUERY" "$@" $DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require Bitwise | |
defmodule Circuit do | |
def connect(map, wire) do | |
instruction = Map.get(map, wire) | |
cond do | |
match = Regex.run(~r/^(\d+)$/, instruction) -> | |
[_, value] = match | |
String.to_integer(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test double for a request | |
class RequestDouble | |
attr_accessor :env | |
def initialize hash | |
@env = {} | |
# Turn each hash entry into an instance variable | |
hash.each do |key, value| | |
instance_variable_set "@#{key}", value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
class MockRequest | |
attr_reader :ip, :env | |
def initialize hash | |
@ip = hash[:ip] || '127.0.0.1' | |
@env = hash[:env] || {} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Forgiver < BasicObject | |
attr_reader :arg | |
def initialize arg | |
@arg = arg | |
end | |
def method_missing m, *args, &block | |
arg.respond_to?(m) ? ::Forgiver.new(arg.send(m, *args, &block)) : self | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" | |
#include "SD.h" | |
#include "Wire.h" | |
#define DHTTYPE DHT22 | |
#define DHTPIN 4 | |
DHT dht(DHTPIN, DHTTYPE); | |
File logFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'yard' | |
libs = Hash.new {|hash,key| hash[key] = [] } | |
base = ENV['GEM_PATH'].split(':')[1][%r{^.+(?=/.+@global$)}] rescue nil | |
if base | |
Gem.paths = { | |
'GEM_PATH' => Dir["#{base}/ruby-*"].join(':'), | |
'GEM_HOME' => ENV['GEM_HOME'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sometimes I wish Array#map would take an argument for the index | |
# I usually think about it when I'm working with a CSV file | |
class Array | |
def map(arg=nil, &block) | |
if arg && block_given? | |
self.map(arg).map(&block) | |
elsif arg | |
self.map {|x| x[arg]} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# String#+ appends a string, ¿por qué no los dos? | |
class String | |
def - s | |
self.dup[0...self.rindex(s)||self.length] | |
end | |
end |