Skip to content

Instantly share code, notes, and snippets.

View bgreenlee's full-sized avatar

Brad Greenlee bgreenlee

View GitHub Profile
@bgreenlee
bgreenlee / check_echo_nest.py
Created December 20, 2012 02:06
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
#!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 / crontab
Last active December 11, 2015 19:59
Poor man's Nagios
# logtail from logcheck (http://logcheck.org/)
*/15 * * * * /usr/sbin/logtail /path/to/some/log/file.log | egrep "WARN|ERROR|Exception" | head
@bgreenlee
bgreenlee / gist:5305273
Last active December 15, 2015 18:39
Coalesce a list of overlapping start/end tuples
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
INSERT INTO 'snippets' ('title', 'body') VALUES
(':+1:', '👍'),
(':-1:', '👎'),
(':100:', '💯'),
(':1234:', '🔢'),
(':8ball:', '🎱'),
(':a:', '🅰'),
(':ab:', '🆎'),
(':abc:', '🔤'),
(':abcd:', '🔡'),
@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 / levenshtein.swift
Created June 27, 2014 05:54
Levenshtein Distance in 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 / 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 / flashScreen.swift
Created April 1, 2015 23:31
Flashing the screen in Swift. Sticking this here because it took me a while to work out the right variable types and casting.
func flashScreen() {
let inDuration: CGDisplayFadeInterval = 0.5
let outDuration: CGDisplayFadeInterval = 0.5
let color = NSColor.redColor()
var fadeToken: CGDisplayFadeReservationToken = 0
let colorToUse = color.colorUsingColorSpaceName(NSCalibratedRGBColorSpace)!
let err = CGAcquireDisplayFadeReservation(inDuration + outDuration, &fadeToken)
if Int(err) != Int(kCGErrorSuccess.value) {
NSLog("Error acquiring fade reservation")