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
View cacophony.php
<?php
if (strpos(`uname`, 'Darwin') === false) {
fwrite(STDERR, "This only works on macOS, sorry.\n");
exit(1);
}
$voices = array_map(
function($voice) {
return (explode(' ', $voice))[0];
@bgreenlee
bgreenlee / crypto.rb
Created Feb 26, 2009
Simple Ruby wrapper for encryption/decryption using OpenSSL
View crypto.rb
class Crypto
# encrypts data with the given key. returns a binary data with the
# unhashed random iv in the first 16 bytes
def self.encrypt(data, key)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.encrypt
cipher.key = key = Digest::SHA256.digest(key)
random_iv = cipher.random_iv
cipher.iv = Digest::SHA256.digest(random_iv + key)[0..15]
encrypted = cipher.update(data)
@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})
View Document.swift
import Cocoa
class Document: NSDocument {
@IBOutlet weak var textField: NSTextField!
var content = ""
override init() {
super.init()
@bgreenlee
bgreenlee / rdio-music-to-code-by-csv
Created Nov 20, 2015
Music to Code By Playlist
View rdio-music-to-code-by-csv
Yppah,Blue Schwinn
Yppah,D. Song
Yppah,R. Mullen
Yppah,Film Burn
Yppah,Never Mess With Sunday
Yppah,Happy to See You
Yppah,Soon Enough
Yppah,Paper Knife
Yppah,Golden Braid
Yppah,Three Portraits
View dash_emoji_snippets.sql
INSERT INTO 'snippets' ('title', 'body') VALUES
(':+1:', '👍'),
(':-1:', '👎'),
(':100:', '💯'),
(':1234:', '🔢'),
(':8ball:', '🎱'),
(':a:', '🅰'),
(':ab:', '🆎'),
(':abc:', '🔤'),
(':abcd:', '🔡'),
@bgreenlee
bgreenlee / multipart_binary_posts.js
Created Sep 17, 2011
Multipart Binary POSTs in Javascript #javascript
View multipart_binary_posts.js
var dataURL = this.canvas.toDataURL(this.getImageType()); // grab the snapshot as base64
var imgData = atob(dataURL.substring(13 + this.getImageType().length)); // convert to binary
var filenameTimestamp = (new Date().getTime());
var separator = "----------12345-multipart-boundary-" + filenameTimestamp;
// Javascript munges binary data when it undergoes string operations (such as concatenation), so we need
// to jump through a bunch of hoops with streams to make sure that doesn't happen
// create a string input stream with the form preamble
View @
#!/bin/bash
# "@Pad"
# An easy commandline time-stamped log/notepad
# Derived from https://web.archive.org/web/20120118122636/http://blog.rubybestpractices.com/posts/jamesbritt/James_will_be_right_back_after_these_interruptions.html
#
# Usage:
# @ something or other - log the timestamped message "something or other"
# @ . - open the @ scratchpad with a new timestamp and
# no message with your default editor
View Default (OSX).sublime-keymap
{ "keys": ["super+f4"], "command": "public_gist_from_selection" }
@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