Skip to content

Instantly share code, notes, and snippets.

View mrrooijen's full-sized avatar

Michael van Rooijen mrrooijen

View GitHub Profile
@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)
@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 / 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 / out-of-memory.sh
Last active August 29, 2015 14:08
Dokku Information
echo 1 > /proc/sys/vm/overcommit_memory
@mrrooijen
mrrooijen / Git-Ignore
Created July 29, 2009 09:41
Git Ignore File for my Capistrano recipe
# Author: Michael van Rooijen
# Description:
# If you are using my Capistrano Recipe, be sure to add these lines to your .gitignore file.
# It will prevent problems when deploying incase your generated the all.js/all.css, assets, database.yml etc.
# Assets and Database yaml should be stored in the "shared" section of the application, not inside the actual application with every release.
.DS_Store
log/*.log
tmp/**/*
config/database.yml
@mrrooijen
mrrooijen / nginx
Created July 29, 2009 09:44
A script to enable easy start/stop functionality for the NginX Web Server.
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@mrrooijen
mrrooijen / jQuery-Plugin-Template.js
Created July 29, 2009 11:04
A jQuery Plugin Template.
(function($){
/**
* jQuery PluginName
*
* @plugin {PluginName}
* @description {PluginDescription}
*
* @changelog
* @{mm/dd/yyyy} {version} {author} {changedescription}
# Inside the model.rb
has_attached_file :image,
:url => "/assets/images/:style/:id.:basename.:extension",
:path => ":rails_root/public/assets/images/:style/:id.:basename.:extension",
:styles => {
:small => '50x45#',
:medium => '150x150',
:large => '300x300'
}
# Place this line below in your environment.rb to remove the Form Error Decorations that display when the form validation failed.
ActionView::Base.field_error_proc = proc { |input, instance| input }
.CodeRay {
background-color: #232323;
border: 1px solid black;
font-family: 'Courier New', 'Terminal', monospace;
color: #E6E0DB;
padding: 3px 5px;
overflow: auto;
font-size: 12px;
margin: 12px 0;
}