Skip to content

Instantly share code, notes, and snippets.

View samnang's full-sized avatar
🚀

Samnang Chhun samnang

🚀
View GitHub Profile
@samnang
samnang / Rakefile
Created April 29, 2011 03:57
Register RSpec rake's tasks
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
rescue LoadError
task :spec do
abort "Please run `bundle install` to install RSpec."
end
end
@samnang
samnang / users.md
Created June 29, 2011 17:54 — forked from jordanbyron/users.md
Discussion and design ideas for University Web's User API

le API design

A consumer needs to lookup a single user by their github name (jordanbyron). That consumer doesn't know the user's ID. There is a possibility to also search by email and twitter.

"/users.json?github=jordanbyron"
=> [{github: "jordanbyron", id: 1}]

When there are no results an empty array is returned

"/users.json?github=noexist"

require 'test/unit/assertions'
include Test::Unit::Assertions
assert_equal "1.9.2", RUBY_VERSION
# A Ruby meta-programming puzzle for polite programmers.
# This puzzle was created by Matt Wynne (@mattwynne) on 2011-04-10 inspired by Jim Weirich's
# talk at the Scottish Ruby Conference 2011.
#
# The challenge is: you have a class Foo which you want to monkey-patch, but politely.
@samnang
samnang / thinking_sphinx)
Created August 20, 2011 14:12 — forked from ancorcruz/thinking_sphinx)
Thinking Sphinx init.d script
#!/bin/bash -e
### BEGIN INIT INFO
# Provides: thinking_sphinx
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop Sphinx daemon for Thinking Sphinx
### END INIT INFO
CONFIG_FILE=/etc/default/thinking_sphinx.conf
. $CONFIG_FILE || exit
@samnang
samnang / gist:1159235
Created August 20, 2011 15:29
Completely remove mysql-server
sudo apt-get purge mysql-server
sudo apt-get purge mysql-client
sudo apt-get purge mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-cache rdepends mysql-server
sudo apt-cache rdepends mysql-client
@samnang
samnang / ruby_enterprise.rb
Created August 21, 2011 17:22
Sprinkle: install Ruby Enterprise
package :ruby_enterprise do
description 'Ruby Enterprise Edition'
version '1.8.7-2011.03'
REE_PATH = "/usr/local/ruby-enterprise"
binaries = %w(erb gem irb rackup rails rake rdoc ree-version ri ruby testrb)
source "http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-#{version}.tar.gz" do
custom_install 'sudo ./installer --auto=/usr/local/ruby-enterprise'
binaries.each {|bin| post :install, "ln -s #{REE_PATH}/bin/#{bin} /usr/local/bin/#{bin}" }
end
@samnang
samnang / rspec-syntax-cheat-sheet.rb
Created September 1, 2011 05:09 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@samnang
samnang / rails31init.md
Created September 3, 2011 16:27 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@samnang
samnang / gist:1205781
Created September 9, 2011 08:42
Using view_context
# app/controllers/posts_controller.rb
class PostsController < ActionController::Base
def show
# ...
tags = view_context.generate_tags(@post)
email_link = view_context.mail_to(@user.email)
# ...
end
end
@samnang
samnang / gist:1213607
Created September 13, 2011 11:11
Git global configuration
$ git config --global user.name "Samnang Chhun"
$ git config --global user.email "[email protected]"
$ git config --global color.ui true
$ git config --global alias.st status
$ git config --global alias.ci commit
$ git config --global alias.br branch
$ git config --global alias.co checkout
$ git config --global alias.df diff