Skip to content

Instantly share code, notes, and snippets.

View mrrooijen's full-sized avatar

Michael van Rooijen mrrooijen

View GitHub Profile
@mrrooijen
mrrooijen / cmd.sh
Last active August 18, 2017 10:38
iCloud Drive shortcut on Desktop.
ln -nfs "~/Library/Mobile Documents/com\~apple\~CloudDocs" "~/Desktop/iCloud Drive"
package main
import (
"fmt"
"github.com/codegangsta/negroni"
"github.com/julienschmidt/httprouter"
"net/http"
)
func main() {
@mrrooijen
mrrooijen / countries.js
Last active May 27, 2016 13:27
A list of country codes and names
COUNTRIES = {
"US": "United States",
"AF": "Afghanistan",
"AX": "Åland Islands",
"AL": "Albania",
"DZ": "Algeria",
"AS": "American Samoa",
"AD": "Andorra",
"AO": "Angola",
"AI": "Anguilla",
@mrrooijen
mrrooijen / out-of-memory.sh
Last active August 29, 2015 14:08
Dokku Information
echo 1 > /proc/sys/vm/overcommit_memory
@mrrooijen
mrrooijen / resque_stale_worker_cleaner.rb
Last active August 29, 2015 14:07
Prune stale Resque workers.
class ResqueStaleWorkerCleaner
SLOWEST_JOB = (ENV["SLOWEST_JOB"] || 30).to_i # minutes
def call
Resque.workers.each do |worker|
worker.unregister_worker if old_worker?(worker)
end
end
private
@mrrooijen
mrrooijen / api_base_controller.rb
Last active August 29, 2015 14:05
Ember.js + Rails API setup with header-based API key and API version configuration.
class Api::BaseController < ActionController::Base
protect_from_forgery with: :null_session
before_action :unauthorized_if_signed_out
layout false
def current_user
@current_user ||= (
authenticate_or_request_with_http_token do |token, options|
User.find_by(api_key: token)
end
@mrrooijen
mrrooijen / lib_utils_coders_marshal.rb
Last active August 29, 2015 13:57
Marshal serializer for ActiveRecord 4.
module Coders
class Marshal
attr_reader :klass
def initialize(klass)
@klass = klass
end
def load(data)
app.value "Ticket",
class Ticket
console.log "defined once"
constructor: (@price, @count) ->
console.log "new instance constructed"
amount: ->
@price * parseInt(@count, 10)
@mrrooijen
mrrooijen / hdiutil.sh
Last active January 2, 2016 22:59
Set of commands for creating OSX Journaled (Extended) Encrypted images. Attaching them. Detaching them. Attaching them on system boot.
# Create a 10 megabytes, blank, AES 256 Encrypted, with password "mypassword",
# MacOS Journaled (Extended) image named "MyImage" when attached,
# and myimage.dmg as filename in the current directory.
#
echo -n "mypassword" | hdiutil create \
-encryption AES-256 \
-stdinpass \
-size 10m \
-fs "Journaled HFS+" \
-volname MyImage \
@mrrooijen
mrrooijen / chat.rb
Created December 11, 2013 16:33 — forked from mig-hub/chat.rb
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do