Skip to content

Instantly share code, notes, and snippets.

View larsar's full-sized avatar

Lars Preben Sørsdahl larsar

View GitHub Profile
@larsar
larsar / authentications_controller.rb
Created November 21, 2013 12:33
FEIDE authentication controllers for Rails, using "omniauth". Code written mostly by Christian Martin. https://github.com/cmartin81
class AuthenticationsController < ApplicationController
def index
if current_user
@authentications = current_user.authentications
else
redirect_to root_path
end
end
def create
module Delayed
module Plugins
class Airbrake < Plugin
module Notify
def error(job, error)
::Airbrake.notify_or_ignore(error)
super
end
end
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" ?>
@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 / 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 / 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=""

Install Python

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

Symlinks...

# 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
@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
[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]