Skip to content

Instantly share code, notes, and snippets.


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 /
Created Jun 18, 2014
Toying around with metaprogramming in Python.
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
if len(funcs) < 2:
raise Exception("too few arguments given")
elif len(funcs) == 2:
(a, b) = funcs
def call(*args, **kwargs):
mooware /
Created Jan 6, 2015
Bit operations to determine whether a month has 31 days
# Bit operations to determine whether a month has 31 days.
# Just for fun, inspired by an example in the Coursera course
# 'Hardware Security',
def has31days(month):
return (month & 1) ^ ((month & 8) >> 3)
for i in range(1, 13):
print(i, has31days(i))
mooware / amazon-cloud-player-download.js
Last active Oct 13, 2015
Amazon Cloud Player Download Bookmarklet
View amazon-cloud-player-download.js
// I wrote this bookmarklet because Amazon has ended Linux support for downloading MP3s,
// and now I have to download songs separately through Amazon Cloud Player.
// This bookmarklet helps a bit with this, but it's far from perfect.
// When a list of songs is shown in Amazon Cloud Player, it clicks the song checkbox and
// the download button separately for each song, while waiting a few seconds in between songs.
// I encountered the issue that I cannot download more than a few songs simultaneously;
// the rest will just not show a download window. Not sure whether my browser or the server
// is doing this, but you might want to set the value of songdelayms high enough.
// The script is not really that useful, but it was fun to play around with this.
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:
// to build locally, just add this source file into the SDK sample plugin.
mooware / fm4-musik.rb
Last active Dec 13, 2015
Ruby script to scrape for FM4 music events and turn the result into an RSS feed, with one post per run.
View fm4-musik.rb
#!/usr/bin/env ruby
# Ruby script to scrape for FM4 music events and
# turn the result into an RSS feed.
# Usage: ruby fm4-musik.rb <result-file> <data-file> [-digest]
# The result file is where the feed xml will be written to,
# and the data file stores some state necessary to track
# the events that were already posted.
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])
mooware /
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"
#!/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
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 / 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
# 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 / .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
You can’t perform that action at this time.