Instantly share code, notes, and snippets.

View gist:d5be6993921368d7f43a4c83b024b84b
### Keybase proof
I hereby claim:
* I am lukeledet on github.
* I am lukeledet (https://keybase.io/lukeledet) on keybase.
* I have a public key ASAq37AsIe3VPgfrsVdysYG5l1ZDX0Eq4THnSNpL100rVgo
To claim this, I am signing this object:
View assignpr
#!/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
View q
#!/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
View day7.exs
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)
View request_double.rb
# 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
View rack_attack_spec.rb
require 'spec_helper'
class MockRequest
attr_reader :ip, :env
def initialize hash
@ip = hash[:ip] || '127.0.0.1'
@env = hash[:env] || {}
end
end
View forgiver.rb
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
View sketch.ino
#include "DHT.h"
#include "SD.h"
#include "Wire.h"
#define DHTTYPE DHT22
#define DHTPIN 4
DHT dht(DHTPIN, DHTTYPE);
File logFile;
View config.ru
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']
View gist:1686123
# 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