Skip to content

Instantly share code, notes, and snippets.

View larsar's full-sized avatar

Lars Preben Sørsdahl larsar

View GitHub Profile
[HKEY_CLASSES_ROOT\Directory\shell\sublime]
@="Open Folder as &Sublime Project"
[HKEY_CLASSES_ROOT\Directory\shell\sublime\command]
@="\"C:\\Program Files\\Sublime Text\\sublime_text.exe\" \"%1\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\sublime]
@="Open Folder as &Sublime Project"
[HKEY_CLASSES_ROOT\Directory\Background\shell\sublime\command]
@larsar
larsar / gist:4622148
Created January 24, 2013 14:18
javac windows encoded files with Norwegian characters.
# Option for javac to accept java files with nasty Windows encoding:
-encoding cp1252
# Checkout
git tag # List tagged versions
git checkout -b prodfix <version> # Checkout specific version into prodfix branch
# Fix code and commit
# Test in staging (requires compatible database state)
git push staging +HEAD:master # Push to staging
# Put in producton

Install Python

$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...

@larsar
larsar / add_sendgrid_recipient_list_with_non_duplicates.rb
Created March 8, 2013 21:59
Adds email,name from a csv file to a new Sendgrid recipient list. Only emails that are not already on an existing recipient list are added to the new one.
require 'CSV'
require 'rest_client'
require 'json'
USERNAME=""
PASSWORD=""
URL_POSTFIX = "&api_user=#{USERNAME}&api_key=#{PASSWORD}"
SOURCE_LIST=""
NEW_LIST=""
CSV_FILE=""
@larsar
larsar / syslog.py
Created March 19, 2013 12:43
Syslogging from Python
import logging
from logging.handlers import SysLogHandler import socket
def syslogger(hostname, tag):
logger = logging.getLogger()
logger.setLevel(logging.INFO)
syslog = SysLogHandler(address=('syslogserver', 514), facility="local4")
formatter = logging.Formatter(hostname + ' ' + tag + ' %(levelname)s %(message)s')
syslog.setFormatter(formatter)
logger.addHandler(syslog)
@larsar
larsar / dynamic_layout_application_controller.rb
Last active December 15, 2015 04:39
Multiple layouts based on request parameter in Rails. Layout in URL parameter overrides cookies.
class ApplicationController < ActionController::Base
layout :resolve_layout
# ....
private
def resolve_layout
layout ||= params[:layout]
layout ||= cookies[:layout]
@larsar
larsar / wait_for_bg_process.sh
Created May 28, 2013 10:22
Example shell script for forking processes in parallell and then waiting for them to finish.
#!/bin/bash
pids=()
# Snooooze for two seconds
function do_stuff {
sleep 2
}
# Starts 10 processes
import os
import simplejson
import subprocess
import datetime
f = open('latitude.json', 'r')
locdata = simplejson.loads(f.read());
fd = open('latitude.gpx', 'w')
fd.write("""# <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
module Delayed
module Plugins
class Airbrake < Plugin
module Notify
def error(job, error)
::Airbrake.notify_or_ignore(error)
super
end
end