Skip to content

Instantly share code, notes, and snippets.

View rsms's full-sized avatar

Rasmus rsms

View GitHub Profile
// very simple http server on libevent evhttp
#include <stdio.h>
#include <assert.h>
#include <event.h>
#include <evhttp.h>
#ifndef NDEBUG
#define AZ(foo) assert((foo) == 0)
#define AN(foo) assert((foo) != 0)
# print context switches per second
N=0; while true; do NP=$N; N=$(cat /proc/stat|grep ctxt|awk '{print $2}'); expr $N '-' $NP; sleep 1; done
# dump mysql databases
PASSWD='secret'
for db in hal_mail \
hal_roundcubemail \
hal_wiki \
jforster_blog \
kjallgren \
mattias_wp \
miken_digredi \
mysql \
/* Embed fonts using CSS3
Source: http://www.alistapart.com/articles/cssatten */
@font-face {
font-family: "Kimberley";
src: url(http://www.princexml.com/fonts/larabie/kimberle.ttf) format("truetype");
}
h1 { font-family: "Kimberley", sans-serif; }
// Cocoa forwardInvocation snippet
- (void)forwardInvocation:(NSInvocation *)invocation {
SEL se = [invocation selector];
if ([window respondsToSelector:se])
[invocation invokeWithTarget:window];
else
[self doesNotRecognizeSelector:se];
}
#!/bin/sh
# $Id: modersynk.sh 84 2008-01-14 10:50:55Z rasmus $
if [ `id -u` != 0 ]; then
echo "Must be run as root" >&2
exit 1
fi
RSYNC=/usr/bin/rsync
BACKUP_BASE=/Volumes/Stuff/backup
// HTTP client for testing high connection concurrency
// Authors: Richard Jones and Rasmus Andersson
// Released in the public domain. No restrictions, no support.
#include <sys/types.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <stdlib.h>
#include <err.h>
#include <event.h>
#include <evhttp.h>
// Skeleton Growl delegate/handler
static MyGrowlDelegate *_growl_delegate = nil;
static NSString *_notification_name = @"Transmission complete";
@implementation MyGrowlDelegate
+ (void)initialize {
[GrowlApplicationBridge setGrowlDelegate:[isa sharedInstance]];
}
// print_r
// http://dev.base86.com/solo/47/actionscript_3_equivalent_of_phps_printr.html
package
{
public function print_r(obj:*, level:int = 0, output:String = ""):*
{
var tabs:String = "";
for (var i:int = 0; i < level; i++, tabs += "\t");
for (var child:* in obj)
var xyz = {};
xyz.receiverURL = '.res/save-proxy-image.php';
xyz.resizeImage = function(img, dstw, dsth, fit) {
try {
var w = dstw;
var h = dsth;
if (img.naturalWidth === 0 || img.naturalHeight === 0)
return null;
if (img.naturalWidth > dstw || img.naturalHeight > dsth) {
if (fit) {