Skip to content

Instantly share code, notes, and snippets.

View dreamcat4's full-sized avatar
😋
credible honest persons who wants to talk to me... send brief msg to my gmail !

Dreamcat4 dreamcat4

😋
credible honest persons who wants to talk to me... send brief msg to my gmail !
View GitHub Profile
@dreamcat4
dreamcat4 / cli-reference.sh
Created April 26, 2009 11:40
Comand line reference
# GIT
# create a new branch named <new_branch> and start it at origin/master
git-checkout -b <new_branch> origin/master
# continue on an existing branch
git-checkout origin/master
# Split a hunk for staging
git add --patch
@dreamcat4
dreamcat4 / cocoa-snippets.m
Created April 26, 2009 13:00
Cocoa snippets
// Is hostname reachable ?
- (BOOL) isReachable:(NSString *)hostname
{
SCNetworkConnectionFlags flags;
if (!SCNetworkCheckReachabilityByName([hostname cStringUsingEncoding:NSASCIIStringEncoding], &flags))
return FALSE;
// If a connection is required, then it's not reachable
if (flags & (kSCNetworkFlagsConnectionRequired | kSCNetworkFlagsConnectionAutomatic | kSCNetworkFlagsInterventionRequired))
return FALSE;
# Install mysql adaptor for ruby 1.9
gem install kwatch-mysql-ruby -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
@dreamcat4
dreamcat4 / example.rb
Created April 29, 2009 17:13
Ruby snippets
# jsquared: given an array with contents like ["47", 12, "hello"],
# how do I prefix each element with a given string and then join
# the elements together with another string? for example, something like
# ["47", 12, "hello"].join_with_prefix("+", "**") should give me +47**+12**+hello
array = ["47", 12, "hello"]
result = String.new()
array.each do | s |
s.join_with_prefix("+", "**")
@dreamcat4
dreamcat4 / geokit_config.rb
Created April 30, 2009 15:24
Example Geocoder in an external file
# Add the following lines to your geokit configuration
require "geocoder_maxmind_city.rb"
# This is your authorization key for MaxMind's geoip city web service.
# Paid alternative to the free hostip.info ip Geocoder
# See http://www.maxmind.com/app/web_services#country
# Set the value to the 12-digit key obtained from MaxMind.
Geokit::Geocoders::maxmind_city = 'REPLACE_WITH_YOUR_MAXMIND_KEY'
# Valid symbols are :ip,:geonames,:geo_plugin, and :maxmind_city.
# As before, make sure you read up on relevant Terms of Use for each
@dreamcat4
dreamcat4 / geocoders.rb
Created May 13, 2009 18:51
External geocoders example
# (MY CHANGES)
def self.geocode(address)
res = do_geocode(address)
return res ? res : GeoLoc.new
end
# (ORIGINAL - YOUR CHANGES)
def self.geocode(address)
res = do_geocode(address)
return res.success? ? res : GeoLoc.new
@dreamcat4
dreamcat4 / .profile
Created June 4, 2009 16:28
ruby in .profile
export GEM_HOME=$HOME/.gem/ruby/active
export PATH=$HOME/.gem/ruby/active/bin:$PATH
@dreamcat4
dreamcat4 / shoulda.rb
Created July 5, 2009 17:55
Shoulda macros
class Test::Unit::TestCase
# http://programblings.com/2008/10/31/two-shoulda-best-practices/
# Sets the current person in the session from the person fixtures.
def self.logged_in_as(person, &block)
context "logged in as #{person}" do
setup do
@request.session[:person] = people(person).id
end
# chef-server as ssh tunnel (reverse-proxy) for Mac OS X 10.6 SL
# Based loosely on Readme.rdoc - http://github.com/opscode/chef/
# port install CouchDB (may be broken on Snow Leopard)
sudo port install couchdb-devel
sudo launchctl load -w /Library/LaunchDaemons/org.apache.couchdb.plist
sudo launchctl unload -w /Library/LaunchDaemons/org.apache.couchdb.plist
# check for Trace/BPT trap error
couchdb
CTRL ^C
@dreamcat4
dreamcat4 / chef-client_404_no_reg.rb
Created October 29, 2009 22:37
Missing registration entry for new node (localhost address)
janitors-Mac-mini:~ id$ sudo chef-client --config /etc/chef/client.rb --token 162a81fc9c30ade3e021ea084d72df29 -l debug
[Thu, 29 Oct 2009 22:33:09 +0000] INFO: Starting Chef Run
[Thu, 29 Oct 2009 22:33:09 +0000] DEBUG: Loading plugin os
[Thu, 29 Oct 2009 22:33:09 +0000] DEBUG: Loading plugin ruby
[Thu, 29 Oct 2009 22:33:09 +0000] DEBUG: Loading plugin languages
[Thu, 29 Oct 2009 22:33:11 +0000] DEBUG: Loading plugin kernel
[Thu, 29 Oct 2009 22:33:11 +0000] DEBUG: ---- Begin uname -s STDOUT ----
[Thu, 29 Oct 2009 22:33:11 +0000] DEBUG: Darwin
[Thu, 29 Oct 2009 22:33:11 +0000] DEBUG: ---- End uname -s STDOUT ----
[Thu, 29 Oct 2009 22:33:11 +0000] DEBUG: ---- Begin uname -s STDERR ----