Skip to content

Instantly share code, notes, and snippets.

View mikesea's full-sized avatar

Mike Chlipala mikesea

View GitHub Profile
startdate=2015-01-01
enddate=`date "+%Y-%m-%d"`
startDateTs=`date -j -f "%Y-%m-%d" $startdate "+%s"`
endDateTs=`date -j -f "%Y-%m-%d" $enddate "+%s"`
dateTs=$startDateTs
offset=86400
while [ "$dateTs" -le "$endDateTs" ]
do
@mikesea
mikesea / gist:9534788
Created March 13, 2014 19:07
keybase.md
### Keybase proof
I hereby claim:
* I am mikesea on github.
* I am mikec (https://keybase.io/mikec) on keybase.
* I have a public key whose fingerprint is 2C4A DC67 30AB 3D41 F41F 8182 A735 F17B 829C D927
To claim this, I am signing this object:
$ irb
irb(main):001:0> if false
irb(main):002:1> foo = "hi"
irb(main):003:1> end
=> nil
irb(main):004:0> foo
=> nil
irb(main):005:0> bar
NameError: undefined local variable or method `bar' for main:Object
from (irb):5
@mikesea
mikesea / newrelic_instrumentation.rb
Created October 25, 2013 16:30
wd_sinatra with NewRelic instrumentation
require 'new_relic/agent/instrumentation/controller_instrumentation'
DependencyDetection.defer do
depends_on do
defined?(WeaselDiesel) && defined?(WeaselDiesel::RequestHandler) &&
WeaselDiesel::RequestHandler.method_defined?(:dispatch)
end
executes do
NewRelic::Agent.logger.debug 'Installing WeaselDiesel instrumentation'
@mikesea
mikesea / iterator_benchmark.rb
Last active December 25, 2015 02:49
Comparing for Array#each against for x in Array
require 'benchmark'
array = (1..1000000).map { rand }
Benchmark.bmbm do |x|
x.report("for:") { for num in array; next; end }
x.report("each:") { array.each { |x| next } }
end
function getNext() {
scan = badgeScans[index];
console.log("got scan " + scan);
if (scan) {
var scanAction = svgContainer.selectAll("g")
.data([scan], function(d){return d.scan_time});
scanAction.exit().remove();
@mikesea
mikesea / caching.rb
Last active December 18, 2015 01:19
caching client-side responses
require 'rest_client'
require 'active_support/cache'
class MyService
def self.find(id)
return unless id.present?
cache("my-service:#{id}", :ttl => 1.day) do
RestClient.get("http://myservice.com/foo/#{id}")
end
@mikesea
mikesea / gist:5548051
Last active December 17, 2015 04:08
determine user's location
on :message, /where\s?is (.+)/ do |m|
nick = m.params[-1][/where\s?is (.+)/, 1]
if nick == @bot.nick
m.reply "#{@bot.nick} is both everywhere and nowhere."
return
end
user = @bot.user_list.find(nick)
@mikesea
mikesea / zshrc
Last active December 17, 2015 01:38
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Aliases
@mikesea
mikesea / location_bot.rb
Created April 27, 2013 20:48
A simple irc bot for telling people where they are.
require 'rubygems'
require 'cinch'
require 'geocoder'
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.channels = ["#super-cool-beans"]
c.nick = "_davebot_"
end