Skip to content

Instantly share code, notes, and snippets.

@Ape
Ape / hash-shader.glsl
Last active August 29, 2015 14:17
Kuku Kube Compositing Shader
// Run this with Compton
// compton --backend glx --force-win-blend --glx-fshader-win "$(cat hash-shader.glsl)"
uniform float opacity;
uniform bool invert_color;
uniform sampler2D tex;
// HSV conversion taken from http://stackoverflow.com/a/17897228
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
@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))
@Ape
Ape / vaihtoraha.py
Last active September 23, 2015 14:39
vaihtoraha
#!/usr/bin/env python3
rahat = [
(10, "kymppiä"),
(5, "vitosta"),
(2, "kaksieuroista"),
(1, "euroa")
]
hinta = int(input("Ostosten hinta: "))
#!/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 / 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),
}
@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 / 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)]
pkt = bytearray(b'\x11\x80\x00\xff\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
device = open('/dev/hidraw7', 'wb')
device.write(pkt)
device.close()
@Ape
Ape / hidraw_test.c
Last active January 4, 2016 13:49
DualShock 4 driver test using C
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char **argv) {
if (argc != 2) {
printf("Usage: %s hidraw_device\n", argv[0]);
return 0;
@Ape
Ape / hidraw_test.py
Created January 26, 2014 10:29
DualShock 4 driver test using python
import os
device_path = '/dev/hidraw7'
fd = os.open(device_path, os.O_RDWR)
report = bytearray(78)
report[0] = 0x11
report[1] = 128