Skip to content

Instantly share code, notes, and snippets.

@stbuehler
stbuehler / batcher_oddeven_mergesort.cpp
Created March 23, 2011 18:22
Batcher odd-even mergesort
/* Batcher odd-even mergesort: http://en.wikipedia.org/wiki/Batcher_odd-even_mergesort */
/* O(n * (log n) * (log n)): inplace, and could run in O( (log n) * (log n) ) on n cores in parallel */
/* Most implemenations only handle power-of-two input sizes; this implementation
appends "virtual" infinity items at the end of input (takes no space) */
#include <vector>
#include <cassert>
@stbuehler
stbuehler / torrent-announce-info.rl
Created April 10, 2011 13:42
Torrent Announce Info extractor
/*
Torrent Announce Info extractor
lists all announce urls from torrents on stdout
Build with ragel (http://www.complang.org/ragel/) and a c compiler:
ragel -T1 torrent-announce-info.rl && CFLAGS='-O2' make torrent-announce-info
list torrent files on stdin:
ls -1 /path/to/torrents/*.torrent | torrent-announce-info
@stbuehler
stbuehler / Makefile
Created April 11, 2011 00:13
analyse/fix torrent files
override LDFLAGS += -lssl -lpcrecpp
override CPPFLAGS += -O2 -Wall
all: torrent-sanitize
clean:
rm torrent-sanitize
.PHONY: all clean
@stbuehler
stbuehler / ipkdesc
Created April 20, 2011 19:26
ipk package feed
#!/bin/bash
IPKG=$1
FILENAME=$(basename "$IPKG")
X=$FILENAME
PACKAGE=${X%%_*}
X=${X#*_}
VERSION=${X%%_*}
X=${X#*_}
@stbuehler
stbuehler / future-nest-fix.js
Created April 20, 2011 21:59
webos Mojo: Foundations.Control.Future - make nest usable
/* wait for "this" future to reach this point, run "inner" in background; copy result from "inner" future */
Future.prototype.nest = function(inner) {
var succ, result, exc, wait = 2, f = this;
this.then(function () {
f.exception;
if (0 == --wait) { if (succ) f.result = result; else f.exception = exc; }
});
inner.then(function (future) {
if (future.exception) { succ = false; exc = future.exception; } else { succ = true; result = future.result; }
if (0 == --wait) { if (succ) f.result = result; else f.exception = exc; }
@stbuehler
stbuehler / ipkbuild
Created April 30, 2011 12:21
palm-package recode in ruby
#!/usr/bin/env ruby
require 'optparse'
require 'tmpdir'
require 'json'
require 'fileutils'
require 'zlib'
require 'rubygems' rescue nil
require 'libarchive'
@stbuehler
stbuehler / palmcomments.php
Created October 19, 2011 21:28
fetch comments for webos appcatalog apps
<?php
global $token;
/* Insert real token data to use search/app details
luna-send -n 1 palm://com.palm.accountservices/getAccountToken '{}'
luna-send -n 1 palm://com.palm.deviceprofile/getDeviceId '{}'
luna-send -n 1 palm://com.palm.preferences/systemProperties/Get '{"key":"com.palm.properties.DMCARRIER"}'
*/
$token = array(
@stbuehler
stbuehler / git.lighttpd.net.conf
Created January 9, 2012 21:51
smart http git + cgit with lighttpd2 (needs fcgi-cgi)
git = {
docroot "/home/gitosis/repositories";
mime_types (
# css for cgit
".css" => "text/css; charset=utf-8",
# git mime types, default for objects files
"HEAD" => "text/plain",
"alternates" => "text/plain",
@stbuehler
stbuehler / Makefile
Created January 29, 2012 18:28
preware build.git: build stub libs for libs from PalmSDK
NAME = PDK
TITLE = PDK
APP_ID = org.webosinternals.toolchain.${NAME}
VERSION = 1.0-1
MAINTAINER = WebOS Internals <support@webos-internals.org>
.PHONY: package
package: build/.built-${VERSION}
.PHONY: stage
@stbuehler
stbuehler / cppallocs.cpp
Created March 21, 2012 16:32
custom c++ allocators using glib slice/mallo and mmap
// g++ -O3 -Wall `pkg-config --cflags --libs glib-2.0` cppallocs.cpp -o cppallocs
#include <new>
#include <glib.h>
#include <sys/mman.h>
// Use different allocators depending on size, so we need to remember the size
// One could add other members,like some magic data to check the allocs/frees