Skip to content

Instantly share code, notes, and snippets.

View bgreenlee's full-sized avatar

Brad Greenlee bgreenlee

View GitHub Profile
@bgreenlee
bgreenlee / boggler.rb
Created February 11, 2014 23:13
Rather inefficient Boggle puzzle solver
#!/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

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 August 29, 2015 14:02
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
#!/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 August 29, 2015 14:10
Bare-bones slash command handler for Slack
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 August 29, 2015 14:27
Post a random gif (with random icon) to a Slack channel
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
# 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
# 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
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 }
<!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>
<!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>