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
@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 / 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 / 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
# -*- 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|
def Math.pow(x,y)
x**y
end
## Converts from utm to lat_lng. Default zone is the one in which
## Oslo and Akershus falls.
def utm_to_lat_lng(easting, northing, zone=32, northernHemisphere=true)
if not northernHemisphere then
northing = 10000000 - northing
end
We couldn’t find that file to show.
# -*- coding: utf-8 -*-
# Generer vortex sitemap. Eksempel:
#
# $generate_vortex_sitemap.rb http://www.iss.uio.no/
#
# Author: Thomas Flemming, thomas.flemming@usit.uio.no 2010
#
require "net/https"
require "uri"
require 'rubygems'
require 'vortex_client'
include Vortex
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/", ENV['DAVUSER'], ENV['DAVPASS'])
vortex.cd('/brukere/thomasfl/events/')
collection = ArticleListingCollection.new(:url => 'my-collection', :title => 'My articles')
path = vortex.create(collection)
puts "Created folder: " + path
require 'rubygems'
require 'vortex_client'
include Vortex
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
vortex.cd('/brukere/thomasfl/events/')
event = HtmlEvent.new(:title => "My Sample Event 1",
:introduction => "Sample event introduction",
:body => "<p>Hello world</p>",
:startDate => "19.06.2010 17:56",