Skip to content

Instantly share code, notes, and snippets.

@Jach
Jach / jukebox.sh
Last active January 21, 2017 23:37
Shell-based jukebox with mpv and json ipc handling single commands like q for quit, p for pause. Requires socat.
#!/bin/sh
rm /tmp/fifo
mkfifo /tmp/fifo
mdir='/mnt/media/music/ /home/kevin/Desktop/some_sound/'
filter='(\.jpg|\.png|\.bmp|\.m3u|\.ini)'
function maybe_filter() {
while read -r -d $'\0' input; do
if [[ $input == *tons_of_video_game_music* ]]; then
if [ $RANDOM -lt 16384 ]; then
@Jach
Jach / sieve.py
Created February 7, 2012 18:43
Incremental Sieve of Eratosthenes
'''
Python implementation of Haskell's
sieve xs = sieve' xs Map.empty
where
sieve' [] table = []
sieve' (x:xs) table =
case Map.lookup x table of
Nothing -> x : sieve' xs (Map.insert (x*x) [x] table)
Just facts -> sieve' xs (foldl reinsert (Map.delete x table) facts)
@Jach
Jach / ai.clj
Created March 16, 2012 14:52
Recursive self-improving AI!
; pro-tip: run "java -jar clojure.jar ai.clj >> ai.clj" for infinite fun!
(println ((fn [x y] (list (quote println) (list x (list (quote quote) x) (inc y)))) (quote (fn [x y] (list (quote println) (list x (list (quote quote) x) (inc y))))) 1))
@Jach
Jach / audio_trigger.py
Created August 28, 2013 01:33
Trigger on audio
'''
Repeatedly run a command if the system records a sound loud enough.
Requires PyAudio and Numpy.
Windows users:
win32 Python 2.7: http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi
Numpy: http://sourceforge.net/projects/numpy/files/NumPy/1.7.1/numpy-1.7.1-win32-superpack-python2.7.exe/download
PyAudio: http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.7.py27.exe
'''
import os
@Jach
Jach / gist:6b82fb57bf0bc13937be
Last active August 29, 2015 14:03
REPL commands using clj-webdriver to get my tweets
; See revision version 1 for non-phantomJS version, setup phantomJS here: http://blog.zolotko.me/2012/12/clojure-selenium-webdriver-and-phantomjs.html
(use 'clj-webdriver.taxi)
(import 'org.openqa.selenium.phantomjs.PhantomJSDriver
'org.openqa.selenium.remote.DesiredCapabilities)
(use '[clj-webdriver.driver :only [init-driver]])
; skip this section until 'lawl' comment
(use '[clj-webdriver.core :only [execute-script*]])
@Jach
Jach / .vimrc
Last active August 29, 2015 14:04
My master .vimrc. It needs to be cleaned up, but meh.
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O><F2>
set pastetoggle=<F2>
set incsearch
set ignorecase
set smartcase
set scrolloff=2
set wildmode=longest,list
set showcmd
@Jach
Jach / show_retweets.py
Created September 25, 2014 04:47
Print out all the retweets you made. Download your twitter data backup, go into the data/js/tweets folder and run this script.
import json
import glob
files = glob.glob('*.js')
data = {}
for f in files:
file = open(f)
_ = file.readline()
data[f] = json.loads(file.read())
@Jach
Jach / sevseg.cljs
Created October 24, 2015 01:29
cljs code for a seven segment display example from http://www.thejach.com/view/2015/10/re-frame_a_software_fpga
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; calc.cljs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ns sevseg.calc)
(defn calc
"Expects a 4-item vector of booleans
representing a big-endian binary number.
Returns a 7-item map with keys prefix + num
corresponding to which segments of the display
@Jach
Jach / roswell-0.0.6.63.ebuild
Last active June 3, 2016 02:08
quick and dirty ebuild for roswell, installed under local dev-lisp/roswell/
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
EAPI=5
inherit eutils autotools
DESCRIPTION="Common Lisp environment setup utility"
HOMEPAGE="https://github.com/roswell/roswell"
@Jach
Jach / reverse-string.lisp
Last active November 8, 2017 19:22
How to write Lisp like C...
(defun reverse-string-c (string string-length)
(prog ((pos 0) (half (truncate (/ string-length 2))))
START (if (= pos half)
(return string))
(let ((swap-pos (- string-length pos 1)))
(rotatef (schar string pos) (schar string swap-pos)))
(incf pos)
(go START)))
(defun reverse-string (string)