Skip to content

Instantly share code, notes, and snippets.

View adamhunter's full-sized avatar

Adam Hunter adamhunter

View GitHub Profile
@adamhunter
adamhunter / darksky.py
Created July 11, 2018 02:16
batch download darksky timemachine api
import os
import time
from datetime import datetime, timedelta
from dotenv import load_dotenv, find_dotenv
from urllib.request import urlopen
from concurrent.futures import ThreadPoolExecutor, wait
def main():
print("running!")
load_dotenv(find_dotenv())
echo "commit,reverted" && git log -600 | grep -B 8 'This reverts commit' | awk '/commit/ {if($1 == "This") { printf "%s %s\n", substr($4, 0, length($4) - 1), nextline } else { printf "%s, ", $2 }; }'
@adamhunter
adamhunter / led-blink.py
Created January 8, 2014 02:45
python gpio script to blink led
@adamhunter
adamhunter / wrap.rb
Last active January 2, 2016 01:19
wrapping an ActiveRecord instance in a subclass with more functionality. Given an instance you didn't create (aka current_user, User class), you can get a new instance who's class is the wrapping class. The primary reason to do this is for smaller objects in different parts of your system.
# per sean cribb's suggestion some time ago
User.new.becomes(Super::User) # thanks Rails :)
# below not needed, for reference
User = Class.new(ActiveRecord::Base)
class Super::User < ::User
def self.wrap(user)
@adamhunter
adamhunter / say.rb
Last active December 23, 2015 11:59
using say in ruby
# after pasting the class in speaker.rb into irb, run the following,
# edit to your liking...
@speaker = Speaker.new
# other voices can be found at
# http://www.gabrielserafini.com/blog/2008/08/19/mac-os-x-voices-for-using-with-the-say-command/
@speaker.voice = 'Kathy'
@speaker.what = %[what should i say here?]
# Set Apple Terminal.app resume directory (OS X Lion feature)
if [[ $TERM_PROGRAM == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]] {
# function must be named chpwd so when new tab is opened it will go to the
# current working directory
function chpwd {
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
@adamhunter
adamhunter / application.rb
Last active June 10, 2017 05:02
All that is required to bootstrap a basic rails application for a test suite.
# spec/dummy/config/application.rb
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
require 'rubygems'
require 'bundler'
Bundler.setup
$:.unshift File.expand_path('../../../../lib', __FILE__)
@adamhunter
adamhunter / extconf.rb
Created February 26, 2013 19:00
A Ruby extension that will allow access to instance variables that are set in C and do not begin with an "@".
require 'mkmf'
have_header('ruby.h') or missing('ruby.h')
dir_config("ivar")
create_makefile("ivar")
it "returns the list of possible industries for this account" do
fake_industries = ['Deforester', 'Sludge Distillery'] # Captain Planet hates these
@cavs_api.stub(:industries).and_return(fake_industries)
estimator.industries.should eq(fake_industries)
end
@adamhunter
adamhunter / riak_cache.rb
Created June 20, 2011 16:23
basic read write cache for riak
require 'riak'
class RiakCache
def initialize
@client = Riak::Client.new(:pb_port => 8081, :protocol => :pbc)
@bucket = @client.bucket("riakcache")
end
def read(key)