Skip to content

Instantly share code, notes, and snippets.

@Ape
Ape / config.py
Created October 16, 2017 06:08
My qutebrowser config
import setproctitle
setproctitle.setproctitle("qutebrowser")
# Bindings
config.bind("gi", "hint inputs")
config.bind("<f12>", "inspector")
config.unbind("+")
config.unbind("-")
config.unbind("=")
@Ape
Ape / day2.py
Created December 3, 2016 18:26
Aoc 2016 Day 2 with Python
#!/usr/bin/env python3
import sys
import numpy as np
KEYPADS = [
np.array([
["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"],
@Ape
Ape / day1part1.py
Created December 3, 2016 16:56
AoC 2016 Day 1 Part 1 with Python
#!/usr/bin/env python3
import sys
steps = next(sys.stdin).split(", ")
x = 0
y = 0
for step in steps:
@Ape
Ape / part2.py
Created December 3, 2016 07:26
AoC 2016 Day 3 Part 2 with Numpy
#!/usr/bin/env python3
import sys
import numpy as np
data = np.loadtxt(sys.stdin).T.reshape(-1, 3).T
data.sort(axis=0)
print(np.sum(sum(data[:2]) > data[2]))
@Ape
Ape / spotifyadd
Last active April 17, 2016 09:44
spotifyadd
#!/bin/sh
set -e
TRACK_ID="$1"
CLIENT_ID="..."
CLIENT_SECRET="..."
REFRESH_TOKEN="..."
ACCESS_TOKEN=$(
@Ape
Ape / advent9.py
Last active December 9, 2015 15:15
advent9.py
#!/usr/bin/env python3
import itertools
import sys
lines = (x.split(" ")[::2] for x in sys.stdin.readlines())
routes = {frozenset(x[:2]): int(x[2]) for x in lines}
places = set.union(*(set(x) for x in routes.keys()))
path_len = lambda path: sum(routes[frozenset(x)] for x in zip(path, path[1:]))
lengths = [path_len(x) for x in itertools.permutations(places)]
@Ape
Ape / advent7.py
Last active December 7, 2015 21:04
advent7.py
#!/usr/bin/env python3
import functools
import sys
OPERATORS = {
None: lambda arg: arg(0),
"NOT": lambda arg: ~arg(1),
"AND": lambda arg: arg(0) & arg(2),
"OR": lambda arg: arg(0) | arg(2),
@Ape
Ape / advent3.py
Last active December 3, 2015 20:05
advent3.py
#!/usr/bin/env python3
import sys
MOVES = {
">": ( 1, 0),
"<": (-1, 0),
"^": ( 0, 1),
"v": ( 0, -1),
}
#!/usr/bin/env python3
import collections
print("Syötä viestin tekstirivejä. Lopeta syöttämällä tyhjä rivi.")
teksti = ""
while True:
syöte = input()
@Ape
Ape / tulosta.py
Last active September 23, 2015 14:33
#!/usr/bin/env python3
class Kartta:
def __init__(self, koko, auto):
self.koko = koko
self.auto = auto
def tulosta(self):
for rivinumero in reversed(range(1, self.koko + 1)):
print(self._rivi(rivinumero))