Skip to content

Instantly share code, notes, and snippets.

@runeb
runeb / mls.rb
Created April 23, 2011 15:10 — forked from judofyr/mls.rb
Conversions between latitude, longitude and Maidenhead Locator System
module MLS
extend self
GRID = ("A".."R").to_a
SQUARE = ("0".."9").to_a
SUB = ("a".."x").to_a
deg = 180.0
PARTS = [[18, GRID], [10, SQUARE], [24, SUB], [10, SQUARE]]
PARTS.map! { |div, part| [deg = deg / div, part] }
@runeb
runeb / provisioning_protal.rb
Created May 6, 2011 12:06
A script for accessing the iOS provisioning portal programmatically. Probably a bit outdated now, and assumes you are part of several teams. CUD of CRUD not impl.
require 'bundler/setup'
require 'mechanize'
class Device
attr_accessor :name, :uuid, :id
end
class ProvisioningPortal
attr_reader :connection
@runeb
runeb / paper.SVG.js
Created August 25, 2011 14:34
Export the paper.js view as SVG by rendering to http://svgkit.sourceforge.net/web/SVGCanvas.html
// SVGCanvas.prototype.transform = SVGCanvas.prototype.translate;
// SVGCanvas.prototype.fillText = SVGCanvas.prototype.text;
paper.View.prototype.toSVG = function() {
var svgContext = new SVGCanvas(this.canvas.width, this.canvas.height);
var oldCtx = this._context;
this._context = svgContext;
this.draw(false);
@runeb
runeb / backbone.namespace.js
Created November 23, 2011 15:55
Backbone support for (railsy) namespaces in model/collection json representations
// Extend Backbone.Model to support setting a namespace
// for models. Example response from server:
// {
// 'modelname' : {
// ... attributes ...
// }
// We dont want the attributes to be scoped by the model name
// in the models attributes property. This new parse function
// will drop the namespace if it is defined on the model.
// Example:
@runeb
runeb / finn.rb
Created December 20, 2011 10:00
Finn.no real estate pages as JSON data
# encoding: UTF-8
require 'open-uri'
require 'uri'
def finn(id)
doc = open("http://www.finn.no/finn/realestate/homes/object?finnkode=#{id}").read
doc =~ /helios_parameters\s?:\s?'(.*)'/
attrs = $1.split(';').inject({}) do |mem, e|
key, value = e.split "="
@runeb
runeb / loadAd.js
Created January 30, 2012 15:24
document.write ad voodoo
function loadAd(url, div) {
function makeAdParser(el, cb) {
var inNoScriptTag = false;
var parser = function(txt) {
txt = txt.trim();
if(txt === '</noscript>') { inNoScriptTag = false; return; }
if(txt === '<noscript>') { inNoScriptTag = true; return; }
if(inNoScriptTag) { return; }
#import <Cocoa/Cocoa.h>
@interface RBAppDelegate : NSObject <NSApplicationDelegate>
{
NSStatusItem *systemStatusItem;
}
@end
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSStatusBar *bar = [NSStatusBar systemStatusBar];
systemStatusItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[systemStatusItem setTitle:@"Radio"];
[systemStatusItem setMenu:NULL];
[systemStatusItem retain];
}
- (void) quit {
[NSApp terminate:NULL];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSStatusBar *bar = [NSStatusBar systemStatusBar];
systemStatusItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[systemStatusItem setTitle:@"Radio"];
[systemStatusItem retain];
NSMenu *appMenu = [[NSMenu alloc] init];
[appMenu addItemWithTitle:@"Avslutt" action:@selector(quit) keyEquivalent:@""];
[systemStatusItem setMenu:appMenu];