Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / keybase.md
Created February 8, 2016 04:19
Keybase proof

Keybase proof

I hereby claim:

  • I am louisswarren on github.
  • I am louisswarren (https://keybase.io/louisswarren) on keybase.
  • I have a public key whose fingerprint is 1AC6 4B7A 624E 8409 A7D3 DC0F C405 A798 0B57 F6B7

To claim this, I am signing this object:

#!/usr/bin/python3
from sys import argv
text = ''.join(argv[1:]).upper().replace(' ', '')
print(' '.join(text))
print('\n'.join(text[1:]))
@louisswarren
louisswarren / pcat
Last active March 27, 2016 05:28
Script for viewing long files in tty using only head, tail, echo, bc
#!/bin/sh
# Use to view long files without more or less
# One-liner so that it may be easily echo'd to /bin/pcat instead of using ed
# Usage:
# pcat filename pagenum
head -n $(echo "$2 * 20" | bc) $1 | tail -n 20
def scale_matrix(m, s):
return list(list(s * x for x in row) for row in m)
def print_matrix(m):
print('--' + ' ' * (len(m[0]) * 10) + '--')
for row in m:
print('| ', end='')
for x in row:
print('{:10.2f}'.format(x), end='')
print(' |')
@louisswarren
louisswarren / sin_approx.py
Last active April 30, 2016 06:32
Test Taylor series approximations to sin
from math import factorial, pi, sin
def max_diff(f, g, v):
return max(abs(f(x) - g(x)) for x in v)
def zigrange(x, s=1.0):
yield 0
for y in range(1, int(x / s + 0.5) + 1):
yield y * s;
yield -y * s;
@louisswarren
louisswarren / converge.py
Last active April 30, 2016 06:36
Guess what a function converges to
import itertools
def adjacent_pairs(g):
a, b = itertools.tee(g)
next(b)
return zip(a, b)
def converge(f, vals, e=1e-9):
for a, b in adjacent_pairs(vals):
if abs(f(a) - f(b)) < e:
@louisswarren
louisswarren / duseful.sh
Created May 28, 2016 02:28
du which is actually useful
#!/bin/sh
du -hd 1 2> /dev/null | sort -h
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
/* Buffer is big-endian */
/* Get bits in order of descending significance */
uint8_t get_bit(const uint8_t *x, size_t n)
{
return (x[n / 8] & (1 << (7 - (n % 8)))) != 0;
@louisswarren
louisswarren / named_func.py
Last active June 6, 2016 00:01
Functions with human-readable representations
def named_func(f):
return type('named_func', (), {
'__call__': lambda s, *a, **k: f(*a, **k),
'__repr__': lambda s: f.__name__,
'__name__': f.__name__,
'__doc__': f.__doc__,
})()
>>> @named_func
@louisswarren
louisswarren / ideas.md
Last active June 9, 2016 04:21
Good ideas that people should do
  • Use a set-based filesystem (instead of directory based). These would act like tags. Sets generated from predicates would also be handled by the filesystem (when used), for example ?modified>yesterday, ?size<1M. These could also include file extensions.

    vlc media,?modified>yesterday

    for files in the set 'media' which were modified since yesterday, and

    vim &gt;&gt;modified