Skip to content

Instantly share code, notes, and snippets.

@larryfox
larryfox / playing
Created April 29, 2016 01:15
Get info about the currently playing iTunes track
#!/usr/bin/env bash
read -r -d '' JS <<JS
function run () {
var iTunes = Application("iTunes")
if (!iTunes.running()) { return JSON.stringify({ state: "closed" }) }
var state = iTunes.playerState()
if ('stopped' === state) { return JSON.stringify({ state: state }) }
@larryfox
larryfox / licenses.rb
Last active April 25, 2016 20:30
Get gem licenses
File.open('licenses.txt', 'w+') do |io|
Dir.glob('.gem/**/*LICENSE*').map do |filename|
io.write("====================================\n")
io.write("#{filename}\n")
io.write("====================================\n\n")
io.write File.read(filename)
io.write("\n\n\n\n")
end
end

Keybase proof

I hereby claim:

  • I am larryfox on github.
  • I am lf (https://keybase.io/lf) on keybase.
  • I have a public key whose fingerprint is 6222 C240 686D 89D2 A1EC 9750 DE0A 9991 8B8F 7E5D

To claim this, I am signing this object:

module EuclideanRhythm
export euclideanrhythm
typealias Bits BitArray{1}
one() = ~Bits(1)
zero() = Bits(1)
flatten(m::Array{Bits}) = reduce(vcat, m)
@larryfox
larryfox / sample-chain
Last active August 29, 2015 14:22
Generate sample chains for use with the Elektron Octatrack
#!/usr/bin/env ruby
require 'pathname'
def run_cmd(*cmd)
io = IO.popen cmd.map(&:to_s)
io.read.chomp
end
class Sample
include Comparable
@larryfox
larryfox / yes.rs
Last active August 29, 2015 14:20
yes(1) in Rust
use std::env;
fn main() {
let args: Vec<_> = env::args().skip(1).collect();
let yes = args.connect(" ");
if yes.is_empty() {
loop {
println!("y");
}
@larryfox
larryfox / adjacency-list.swift
Last active March 6, 2022 04:21
Adjacency list in Swift
// Found this lying around in my code folder from when I was
// first playing with Swift. Consider it public domain.
struct Graph<T: Hashable> {
let directed: Bool
var adj = Dictionary<T, [T]>()
init(directed d: Bool) {
directed = d
}
@larryfox
larryfox / floyd_warshall.jl
Last active August 29, 2015 14:04
Floyd-Warshall and path reconstruction.
typealias Edge (Int,Int)
typealias Vertex Int
function floyd_warshall(V::Set{Vertex}, E::Set{Edge}, C::Dict{Edge,Real})
n = length(V)
A = fill(Inf, n, n)
N = cell(n, n)
for v in V
A[i,i] = 0
if isinteractive()
repl = Base.active_repl
repl.interface = Base.REPL.setup_interface(repl)
repl.interface.modes[1].first_prompt = \
repl.interface.modes[1].prompt = " \U2234 "
end
function knapsack(v, w, capacity)
n = length(v) + 1
capacity += 1
A = zeros(Int, n, capacity)
for j in 1:capacity, i in 2:n
A[i,j] = if w[i-1] < j
max(
A[i-1, j],
A[i-1, j-w[i-1]] + v[i-1]