Skip to content

Instantly share code, notes, and snippets.

View patrikjohansson's full-sized avatar

Patrik Johansson patrikjohansson

  • Gothenburg, Sweden
View GitHub Profile
@patrikjohansson
patrikjohansson / read.rb
Created October 16, 2012 00:23
Convert history.plist to csv
# encoding: UTF-8
####
# Converts Safaris history file (history.plist) into csv (tab)
# Dependency: nokogiri
# Usage: ruby read.rb input.plist output.csv
###
require "rubygems"
require "nokogiri"
@patrikjohansson
patrikjohansson / evernote_randomizer.applescript
Last active December 23, 2015 02:29
Opens X number of random evernote notes from a collection of notebooks
display dialog "Number of random notes?" default answer "1"
set iterations to (text returned of result)
tell application "Evernote"
-- Fetch all notebooks that the notes shoukd be randomized from
set allNotebooks to every notebook whose name does not contain "kentor" and notebook type is synchronized
// ==UserScript==
// @name vasttrafiklabs
// @description Removes the nag screen from labs.vasttrafik.se
// @grant none
// @version 0.0.23
// @include https://labs.vasttrafik.se/*
// @include http://labs.vasttrafik.se/*
// ==/UserScript==
var elements = document.getElementsByTagName("div");
#!/bin/sh
# Adds story/ticket number to original git commit template
# Add this file to .git/hooks/
git_commit_file=$1
temp=`mktemp /tmp/git-commit-message-XXXXXX`
story_number=`git branch | grep '^\*' | grep -o '[1-9][0-9]*$'`
# encoding: UTF-8
module StringToDatetimeForSoap
def to_datetime
begin
if /^([+\-]?\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ self.strip
return Time.xmlschema(self).localtime
end
super
rescue
# If a invalid date is supplied, it will automatically turn it into the first Julian Day
bunny = Bunny.new(:host => "localhost" )
bunny.start
APP_CONFIG[:asset_sync_bindings].each do |e|
queue = bunny.queue e[:queue], :durable => true
exchange = bunny.exchange e[:exchange] , :durable => true , :type => :fanout
queue.bind exchange
end
2012-02-08 04:00:49 CET [11602]: [2-1] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2012-02-08 04:00:49 CET [11602]: [3-1] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2012-02-08 04:00:50 CET [31876]: [13-1] LOG: all server processes terminated; reinitializing
2012-02-08 04:00:56 CET [31876]: [14-1] FATAL: could not create shared memory segment: Kan inte allokera minne
2012-02-08 04:00:56 CET [31876]: [15-1] DETAIL: Failed system call was shmget(key=5444001, size=9673490432, 03600).
2012-02-08 04:00:56 CET [31876]: [16-1] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 9673490432 bytes), reduce PostgreSQL's shared_buffers parameter (currently 1152000) and/or its max_connections parameter (currently 30
def serialize(key, value, options=nil)
marshalled = false
value = unless options && options[:raw]
marshalled = true
begin
Marshal.dump(value)
rescue => ex
# Marshalling can throw several different types of generic Ruby exceptions.
# Convert to a specific exception so we can special case it higher up the stack.
exc = Dalli::MarshalError.new(ex.message)
require "rubygems"
require "bunny"
require "pp"
bunny = Bunny.new(:host => "127.0.0.1", :port => 15672)
bunny.start
pp bunny.status
# Send message
@patrikjohansson
patrikjohansson / gist:1415070
Created December 1, 2011 08:42
Problem when looping over arrays with objects
# Adding a tweet with an array of tags and an array with weights for each detected language.
curl -XPUT http://localhost:9201/twitter/tweet/1 -d '
{
"tags" : ["foo", "bar"],
"weights" : [{"lang":"eng", "weight":0.97}, {"lang":"swe", "weight":0.03}]
}
'
{"ok":true,"_index":"twitter2","_type":"tweet","_id":"1","_version":1}
--------