Skip to content

Instantly share code, notes, and snippets.

import struct
import itertools
from base64 import b64encode
from retrie.trie import Trie
def commonise_group(pat):
patr = list(sorted(''.join(reversed(s)) for s in pat))
common = [patr[0]]
pat_map = {}
@iscgar
iscgar / fire_consume_all_args.py
Last active July 18, 2021 22:44
Helper decorator to enforce strict optional args for python fire
# Originally by Tyler Rhodes at https://gist.github.com/trhodeos/5a20b438480c880f7e15f08987bd9c0f
# Was broken in later fire versions due to unwrapping of decorated
# functions by fire, which ignores the signature of the wrapper and
# just doesn't pass the needed parameters, so I reimplemented this
# without functools.wraps() and added a bit more validation.
# Unfortunately this solution adds unneeded things to the help output
# due to the added varargs and kwargs, but there's no way around this
# that I know of.
import fire
@iscgar
iscgar / kdz.py
Last active October 31, 2023 09:15
A correct extractor for LG's KDZ Android image files
# A simple and correct LG KDZ Android image extractor, because I got fed up
# with the partially working one from kdztools.
#
# Copyright (c) 2021 Isaac Garzon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@iscgar
iscgar / fizz4.c
Last active November 13, 2020 13:50
Hand-rolled FizzBuzz, with reduced arithmetic (thanks, clang!)
#ifdef _WIN32
# include <Windows.h>
typedef HANDLE out_handle_t;
#else
# include <unistd.h>
typedef int out_handle_t;
#endif
#ifdef _MSC_VER
# include <string.h>
@iscgar
iscgar / fizz3.c
Last active November 9, 2020 22:20
Hand-rolled, compiler copy FIzzBuzz (thanks, Gal!)
#include <string.h>
#include <unistd.h>
#define CACHELINE 64
#define ALIGNED_BUF 65536
#define FIZZ "Fizz"
#define BUZZ "Buzz"
#define DELIM " "
typedef struct {
@iscgar
iscgar / fizz2.c
Created November 9, 2020 19:53
Hand-rolled FizzBuzz redux (thanks, Itai!)
#include <string.h>
#include <unistd.h>
#define CACHELINE 64
#define ALIGNED_BUF 65536
#define DELIM " "
typedef struct {
unsigned short offset;
char data[CACHELINE - sizeof(unsigned short)];
@iscgar
iscgar / fizz.c
Last active November 9, 2020 18:13
Hand-rolled FizzBuzz
#include <string.h>
#include <unistd.h>
#define ALIGNED_BUF 65536
#define DELIM ' '
#define MAX_DIGITS 20 /* 64-bit */
typedef unsigned int fizz_t;
__attribute__((always_inline))
@iscgar
iscgar / fizzbuzz.c
Last active August 15, 2020 19:30
Embedded Software Engineer Solves FizzBuzz
#include <stdio.h>
enum
{
FIZZ = 1,
BUZZ = 2
};
static int get_natural(const char *val, unsigned int *out)
{
@iscgar
iscgar / realbasic-overlay-resolve.py
Created September 26, 2018 19:32
REALbasic (Xojo) Reverse-Engineering Helper Script
# IDA REALbasic reverse engineering helper script
# It seems that every version of REALbasic (Xojo) the loader
# has a different behaviour (especially with regard to parsing
# the imports table), so I'm documenting here that this script
# was created based on a 2009r5 executable.
# iscgar, 2018-09-26
#
# Based on the REALbasic OVERLAY resolver
# XpoZed @ http://nullsecurity.org, 2017-07-16
# http://www.nullsecurity.org/article/reverse_engineering_realbasic_applications
@iscgar
iscgar / murmur_hash3_constexpr.cpp
Created July 6, 2018 12:18
A C++11 constexpr implementation of 32-bit MurmurHash3
#include <stddef.h>
#include <stdint.h>
#include <limits>
#include <type_traits>
namespace detail
{
template<size_t R, class T>
static inline constexpr T rotl(const T v)
{