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 / 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 / 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 / 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 / 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 / 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>
@mooware
mooware / measure.cpp
Created Mar 3, 2016
Similar to the "time" or "timeit" commands, for Windows.
View measure.cpp
#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;
}
@mooware
mooware / print-exception-text.cpp
Created Feb 12, 2016
An example program to show that FormatMessage() cannot properly return the text for an exception code.
View print-exception-text.cpp
#include <windows.h>
#include <stdio.h>
int main()
{
HMODULE hMod = LoadLibrary("ntdll.dll");
char buf[1024];
DWORD id = 0xc0000005; // code for access violation
@mooware
mooware / changeres.cpp
Last active Feb 14, 2016
Simple program to change the display resolution on Windows
View changeres.cpp
// 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;
You can’t perform that action at this time.