Skip to content

Instantly share code, notes, and snippets.

View ztane's full-sized avatar

Antti Haapala ztane

View GitHub Profile
@ztane
ztane / fix_0cc.py
Created December 16, 2021 17:29
Try to fix a 0cc/FTM file by writing copies with certain chunks missing
#!/usr/bin/python3
import sys
def read_block():
block_id = f.read(16)
version = f.read(4)
size = f.read(4)
contents = f.read(int.from_bytes(size, "little"))
return block_id, version, size, contents
@ztane
ztane / yadayadagettext.py
Created May 16, 2020 20:56
Yadayada gettext
import re
import itertools
def ugettext(s):
c = itertools.cycle('yada')
def replace(m):
char = m.group(0)
replacement = next(c)
if char.isupper():
@ztane
ztane / clang.c
Created March 20, 2019 16:14
clang ub stuff
#include <stdio.h>
#define BUGGY
void funcA(int s, int g)
{
int i, j = 0, k;
int grp[4] = {-1, -1};
for (i = 0, k = 0; i < 1; ++i) {
int foo(int a, int b) {
if ((a-b)==0) {
return 1;
}
return 0;
}
int bar(int a, int b) {
if (a==b) {
return 1;
@ztane
ztane / test.py
Last active October 9, 2018 11:52
dictionary merging test
from collections import defaultdict
import time
i = 100
for _ in range(3):
list_of_dictionaries = [{1: 1} for i in range(i)]
list_of_dictionaries.append(dict.fromkeys(range(i)))
n = sum(map(len, list_of_dictionaries))
@ztane
ztane / jsonSerialize.js
Created September 7, 2017 22:17
jsonSerialize
(function ($) {
function doSerializeArrayItems($current, target) {
$current.children().each(function (i, e) {
var $e = $(e),
tmp;
if (e.hasAttribute('data-form-item')) {
var o = {};
target.push(o);
doSerialize($e, o);
}
@ztane
ztane / aco.py
Created December 2, 2016 10:58
Advent of Code helpers for Python 3
# advent of code helpers for Python 3
def input_file(filename='input'):
"""
Read the input from current working directory,
return as a string stripped
"""
with open(input) as f:
return f.read().strip()
@ztane
ztane / keybase.md
Created November 13, 2016 12:59
keybase.md

Keybase proof

I hereby claim:

  • I am ztane on github.
  • I am anttihaapala (https://keybase.io/anttihaapala) on keybase.
  • I have a public key whose fingerprint is B811 2F0F ACC5 6F06 B79C 4E4D 69C6 71AF 0959 C672

To claim this, I am signing this object:

@ztane
ztane / flextest.l
Last active October 24, 2016 18:27
Simple flex
%{
#include <stdio.h>
int line_num = 1;
%}
%%
"(" { printf("a opening parenthesis\n"); }
")" { printf("a closing parenthesis\n"); }
[0-9]+ { printf("a number: %s\n", yytext); }
@ztane
ztane / typechecking.py
Last active September 19, 2016 10:46
Typing testing
import warnings
import inspect
NONE = object()
class TypingWarning(Warning):
pass