Skip to content

Instantly share code, notes, and snippets.

mooware

Block or report user

Report or block mooware

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mooware
mooware / ld-preload-intercept-method.cpp
Last active Dec 6, 2019
Intercept C++ methods with LD_PRELOAD
View ld-preload-intercept-method.cpp
// this file is an example of how to intercept a C++ method by using the
// LD_PRELOAD environment variable of the GNU dynamic linker.
//
// it works like this:
//
// 1) define a method that will have the same symbol as the intercepted
// method when compiled. For example, the method Foo::getValue()
// defined here has the mangled symbol "_ZNK3Foo8getValueEv".
// tools like nm, objdump or readelf can display the symbols of
// binaries. note that depending on compiler and linker options,
@mooware
mooware / outlook-disable-encryption.py
Created Oct 23, 2019
Python script to monitor the Windows registry and ensure that Outlook email encryption by default stays off
View outlook-disable-encryption.py
import ctypes, ctypes.wintypes
advapi32 = ctypes.windll.advapi32
# LSTATUS RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
RegOpenKeyExA = advapi32.RegOpenKeyExA
RegOpenKeyExA.argtypes = (ctypes.wintypes.HKEY, ctypes.wintypes.LPCSTR, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.PHKEY)
# LSTATUS RegCloseKey(HKEY hKey)
RegCloseKey = advapi32.RegCloseKey
@mooware
mooware / colorstreamhandler.py
Last active Oct 10, 2019
Colored log output for Python logging framework. Works on Windows, Linux, and probably Mac as well.
View colorstreamhandler.py
# colored stream handler for python logging framework (use the ColorStreamHandler class).
#
# based on:
# http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output/1336640#1336640
# how to use:
# i used a dict-based logging configuration, not sure what else would work.
#
# import logging, logging.config, colorstreamhandler
#
@mooware
mooware / twitch_redirect.py
Last active Oct 9, 2019
Simple bottle.py application to play twitch.tv streams through HTML5 video
View twitch_redirect.py
# 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):
@mooware
mooware / constexpr-char-lookup-table.cpp
Created Sep 28, 2019
Constexpr generation of character lookup tables
View constexpr-char-lookup-table.cpp
// generate character-based static lookup tables
// that can be used for character classification,
// e.g. like in cctype functions (isdigit, isalpha ...)
struct CharLookupTable
{
bool data[256];
template <unsigned int N>
constexpr CharLookupTable(const char (&str)[N])
@mooware
mooware / gnu-libc-print-stacktrace.c
Last active Sep 28, 2019
Print a stacktrace on Linux with GNU libc
View gnu-libc-print-stacktrace.c
// this code fragment shows how to print a stack trace (to stderr)
// on Linux using the functions provided by the GNU libc
#include <execinfo.h>
#define MAX_STACK_LEVELS 50
// helper-function to print the current stack trace
void print_stacktrace()
{
@mooware
mooware / pihut_xmas_tree.py
Last active Dec 1, 2018
Script for the Pi Hut 3D Xmas Tree
View pihut_xmas_tree.py
from gpiozero import LEDBoard
from time import sleep
import random
tree = LEDBoard(*range(2, 28), pwm=True)
# first led is the top one in the star
tree[0].value = 0.6
leds = range(1, len(tree))
@mooware
mooware / colormsvc.py
Created Oct 13, 2017
Colorization for MSVC warnings and errors
View colormsvc.py
import sys, re
COMPILE_PATTERN = re.compile(r'^.+\(\d+\) ?: (fatal )?(error|warning|note)( C\d+)?: .+$')
LINK_PATTERN = re.compile(r'^.+ : (fatal )?(error|warning) LNK\d+: .+$')
OTHER_PATTERN = re.compile(r'^.+ : (general |Command line )?(error|warning) \w+ ?: .+$')
class WinColorStream:
# wincon.h
FOREGROUND_BLACK = 0x0000
FOREGROUND_BLUE = 0x0001
@mooware
mooware / snake.ino
Created Jun 30, 2017
Snake for Arduino on a LED matrix
View snake.ino
// 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>
@mooware
mooware / tiny_string.h
Created Sep 6, 2016
An experimental "very short string optimization"
View tiny_string.h
// 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>
You can’t perform that action at this time.