This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple Makefile alternative to using Grunt for your static asset compilation | |
# | |
## Usage | |
# | |
# $ npm install | |
# | |
# And then you can run various commands: | |
# | |
# $ make # compile files that need compiling | |
# $ make clean all # remove target files and recompile from scratch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: link_to …, prompt: { message: 'Some message', default: 'default value', param: 'name of parameter' } | |
# The prompt will ask for "message" and use "default" as the default value. | |
# Unless user selects cancel, "param"=<new value> will be sent to the given path. | |
# Optionally, you can just use `prompt: "message"`. | |
$.rails.prompt = (message, defaultValue) -> | |
window.prompt message, defaultValue | |
$.rails.handlePrompt = (element) -> | |
config = element.data 'prompt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 3 # amount of unicorn workers to spin up | |
timeout 30 # restarts workers that hang for 30 seconds | |
preload_app true | |
GC.respond_to?(:copy_on_write_friendly=) and | |
GC.copy_on_write_friendly = true | |
before_fork do |server,worker| | |
defined?(ActiveRecord::Base) and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resize_nocrop_noscale(image, w,h) | |
w_original = image[:width].to_f | |
h_original = image[:height].to_f | |
if w_original < w && h_original < h | |
return image | |
end | |
# resize | |
image.resize("#{w}x#{h}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def daemonize(name = File.basename($0), options = {}) | |
pid_path = options[:pid_path] || File.expand_path("tmp/pids/#{name}.pid") | |
# If the pid file exists, check that the process is actually still running. | |
begin | |
if File.exists?(pid_path) && Process.kill(0, File.read(pid_path).to_i) | |
$stderr.puts "Already running." | |
exit 1 | |
end | |
rescue Errno::ESRCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find and replace text in multiple files | |
# http://www.24hourapps.com/2009/03/linux-tips-17-find-and-replace-text-in.html | |
# Multiple file find and replace is a rarely used, but an extremely time saving, ability of | |
# Linux that I cannot live without. It can be achieved by chaining a few commands together | |
# to get the list of files you want to change (find), make sure the files contain the strings | |
# you want to replace (grep), and do the replacements (sed). | |
# Lets say we have a lot of code that uses the function registerUser that was implemented when | |
# there was only one class of users, but now another class of users need to access the system |
NewerOlder