Follow these steps to install graphite on OS X Mavericks.
- Homebrew
- Python 2.7
- Git
| # 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 |
| 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 |
| # 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 |
| 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}") |
| 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 |
| # 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' |
| # 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 |
| #!/bin/bash | |
| set -exo pipefail | |
| BUILD_ENV=$1 | |
| if [ `uname` == 'Darwin' ]; then | |
| OSX=1 | |
| JSCOMPRESSOR="yuicompressor --type js" | |
| else | |
| OSX= |
| #!/usr/bin/env ruby --disable-gems | |
| # Roll your own two-factor authentication! Place this file on a USB key, make | |
| # it executable, then run: | |
| # | |
| # two-factor --setup | |
| # | |
| # Now place each TOTP secret in its own file in the `keys/` directory. I like | |
| # to name them after the website they apply to, but any name is fine. To | |
| # generate a token, plug in your USB key and: |