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 / 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 / levenshtein.swift
Created Jun 27, 2014
Levenshtein Distance in Swift
View levenshtein.swift
/**
* Levenshtein edit distance calculator
* Usage: levenstein <string> <string>
*
* To compile:
* sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer
* xcrun swift -sdk $(xcrun --show-sdk-path --sdk macosx) levenshtein.swift
*/
import Foundation
@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:
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 / 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 dash_emoji_snippets.sql
INSERT INTO 'snippets' ('title', 'body') VALUES
(':+1:', '👍'),
(':-1:', '👎'),
(':100:', '💯'),
(':1234:', '🔢'),
(':8ball:', '🎱'),
(':a:', '🅰'),
(':ab:', '🆎'),
(':abc:', '🔤'),
(':abcd:', '🔡'),
@bgreenlee
bgreenlee / gist:5305273
Last active Dec 15, 2015
Coalesce a list of overlapping start/end tuples
View gist:5305273
val ranges = List((2,3), (1,2), (5,11), (4,10), (3,3), (6,7), (15,16))
ranges.sorted.foldLeft(List[(Int, Int)]()) { (acc, t) =>
acc match {
case x :: xs if x._2 >= t._1 => (x._1, math.max(x._2, t._2)) :: xs
case x :: xs => t +: acc
case _ => List(t)
}
}.reverse
@bgreenlee
bgreenlee / crontab
Last active Dec 11, 2015
Poor man's Nagios
View crontab
# logtail from logcheck (http://logcheck.org/)
*/15 * * * * /usr/sbin/logtail /path/to/some/log/file.log | egrep "WARN|ERROR|Exception" | head
@bgreenlee
bgreenlee / check_echo_nest.py
Created Dec 20, 2012
Check for available band names from @bwhitman's "Ten Thousand Statistically Grammar-Average Fake Band Names" (http://alumni.media.mit.edu/~bwhitman/10000.html) using The Echo Nest #python #music #fun
View check_echo_nest.py
#!python
import requests
import time
API_KEY = '<YOUR KEY>'
# names saved from http://alumni.media.mit.edu/~bwhitman/10000.html
for name in open("names.txt"):
name = name.strip()
r = requests.get('http://developer.echonest.com/api/v4/artist/profile', params={'api_key': API_KEY, 'name': name})
@bgreenlee
bgreenlee / useful.js
Created Dec 13, 2012
A collection of useful Javascript functions #javascript
View useful.js
// sum an array, optionally providing a function to call on each element of the
// array to retrieve the value to sum
Array.prototype.sum = function(fn) {
return this.reduce(function(accum, elem) {
return accum + (fn ? fn(elem) : elem);
}, 0);
};
// flatten an array
// [1,2,[3,4]] -> [1,2,3,4]