Skip to content

Instantly share code, notes, and snippets.

View haraldmartin's full-sized avatar
🌝

Martin Ström haraldmartin

🌝
View GitHub Profile
@haraldmartin
haraldmartin / scheduled_job.rb
Created November 14, 2012 13:22 — forked from kares/scheduled_job.rb
Recurring Job using Delayed::Job
#
# Recurring Job using Delayed::Job
#
# Setup Your job the "plain-old" DJ (perform) way, include this module
# and Your handler will re-schedule itself every time it succeeds.
#
# Sample :
#
# class MyJob
# include Delayed::ScheduledJob
@haraldmartin
haraldmartin / convert.sh
Created February 21, 2012 15:46
Convert database to UTF-8
mysqldump --user=username --password --default-character-set=latin1 --skip-set-charset dbname > dump.sql
sed 's/latin1/utf8/g' dump.sql > dump_utf.sql
mysql --user=username --password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --user=username --password --default-character-set=utf8 dbname < dump_utf.sql
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
html, body, .document, #aspnetForm { height: 100%; }
.document { display: table; }
html.ie7 .document { height: auto; min-height: 100%; }
@haraldmartin
haraldmartin / Set active Time Machine Disk.applescript
Created November 27, 2010 16:18
Set active Time Machine Disk
property pth : (path to preferences folder from local domain) as text
property d1name : "WD My Book"
property d1 : "com.apple.TimeMachine RF9.plist"
property d2name : "AirDisk"
property d2 : "com.apple.TimeMachine Home.plist"
property active : "com.apple.TimeMachine.plist"
# 2010-10-01
#
# Mac OS X 10.6.3
# Homebrew 0.7
# Xcode 3.2.4
# Git 1.7.3.1
# RVM 1.0.12
# Ruby 1.8.7, 1.9.2
# Passenger 2.2.15
# MySQL 5.1.49
Sets.updateTitle(collection.name, collection.icon);
// Sets.highlightActive(link);
<?php
$filepath = dirname(__FILE__) . "your_xml_file.xml";
$contents = file_get_contents($filepath);
$elements = @new SimpleXmlElement($contents);
# do somethings with the elements
print_r($elements);
?>
#
# TextMate command to copy an url to the current file (with line & column)
# Input: None
# Output "Show as Tool Tip"
#
url="txmt://open?url=file://$TM_FILEPATH&line=$TM_LINE_NUMBER&column=$TM_COLUMN_NUMBER"
echo -n "$url" | pbcopy
echo "Copied $url"
Element.addMethods({
getValueOrHTML: function(element) {
element = $(element);
var tagName = element.tagName.toLowerCase();
if (tagName === 'input')
return element.getValue();
else if (tagName === 'form')
return element.readAttribute('action');
else