Skip to content

Instantly share code, notes, and snippets.

@jackwillis
jackwillis / play_radio
Created July 16, 2014 00:32
Streaming RTL-SDR over a network
#!/bin/sh
play -r 32k -t raw -e s -b 16 -c 1 -V1 -
@jackwillis
jackwillis / list_compr.rb
Last active August 29, 2015 14:22
List comprehension look-alike in Ruby
class Hash
# http://stackoverflow.com/a/14881438/3551701
def product
product = values[0].product(*values[1..-1])
product.map {|p| Hash[keys.zip(p)] }
end
end
class Proc
# Better Kernel::system in Ruby
def sys(cmd)
*resp, status = `#{cmd}; echo -n "\n$?"`.lines
[resp.join.chomp, status.to_i]
end
sys("echo foo") #=> ["foo\n", 0]
sys("echo -n foo") #=> ["foo", 0]
sys("false") #=> ["", 1]
@jackwillis
jackwillis / redirect.html
Last active August 29, 2015 14:23
redirect.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Time-based Redirect</title>
<script>
var pageTimes = [
{ begin: "7:30 AM", end: "8:00 AM", href: "http://dfgsdfs" },
{ begin: "8:00 AM", end: "12:00 PM", href: "http://tdddfgdfgdfgs" },

Keybase proof

I hereby claim:

  • I am jackwillis on github.
  • I am jackie (https://keybase.io/jackie) on keybase.
  • I have a public key whose fingerprint is 21BA 259F D30B 002B BABD 1195 57A5 8973 A025 781C

To claim this, I am signing this object:

@jackwillis
jackwillis / concurrent-mini-rake.rb
Last active June 2, 2017 05:34
Concurrent mini-Rake
require 'concurrent'
TASKS = Concurrent::Map.new
class Task
def initialize(ref, dep_refs = [], &action)
@ref = ref
@dep_refs = dep_refs
@promise = Concurrent::Promise.new(&action)
end
@jackwillis
jackwillis / NaiveTime.hs
Created July 28, 2017 01:52
NaiveTime in Haskell
import Data.Monoid
data NaiveTime = NT Int Int deriving (Show, Eq)
instance Monoid NaiveTime where
mempty = NT 0 0
mappend (NT h m) (NT h' m') = NT h'' m''
where h'' = (h + h' + ((m + m') `quot` 60)) `mod` 24
m'' = (m + m') `mod` 60
@jackwillis
jackwillis / RPGPrompt.cabal
Last active July 31, 2017 10:33
RPG-style text prompt
name: RPGPrompt
version: 0.1.0.0
synopsis: RPG-style text prompt
author: Jack Willis
maintainer: jack@attac.us
license: MIT
build-type: Simple
cabal-version: >=1.10
executable RPGPrompt
@jackwillis
jackwillis / flower_external_anatomy.hs
Last active September 14, 2017 17:47
External anatomy of a flower using algebraic data types
module Flower where
-- there's probably mistakes in here, also it is not a serious model of the flower
data Pedicel = Pedicel
data Tepal = Tepal
data Sepal = Sepal
data Petal = Petal
data Perigonium = Perigonium [Tepal]
@jackwillis
jackwillis / Main.hs
Last active October 19, 2017 18:24
OL-Systems in Haskell
module Main where
import OLSystem (OLSystem, buildSystem, stepSystem, axiom)
import Data.Sequence (iterateN)
main = do
let algae = buildSystem "A" [ ('A', "AB"), ('B', "A") ]
print $ axiom <$> iterateN 7 stepSystem algae
-- ["A", "AB", "ABA", "ABAAB", "ABAABABA", "ABAABABAABAAB", "ABAABABAABAABABAABABA"]