Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Pretty swamped with work-work

Brad Greenlee bgreenlee

💭
Pretty swamped with work-work
View GitHub Profile
@bgreenlee
bgreenlee / boggler.rb
Created Feb 11, 2014
Rather inefficient Boggle puzzle solver
View boggler.rb
#!/usr/bin/env ruby
# Boggle(tm) puzzle solver
# by Brad Greenlee <brad@footle.org>
# (Boggle is a trademark of Hasbro Inc., who has no affiliation with this
# program and hopefully couldn't care less about its existence.)
BOARD_SIZE = 4
MAX_WORD_SIZE = 12
MIN_WORD_SIZE = 3
View keybase.md

Keybase proof

I hereby claim:

  • I am bgreenlee on github.
  • I am bgreenlee (https://keybase.io/bgreenlee) on keybase.
  • I have a public key whose fingerprint is C683 EE62 E928 D6F9 EEB7 9EB3 5545 85A5 A54D 1F04

To claim this, I am signing this object:

@bgreenlee
bgreenlee / loc2tz.py
Last active Aug 29, 2015
Convert a location name to tab-separated place name, lat, lon, and time zone. Adapted from http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
View loc2tz.py
#!/usr/bin/env python
# Convert a location name to tab-separated place name, lat, lon, and time zone.
# Adapted from http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
#
# Installation:
# 1. Get a free Geonames account: http://www.geonames.org/login
# Note: after you confirm your account, you'll need to enable it to use the
# free web service at http://www.geonames.org/manageaccount
# 2. Install/download geopy and geonames libraries:
@bgreenlee
bgreenlee / slack.go
Last active Aug 29, 2015
Bare-bones slash command handler for Slack
View slack.go
package main
/**
* Bare-bones slash command handler for Slack
*
* Commands:
* /weather [city] - Return the current weather for the given city
*/
import (
@bgreenlee
bgreenlee / random_gif.sh
Last active Aug 29, 2015
Post a random gif (with random icon) to a Slack channel
View random_gif.sh
HOOK_URL=https://hooks.slack.com/services/.../.../...
curl -X POST --data-urlencode "payload={\"channel\": \"#random\", \"username\": \"randombot\", \"text\": \"$(curl -s 'http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC' | sed -nE 's/^.*image_original_url":"([^"]+)".*$/\1/gp' | sed 's/\\//g')\", \"icon_emoji\": \":$(curl -s http://www.emoji-cheat-sheet.com/ | sed -n -E 's/^.*<span class="name".*>(.*)<\/span>.*$/\1/gp' | perl -MList::Util -e 'print List::Util::shuffle <>' | head -1):\"}" $HOOK_URL
View snippet.txt
# class to construct conditions for AR queries
# cc = ConditionsConstructor.new('foobar > ?', 7)
# cc.add('blah is not null')
# cc.add('baz in (?)', [1,2,3])
# cc.conditions
# # => ["(foobar > ?) AND (blah is not null) AND (baz in (?))", 7, [1, 2, 3]]
class ConditionsConstructor
def initialize(*args)
add *args unless args.blank?
end
View gist:59103
# base for "smart" constant classes
class OptionSet
def self.[](id)
if id.is_a?(Fixnum)
return local_constants.find {|c| id == const_get(c)}
else
return const_get(id.upcase)
end
end
View gist:123258
require 'open-uri' ; require 'rss/2.0' ; require 'cgi'; require 'openssl'
delicious_user='mattb'
instapaper_user='me@example.com'
instapaper_password='whatever'
$VERBOSE=nil
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE # lame, but effective; can't verify properly w/ open-uri in Ruby 1.8
RSS::Parser.parse(open("http://feeds.delicious.com/v2/rss/network/#{delicious_user}?count=15").read).items.each { |item| open("https://www.instapaper.com/api/add?username=#{instapaper_user}&password=#{instapaper_password}&url=#{CGI.escape(item.link)}&auto-title=1").read }
View isObjectLiteral.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!-- Online here: http://ejohn.org/files/bugs/isObjectLiteral/ -->
<title>isObjectLiteral</title>
<style>
li { background: green; } li.FAIL { background: red; }
iframe { display: none; }
</style>
View isObjectLiteral.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!-- Online here: http://ejohn.org/files/bugs/isObjectLiteral/ -->
<title>isObjectLiteral</title>
<style>
li { background: green; } li.FAIL { background: red; }
iframe { display: none; }
</style>