Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / ai_range_syntax.py
Created September 19, 2016 04:26
This should be compatible with your Cosc367 project
from sequences import *
class ai_class:
def __getitem__(self, items):
if items[-1] is not Ellipsis:
yield from items
return
expression = find_sequence(items[:-1])
yield from items[:-1]
user="louisswarren"
github="https://api.github.com"
pyjsonlines="'\n'.join(r[sys.argv[-1]] for r in json.loads(sys.stdin.read()))"
pycmd="import sys, json; print($pyjsonlines)"
curl -s "$github/users/$user/repos" | python3 -c "$pycmd" git_url |
while read x; do
git clone "$x"
done
@louisswarren
louisswarren / builtins.py
Last active September 21, 2016 10:08
Co-sane implementations of python builtins and more
import itertools
sum = lambda x: list(itertools.accumulate(x)).pop()
len = lambda x: sum(1 for _ in x)
range = lambda n, step=1: itertools.accumulate(itertools.repeat(step, times=n-1), lambda x, y: x + y)
# Full implementation
range = lambda min, max=None, step=1: itertools.accumulate(itertools.chain((min if max is not None else 0,),
itertools.repeat(step, (max-min-1)//step if max is not None else None)))
@louisswarren
louisswarren / a7booklet.py
Created September 28, 2016 09:32
How to print a 64 page book on 4 a4 sheets
front = 16,1,14,3,12,5,10,7
back = 4,13,2,15,8,9,6,11
for x in range(4):
print("Sheet", x + 1)
for side in front, back:
print(',\t'.join(str(p + 16*x) for p in side))
print()
# Sheet 1
@louisswarren
louisswarren / mp4tomp3.sh
Created September 29, 2016 09:54
Convert mp4 to mp3
for f in *.mp4; do
target="${f%.mp4}.mp3"
ffmpeg -i "$f" -vn -acodec libmp3lame -ac 2 -ab 320k -ar 48000 "$target"
done
@louisswarren
louisswarren / accidental_lisp.py
Last active October 5, 2016 16:25
It was around the time I added car and cdr that I realised this wasn't about natural numbers anymore
from util import *
class Obj:
@constructor
def __init__(self, name):
pass
def __str__(self):
return str(self.name)
@louisswarren
louisswarren / msens.sh
Last active May 10, 2017 19:21
Set mouse sensitivity with xinput
#!/bin/sh
# Set mouse sensitivity
inputnum=`xinput list | grep -oE "USB OPTICAL MOUSE.*id=[0-9]+" | grep -oE "[0-9]+" | head -n 1`
propnum=`xinput list-props "$inputnum" | grep -oE "Coordinate Transformation Matrix \([0-9]+\)" | grep -oE "[0-9]+"`
xinput set-prop "$inputnum" "$propnum" "$1" 0 0 0 "$1" 0 0 0 1
@louisswarren
louisswarren / demo.agda
Last active August 21, 2017 10:07
Trying out agda
module demo where
-- Natural numbers
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
infix 5 _+_
@louisswarren
louisswarren / guileman.py
Last active April 4, 2017 10:52
Python script for running a guile instance as a server, with a file as input
#!/usr/bin/python3
import sys
import os
import time
filename = '/home/louis/minlog/.guileman.txt'
f = open(filename, 'w')
f.write('\n')
f.close()
@louisswarren
louisswarren / humour.py
Last active January 23, 2017 08:04
A turing machine can't solve the halting problem, but it can solve the hilarity problem, right gang?
prepositions = """
aboard, about, above, across, after, against, along, amid, among, anti,
around, as, at, before, behind, below, beneath, beside, besides, between,
beyond, but, by, concerning, considering, despite, down, during, except,
excepting, excluding, following, for, from, in, inside, into, like, minus,
near, of, off, on, onto, opposite, outside, over, past, per, plus,
regarding, round, save, since, than, through, to, toward, towards, under,
underneath, unlike, until, up, upon, versus, via, with, within, without
""".split(', ')