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
// 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, |
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
// 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() | |
{ |
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
// 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. |
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
#!/usr/bin/env ruby | |
# Ruby script to scrape termine.orf.at 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. |
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
// 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]) | |
{ |
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
#!/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 |
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
struct nullptr_t | |
{ | |
template <typename T> | |
operator T*() { return static_cast<T*>(0); } | |
}; | |
nullptr_t nullptr; | |
#include <iostream> |
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
# 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] |
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
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 |
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
# 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 | |
# |
OlderNewer