Skip to content

Instantly share code, notes, and snippets.

View thomasfl's full-sized avatar
🏠
Working from home

Thomas Flemming thomasfl

🏠
Working from home
View GitHub Profile
# -*- coding: utf-8 -*-
#
# Danish norwegian sort order. Requires ruby 1.9 or better.
class String
# compares two strings based on a given alphabet
def cmp_loc(other, alphabet)
order = Hash[alphabet.each_char.with_index.to_a]
self.chars.zip(other.chars) do |c1, c2|
@thomasfl
thomasfl / new_coding_style.rb
Created January 26, 2011 08:39
A new super compact coding style for ruby ☺. Credits to zmalltalker for having the idea at last nights ruby meetup.
# encoding: UTF-8
def ✐(arg)
puts arg
end
☺ = true
✐ "Cool" if ☺
@thomasfl
thomasfl / migrate_summerschool.rb
Created July 8, 2011 13:51
Migrering av summerschool.uio.no
require 'vortex_migration/static'
# To run, first download the content of the site to local disk with wget:
#
# $ wget --mirror –p --html-extension –-convert-links --force-directories -e robots=off -P . http://www.summerschool.uio.no/
# the run this script.
#
# Custom code for migrating the www.summerschool.uio.no site vortex:
class SummerSchoolMigration < StaticSiteMigration
@thomasfl
thomasfl / escape_utf8.js
Created October 14, 2011 08:03
Escape unsafe characters in javascript.
/*
* Convert unicode characters to safe characters.
*
* Usage:
* $ node
* > var utf8 = require("./escape_utf8.js");
* > utf8.unicodeEscapeChars("This is a test with æøå and ÆØÅ");
* 'This is a test with \\xe6\\xf8\\xe5 and \\xc6\\xd8\\xc5'
*/
exports.unicodeEscapeChars = function(str) {
@thomasfl
thomasfl / a_b_split_test.html
Created December 20, 2011 14:06
Simple A/B split testing template.
<html>
<head>
<script language="javascript">
var regex = /uio_a_b_test=([^\;]+)/;
var match = regex.exec(document.cookie);
if(match === null){
var randomnumber = Math.floor(Math.random()*100);
var days=14;
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
@thomasfl
thomasfl / hello_world_in_vortex.rb
Created January 10, 2012 14:43
Vortex Hello World script
require 'rubygems'
require 'net/dav'
require 'json'
require 'highline/import'
webdav_url = 'https://vortex-systest-dav.uio.no'
dav = Net::DAV.new(webdav_url)
username = ask("Username: ")
password = ask("Password: ") {|q| q.echo = "*"}
dav.credentials(username, password)
@thomasfl
thomasfl / hello_world_in_vortex_utils.rb
Created January 10, 2012 14:48
Vortex Utils Hello World script
require 'rubygems'
require 'net/dav'
require 'json'
require 'vortex_utils'
dav = Net::DAV.new('https://vortex-systest-dav.uio.no/test/', :osx_keychain => true)
article = {
"resourcetype" => "structured-article",
"properties" => {
"title" => "Hello world!",
@thomasfl
thomasfl / hello_world_in_vortex_osx.rb
Created January 10, 2012 15:11
Hello World in Vortex on OSX
require 'rubygems'
require 'net/dav'
require 'json'
require 'highline/import'
require 'osx_keychain'
dav = Net::DAV.new('https://vortex-systest-dav.uio.no')
keychain = OSXKeychain.new
username = ENV['USER']
password = keychain['vortex-systest-dav.uio.no', username ]
require 'rubygems'
require 'open-uri-and-write'
file = open("https://www-dav.usit.uio.no/takk_for_meg.html","w")
file.puts { "resourcetype" => "structured-article",
"properties" => { "title" => "Takk for meg!",
"introduction" => "Det har vært 10 fine år."
"content" => "Hilsen Thomas Flemming",
}.to_json
file.proppatch('<v:publish-date xmlns:v="vrtx">' + Time.now.httpdate.to_s + '</v:publish-date>')
#!/usr/bin/perl -w # camel code
use strict;
$_='ev
al("seek\040D
ATA,0, 0;");foreach(1..3)
{<DATA>;}my @camel1hump;my$camel;
my$Camel ;while( <DATA>){$_=sprintf("%-6
9s",$_);my@dromedary 1=split(//);if(defined($
_=<DATA>)){@camel1hum p=split(//);}while(@dromeda