Skip to content

Instantly share code, notes, and snippets.

View hc5duke's full-sized avatar

Hwan-Joon Choi hc5duke

View GitHub Profile
@hc5duke
hc5duke / pre-commit
Created November 2, 2012 18:32
pre-commit hook
#!/usr/bin/env ruby
# copy or symlink this file to .git/hooks/
# automatically strip spaces from the end of lines and add newlines to the end of files as necessary
filetypes = %w(
builder
conf
css
erb
haml
@hc5duke
hc5duke / delegation2.rb
Created October 8, 2012 08:11
sort of kind of delegate
class SubCity < ActiveRecord::Base
belongs_to :city
delegate :map, to: :sub_cities, prefix: true
end
# later
city.sub_cities_map(&:name)
@hc5duke
hc5duke / delegations.rb
Created October 8, 2012 07:02
delegations
delegate :names, to: :sub_cities, prefix: true
# undefined method `names' for #<ActiveRecord::Relation>
delegate :name, to: :sub_cities, prefix: true
# => "SubCity"
delegate :name, to: :sub_city, prefix: true
delegate :names, to: :sub_city, prefix: true
# undefined local variable or method `sub_city' for #<City>
@hc5duke
hc5duke / city.rb
Created October 8, 2012 07:00
city and sub_cities
# sub_city.rb
class SubCity < ActiveRecord::Base
belongs_to :city
def sub_cities_names
sub_cities.map(&:name)
end
end
# city.rb
class City < ActiveRecord::Base
@hc5duke
hc5duke / parent.html
Created September 17, 2012 04:16
Four Seasons html injection
<html>
<head>
<meta http-equiv="Expires" content="Mon, 01 Jan 1900 00:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<script type='text/javascript'>
<!--
if (window.parent != window) {
document.location = "http://mail.tapjoy.com/";
}
//-->
@hc5duke
hc5duke / parse.rb
Created July 30, 2012 06:00
Parse GZipped results
#!/usr/bin/env ruby
require 'active_support'
gzips = {
:java => [31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -77, 41, 74, 45, 44, 77, 45, 46, -79, -77, 41, -120, -49, 76, -79, 51, 50, 48, -78, -80, -47, 7, 51, 109, -118, -13, 75, -117, -110, 83, -29, 75, 42, 11, 82, -19, 12, 108, -12, -111, -71, 54, -6, 48, 109, 0, -21, -40, -25, -121, 64, 0, 0, 0],
:ruby => [31, -117, 8, 0, 32, 45, 19, 80, 0, 3, -77, 41, 74, 45, 44, 77, 45, 46, -79, -77, 41, -120, -49, 76, -79, 51, 50, 48, -78, -80, -47, 7, 51, 109, -118, -13, 75, -117, -110, 83, -29, 75, 42, 11, 82, -19, 12, 108, -12, -111, -71, 54, -6, 48, 109, 0, -21, -40, -25, -121, 64, 0, 0, 0],
}
def formatted_put(text, comment)
text = text.join(' ') if text.is_a? Array
@hc5duke
hc5duke / count.rb
Created June 1, 2012 01:27
rank choice voting
#!/usr/bin/env ruby
require 'rubygems'
require 'time'
require 'csv'
require './hist'
votes = {}
def old_vote?(votes, name, time)
votes[name] && votes[name][:time] > time
@hc5duke
hc5duke / demo1_check_app_version_20.sh
Created April 2, 2012 06:14
Example Usage of Kiteboard
# App Version = 2.0; Tell user to upgrade to latest version
# Found at: http://hurl.it/hurls/14d678ab1729dbec83529e0e7021f54dcf0f0cc9/23c1b3701e97366d2c389f18a64cb199adbc06e1
$ curl -X post www.kiteboard.me/api/api/call.xml --data app_id=4f73f48b4f15a90001000001\&data[app_version]=2.0
@hc5duke
hc5duke / git_info.bash
Created January 11, 2012 08:49
Git info in PS1
git_info() {
# colors
local RESET="\033[0m"
local GRAY="\033[1;30m"
local RED="\033[1;31m"
local GREEN="\033[1;32m"
local BLUE="\033[1;34m"
local PINK="\033[1;35m"
local CYAN="\033[1;36m"
@hc5duke
hc5duke / pre-commit
Created October 5, 2011 23:42
pre-commit hook
#!/bin/sh
files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
if [ "$files" != "" ]
then
for f in $files
do
# Only examine known text files
if [[ "$f" =~ [.](conf|css|erb|html|haml|scss|css|js|json|log|properties|rb|ru|txt|xml|yml)$ ]]
then