Skip to content

Instantly share code, notes, and snippets.

View toto's full-sized avatar

Thomas Kollbach toto

View GitHub Profile
DEFAULT_OPTIONS.keys.each do |key|
define_method key do
return options[key.to_sym] unless options.nil?
end
define_method "#{key}=".to_sym do |value|
returning(options || {}) do |opt|
options[key.to_sym] = value
end
end
@toto
toto / sphinx-smf.xml
Created March 18, 2010 13:18
SMF Manifest for Sphinx on OpenSolaris
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type="manifest" name="sphinx">
<service name="network/sphinx" type="service" version="0">
<dependency name="fs" grouping="require_all" restart_on="none" type="service">
<service_fmri value="svc:/system/filesystem/local"/>
</dependency>
<dependency name="net" grouping="require_all" restart_on="none" type="service">
<service_fmri value="svc:/network/loopback"/>
</dependency>
/*
Some sample code for a horizontal paged UIScrollView with a gap between each image (which looks nicer). Note - not using contentInset, we want each page to fill the iPhone screen and the gap only to be visible when scrolling (like Photos.app).
Taking the iPhone status bar into account - our viewport is 320x460
Our UIScrollView is therefore set in Interface Builder to 340x460 with a -10 X offset (so it's larger than the viewport but still centred)
Then we do the following...
*/
// Our image filenames
require 'yaml'
require 'xmlrpc/client'
typo = XMLRPC::Client.new('blog.host.name', '/backend/xmlrpc')
posts = typo.call('metaWeblog.getRecentPosts', '1', 'username', 'password', 1_000_000).select{|p| !p['description'].nil?}.collect do |post|
{'title' => post['title'],
'body' => post['description'],
'body_converter' => post['mt_convert_breaks'],
'tags' => post['mt_keywords'],
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *tests = [NSArray arrayWithObjects: [NSMutableDictionary dictionary], [NSDictionary dictionary], nil];
SEL sel = @selector(setObject:forKey:);
for(id obj in tests) {
require 'rubygems'
require 'pp'
require 'json'
require 'httparty'
url = "http://www.adgonline.de/adg_online/phoenix/searchalyzr.jspx"
class Loader
include HTTParty
end
@toto
toto / gist:741242
Created December 14, 2010 22:33
AirPlay Connection Upgrading
POST /reverse HTTP/1.1
Upgrade: PTTH/1.0
Connection: Upgrade
Content-Length: 0
User-Agent: MediaControl/1.0
@toto
toto / org.xsane.saned.plist
Created January 16, 2011 15:01
launchd config fille to use a homebrew installed saned with the inetd compatibility features in launchd.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.xsane.saned</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/saned</string>
</array>
@toto
toto / google_user_location.rb
Created April 22, 2011 13:14
Gets your location using the google wifi location service (also used by Firefox) using the Mac OS X CoreWLAN framework on Snow Leopard. Also compare to the CoreLocation based version https://gist.github.com/266916
require 'pp'
require 'net/http'
require 'net/https'
require 'rubygems'
require 'json'
def bssid_to_api(bssidstr)
bssidstr.gsub(':', '-').gsub(/(\-|\A)(\d)(\-|\Z)/) {|match| "#{match[0]}0#{match[1]}#{match[2]}"}
end
@toto
toto / uselessComments.java
Created April 22, 2011 15:22
If you force people to write doc-comments this is what happens
/**
* Berechnet zu einem gegebenen Pfad dessen Fitnesswert
*
* @param subPfad
* der Pfad, dessen Fitnesswert bestimmt werden soll
* @return Fitnesswert des Pfades
*/
private ArrayList<scoredPath> getPfadFitness(ArrayList<scoredPath> pathesToScore, Boolean hasUwkt) {
// …
}