Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@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 / 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

@louisswarren
louisswarren / xrtost.py
Created June 11, 2016 00:05
Convert .Xresources colours to st config format
#!/bin/python3
from sys import argv
with open(argv[1]) as f:
lines = f.readlines()
d = dict()
for line in lines:
if line[0] != '*' or 'color' not in line:
continue
@louisswarren
louisswarren / eduroam
Last active October 14, 2016 13:16
Config for netctl for eduroam wifi
# Write to /etc/netctl/eduroam and start with netctl start eduroam
# Replace <wireless device> <username> and <password> below
Description='Eduroam'
Interface=<wireless device>
Connection=wireless
Security=wpa-configsection
IP=dhcp
ESSID=eduroam
WPAConfigSection=(
@louisswarren
louisswarren / easy_passwords.py
Last active April 30, 2022 10:01
Generate passwords which are easy to type
# Generate passwords which can be typed without using any finger to press two
# different keys in a row.
from math import log, ceil
# For each finger, write the letters *you* type with that finger.
finger_classes = [
'qaz',
'wsx',
'edc',
@louisswarren
louisswarren / memeoisation.py
Last active August 2, 2016 07:21
MEMEoisation (hardy har har)
def meme(f):
memes = {}
def inner(*args, **kwargs):
key = (args, tuple(sorted(kwargs.items())))
if key in memes:
return memes[key]
ret = f(*args, **kwargs)
memes[key] = ret
return ret
return inner
@louisswarren
louisswarren / deadman.sh
Last active October 25, 2016 07:05
Automatically revert change to a config file
#!/bin/sh
# Example:
# deadman /etc/network/interfaces 120 && service networking restart &
#
# After two minutes, changes are reverted and the service is restarted.
# No getting locked out!
# (you were root weren't you?)
backup=`cat "$1"`
@louisswarren
louisswarren / tautologies.py
Last active September 7, 2016 10:46
Generate all tautologies
from itertools import product, permutations
from pyaccum import accumulate
class Proposition:
def __invert__(self):
return Impl(self, bottom)
def __or__(self, other):
return Disj(self, other)
from itertools import count
class r_class:
def __getitem__(self, items):
for i, element in enumerate(items):
if element is Ellipsis:
if i >= 2:
step = items[i - 1] - items[i - 2]
elif i == 1 and items[0] > items[2]:
step = -1