This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compose(*funcs): | |
"""Composes (or chains) two or more functions into a new function. | |
E.g. with "f = compose(len, str, int)", f('123')" is the same as | |
len(str(int('123'))).""" | |
if len(funcs) < 2: | |
raise Exception("too few arguments given") | |
elif len(funcs) == 2: | |
(a, b) = funcs | |
def call(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bit operations to determine whether a month has 31 days. | |
# Just for fun, inspired by an example in the Coursera course | |
# 'Hardware Security', https://www.coursera.org/course/hardwaresec | |
def has31days(month): | |
return (month & 1) ^ ((month & 8) >> 3) | |
for i in range(1, 13): | |
print(i, has31days(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: used cdb commands: | |
:: !sym noisy -> prints verbose output when searching PDBs | |
:: .symopt+0x40 -> accept mismatching PDBs | |
:: .lines -e -> enable source file and line information | |
:: .kframes 100 -> set max number of display stack frames to 0x100 | |
:: lmv -> list all loaded modules with version information | |
:: | -> show process status | |
:: !peb -> show process environment block (command line arguments, environment variables) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// foobar2k plugin that mixes a multi-channel stream down to mono, | |
// and then up to multiple channels again, but with all channels but one empty. | |
// this can be used to play several different tracks simultaneously over a | |
// multi-channel audio output. | |
// | |
// pre-built version can be found here: | |
// https://dl.dropboxusercontent.com/u/267889/foo_down_up_mix_dsp.dll | |
// | |
// to build locally, just add this source file into the SDK sample plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prebuilt for VC14/VS2015 here: | |
// https://dl.dropboxusercontent.com/u/267889/changeres.exe | |
#include <iostream> | |
#include <sstream> | |
#include <Windows.h> | |
int main(int argc, char **argv) | |
{ | |
bool reset = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
int main() | |
{ | |
HMODULE hMod = LoadLibrary("ntdll.dll"); | |
char buf[1024]; | |
DWORD id = 0xc0000005; // code for access violation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <Psapi.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
uint64_t fileTimeToUsec(const FILETIME &ft) | |
{ | |
return ((uint64_t(ft.dwHighDateTime) << 32) | ft.dwLowDateTime) / 10; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a fun little experiment i came up with: | |
// similar to the classic "short string optimization", we could actually use | |
// the bytes of the pointer itself as the short string buffer. | |
// a "tagged pointer" is used to distinguish between the internal buffer | |
// and a heap-allocated string. | |
#include <cassert> | |
#include <cstdint> | |
#include <cstring> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// snake on a MAX7219 led matrix | |
// NOTE: assuming the chip and pins are on the left side of the led matrix, | |
// row = 0, col = 0 is at the upper left corner | |
#include <LedControl.h> | |
// we're using a membrane keypad as controller | |
#include <Keypad.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uses bottle.py as web framework, streamlink for getting the stream URL | |
# and hls.js to play the HLS stream in an HTML5 video tag | |
from bottle import * | |
from streamlink import Streamlink | |
from urllib.request import urlopen, Request | |
import sys, re, json | |
def u(s): | |
if isinstance(s, str): |