Skip to content

Instantly share code, notes, and snippets.

View rjungemann's full-sized avatar

Roger Jungemann rjungemann

View GitHub Profile
@rjungemann
rjungemann / gist:564134
Created September 3, 2010 16:30
Script to mount a filesystem with MacFUSE, then copy its address to the clipboard
#!/usr/bin/env ruby
# simply copy an ip address to your clipboard, then run:
# ./drivel.rb
# to mount an sshfs partition and open it up in Finder.app. To unmount, run:
# ./drivel.rb unmount
# requires a Mac running MacFUSE and sshfs
host = `pbpaste`
prefix = host.include?("@") ? "@" : ""
#!/usr/bin/env ruby
require 'socket'
class IP
def self.local
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open { |s| s.connect('64.233.187.99', 1); s.addr.last }
ensure
@rjungemann
rjungemann / xmlindent.rb
Created August 9, 2010 03:01 — forked from EmmanuelOga/xmlindent.rb
pretty xml with Nokogiri
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
XSL = <<-EOXSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:param name="indent-increment" select="' '"/>
<xsl:template name="newline">
@rjungemann
rjungemann / build.sh
Created July 29, 2010 07:07
Compile SpiderMonkey for iPhone
#!/bin/sh
# Shell script for compiling SpiderMonkey for iPhone
#
# 1) Install autoconf 2.13 if you don't have it. You can install it with
# port install autoconf213, or manually like so:
# curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz
# tar xzf autoconf-2.13.tar.gz
# cd autoconf-2.13
# ./configure --program-suffix=213 --prefix=/Users/nathano/.local
@rjungemann
rjungemann / OneWay.c
Created July 29, 2010 07:06
Chipmunk physics example in C
/* Copyright (c) 2007 Scott Lembcke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
@rjungemann
rjungemann / Rakefile
Created July 27, 2010 18:38
Install Boehm GC on OS X
# how to install boehm gc on OS X
task :clean do
sh "rm -rf gc" if File.exists?("gc")
end
task :checkout do
#sh "curl -O http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-7.2alpha4.tar.gz"
#sh "tar zxf gc-*.tar.gz && rm gc-*.tar.gz"
#sh "mv gc-* gc"
@rjungemann
rjungemann / fileserve.rb
Created July 1, 2010 21:34
A simple Rack server to serve a directory of files
# turn any directory into a simple fileserver
#
# USAGE:
# ruby fileserve.rb # starts server for current dir on port 4567
# ruby fileserve.rb ../ # starts server for parent dir
# ruby fileserve.rb ../ 4568 # starts server for parent dir on port 4568
require 'rack'
require 'webrick'
require 'sinatra/base'
@rjungemann
rjungemann / jsonpatra.rb
Created June 21, 2010 01:21
Example of using JSONP with Sinatra
# http://snippets.aktagon.com/snippets/445-How-to-create-a-JSONP-cross-domain-webservice-with-Sinatra-and-Ruby
require 'sinatra/base'
require 'json/pure'
module JSONPatra
class App < Sinatra::Base
get "/" do
callback = params['callback']
json = { :hello => "world!" }.to_json
@rjungemann
rjungemann / Communicator.h
Created June 21, 2010 00:45
How to open a TCP socket in Objective-C
#import <Foundation/Foundation.h>
@interface Communicator : NSObject <NSStreamDelegate> {
@public
NSString *host;
int port;
}
- (void)setup;
@rjungemann
rjungemann / Notify.m
Created June 20, 2010 23:46
Simplest possible event notification system in Cocoa
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[NSNotificationCenter defaultCenter]
addObserverForName:@"randomEvent" object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
NSString *message = [[note userInfo] valueForKey:@"message"];