Skip to content

Instantly share code, notes, and snippets.

View paydro's full-sized avatar
💨

Peter Bui paydro

💨
View GitHub Profile
#######################################################
# Add this to app/controllers/application_controller.rb
#######################################################
def render_json_response(type, hash)
unless [ :ok, :redirect, :error ].include?(type)
raise "Invalid json response type: #{type}"
end
# To keep the structure consistent, we'll build the json
# structure with the default properties.
require 'minitest/unit'
require 'minitest/spec'
require 'rubygems'
require 'ansi'
class MiniTest::Unit
include ANSI::Code
PADDING_SIZE = 4
@paydro
paydro / apache_rewrite.conf
Created November 27, 2010 14:39
redirect all requests to a particular file - useful for php
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule .* index.php [L]
@paydro
paydro / controller.rb
Created January 14, 2011 21:52
Sample js_message javascript call
# corresponding rails action that handles the js_message call. Note the format.jsm calls in the
# respond_to block
def create
@task = Task.new(params[:task])
respond_to do |format|
if @task.save
format.html { redirect_to(tasks_path, :notice => 'Task was successfully created.') }
format.jsm do
render_js_message(:ok, :html => "it saved!")
@paydro
paydro / git-rsync.sh
Created February 15, 2011 02:16
rsync changed files in a git repo to a remote server
git status -s | awk '{print $2}' | sed 's/\(.*\)/rsync -cav \1 [email protected]:~\/\1/' | sh
@paydro
paydro / gist:1140999
Created August 11, 2011 22:48
Allows #context calls in Rails 3 tests like rspec/minitest spec
# Create a context block like rspec.
#
# Inspired by:
# - MiniTest::Spec
# - Chris Wanstrath's https://gist.github.com/25455
#
# Examples:
#
# class UserTest < ActiveSupport::TestCase
# context "Auth" do
@paydro
paydro / fancybuttons.css
Created August 20, 2011 22:38
Fancy buttons via css
/* Fancy buttons */
.buttons a,
.buttons input,
input.button,
.button {
font-family: "Helvetica Neue", Verdana,Helvetica, sans-serif;
font-size: 12px;
padding: 5px 10px;
@paydro
paydro / commandline.sh
Created January 17, 2012 18:37
What is running on X port
lsof -i TCP:80
@paydro
paydro / bootstrap.sh
Created April 27, 2012 20:50
MapReduce Files
#!/usr/bin/env bash
#
# This script is run as the 'hadoop' user - which means any commands
# that create/update privileged areas must use sudo.
# Print out every command executed in this script.
set -x
# Exit this script if any of the commands below fail.
set -e
@paydro
paydro / wrapper.sh
Created May 16, 2012 20:58
Monit wrapper script that start/stops a process that doesn't use a pid
#!/usr/bin/env bash
case $1 in
start)
PID=$(start statsd | awk '{print $4}');
echo $PID > /var/run/statsd.pid;
;;
stop)
kill `cat /var/run/statsd.pid` ;;
*)