Skip to content

Instantly share code, notes, and snippets.

@happyrobots
happyrobots / gist:1862963
Created February 19, 2012 10:17
Copy to Clipboard Using Ruby
# Mac
IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts html_out }
# Linux
IO.popen(’xsel –clipboard –input’, ‘r+’) { |clipboard| clipboard.puts html_out }
@happyrobots
happyrobots / measure.rb
Created May 17, 2012 03:43
Stuff from HAR
#!/usr/bin/env ruby
require 'json'
def group_time_by_hosts(raw)
result = {}
raw["log"]["entries"].each do |entry|
url = entry["request"]["url"]
addr = url.split('/')[2]
addr = addr.split('.')[-2..-1] if addr
@happyrobots
happyrobots / MiniMapper.h
Created August 23, 2012 17:13
Mini Mapper
/*
Usage:
1. Initialize
MiniMapper *m = [MiniMapper new];
2. Map
[m forClass:[MyClass class] mapAttributes:^(NSMutableDictionary *dict) {
[dict setObject:@"my_attribute"
forKey:@"my_property"];
@happyrobots
happyrobots / input-appearance.css
Created December 30, 2012 11:47
disable default input form appearance
input {
-webkit-appearance: none;
-moz-appearance: none;
}

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

[alias]
try-prune = remote prune --dry-run
serve = daemon --reuseaddr --verbose --base-path=. --export-all ./.git
assume = update-index --assume-unchanged
unassume = update-index --no-assume-unchanged
st = status
ru = remote update
rv = remote -v
pom = push origin master
pr = pull --rebase
# spec/features/home_controller_spec.rb
require 'spec_helper'
describe HomeController do
describe "index" do
it "should check title page" do
visit '/home'
# puts "#{page.html}"
page.should have_content('I can has')
page.should have_selector('p', text: "I can has a content")
#!/bin/bash
sorted_commit_counts=`git shortlog -ns`
echo
echo "Commit Statistics by Authors"
echo "================================================"
echo
i=1
while read -r line; do
@happyrobots
happyrobots / NSArray+BinarySearch.h
Created May 8, 2013 06:24
An Objective-C BinarySearch category on Array of which members are String. http://www.getappninja.com/blog/implementing-a-binary-search-in-ios
@interface NSArray (BinarySearch)
// Before calling this method, make sure this array is an array of string and it is sorted using sortedArrayUsingSelector:
// NSArray *sortedArray = [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
- (unsigned long)indexOfStringUsingBinarySearch:(NSString *)searchString;
@end
class Array
def quick_sort
n = self.size
return self if n <= 1
pivot = self.last
less, more = [], []
for i in 0...n-1
item = self[i]
if item < pivot