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 / foo_up_down_mix_dsp.cpp
Created Oct 20, 2015
foobar2k channel mixer plugin to only play on a single of multiple channels
View foo_up_down_mix_dsp.cpp
// 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.
@mooware
mooware / cdb-show-dump.cmd
Last active Sep 5, 2016
print lots of windows minidump information with CDB
View cdb-show-dump.cmd
@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)
@mooware
mooware / bitwise_has31days.py
Created Jan 6, 2015
Bit operations to determine whether a month has 31 days
View bitwise_has31days.py
# 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))
@mooware
mooware / compose.py
Created Jun 18, 2014
Toying around with metaprogramming in Python.
View compose.py
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):
@mooware
mooware / colorstreamhandler.py
Last active Apr 2, 2020
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 / .vimrc
Created Jan 8, 2014
My .vimrc for work
View .vimrc
set nocompatible
syntax on
filetype plugin on
filetype plugin indent on
" by itself, jellybeans doesnt enable 256 colors
set t_Co=256
set background=dark
@mooware
mooware / challenge8-palindrome-number.rb
Last active Dec 31, 2015
challenge #8: find the largest palindrome made from the product of two 3-digit numbers
View challenge8-palindrome-number.rb
# challenge #8
# 'find the largest palindrome made from the product of two 3-digit numbers'
# see also http://projecteuler.net/index.php?section=problems&id=4
# simple one-line solution, seems fast enough
# => [906609, 993, 913]
999.downto(100).map { |a| 999.downto(100).map { |b| [a*b, a, b] }.select { |arr| s = arr.first.to_s; s == s.reverse } }.flatten(1).sort { |a, b| a.first <=> b.first }.reverse.uniq.first
# more performant solution for n-digit numbers
# 4 => [99000099, 9999, 9901]
@mooware
mooware / nullptr_t.cpp
Last active Dec 16, 2015
Implementation of the C++11 feature nullptr_t and an example of why it works better than the C #define NULL
View nullptr_t.cpp
struct nullptr_t
{
template <typename T>
operator T*() { return static_cast<T*>(0); }
};
nullptr_t nullptr;
#include <iostream>
@mooware
mooware / bytes2ascii.py
Created Apr 2, 2013
Python script that takes lines of text containing byte hex values, and appends a printable representation of the bytes to each line. It's similar to xxd, but it takes already dumped bytes instead of the original binary data. Example: "70 79 74 68 6f 6e" -> "70 79 74 68 6f 6e python"
View bytes2ascii.py
#!/usr/bin/env python
import fileinput
import re
# pattern to match lines of hex byte values
PATTERN = re.compile("^[a-zA-Z0-9]{1,2}( [a-zA-Z0-9]{1,2})*$")
# margin between bytes and text
MARGIN = 2
@mooware
mooware / sizeof_array.hpp
Last active Dec 14, 2015
Type-safe way to get the length of an array in C++.
View sizeof_array.hpp
// In C/C++, the idiom (sizeof(arr) / sizeof(*arr)) is often used to get the length of an array.
// But this will return incorrect results if arr is not actually an array, but a pointer.
// The following function template provides a type-safe way to get the length of an array,
// by "destructuring" the type and reading the array length from there.
#include <cstddef> // for size_t
template <typename T, size_t N>
constexpr size_t sizeof_array(T (&)[N])
{
You can’t perform that action at this time.