Skip to content

Instantly share code, notes, and snippets.

View codespore's full-sized avatar
🔍
Looking for my next mission

Adrian Teh codespore

🔍
Looking for my next mission
View GitHub Profile
@codespore
codespore / arel_joins.rb
Created October 5, 2011 08:01
Left outer joining 2 fields referring to same User model in Rails 3
t = Task.arel_table
u = User.arel_table
c = u.alias("creators")
keyword = "%#{params}%"
relation = joins("LEFT OUTER JOIN users ON users.id = tasks.user_assigned_id")
.joins("LEFT OUTER JOIN users as #{c.name} ON #{c.name}.id = tasks.creator_id")
.where(
t[:id].matches(keyword)
@codespore
codespore / arel_joins.rb
Created October 9, 2011 03:17
Left outer joining 2 fields referring to same User model in Rails 3 (Part 2)
t = Task.arel_table
u = User.arel_table
c = u.alias("creators_tasks")
keyword = "%#{params}%"
relation = includes(:user_assigned,:creator)
.where(
t[:id].matches(keyword)
.or(u[:username].matches(keyword))
@codespore
codespore / config.ru
Created February 2, 2012 02:08
Simples Rack App
class SimpleRackApp
def call(env)
[200, {'Content-Type' => 'text/plain'}, ["Hello World!"]]
end
end
run SimpleRackApp.new
@codespore
codespore / config.ru
Created February 2, 2012 02:17
Rack middleware example
class SimpleRackApp
def call(env)
[200, {}, ["Hello World!"]]
end
end
use Rack::ContentType, 'text/plain' # Adds the Rack::ContentLength middleware in the application middleware stack
run SimpleRackApp.new # Specifies the main rack application to run
@codespore
codespore / config.ru
Created February 2, 2012 02:34
Map method rackup file
class App1
def call(env)
[200, {}, ['App 1']]
end
end
class App2
def call(env)
[200, {}, ['App 2']]
end
@codespore
codespore / rails middlewares
Created February 2, 2012 20:10
rake middleware
$ rake middleware
use ActionDispatch::Static
use Rack::Lock
use ActiveSupport::Cache::Strategy::LocalCache
use Rack::Runtime
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::RemoteIp
use Rack::Sendfile
use ActionDispatch::Callbacks
@codespore
codespore / datatable_rails
Created June 21, 2012 05:27
Datatable Rails Implementation
# customers_controller
def index
index! do |format|
format.html
format.js do
@customers = Customer.data_table(params)
@iTotalRecords = Customer.count
@iTotalDisplayRecords = @customers.length
@sEcho = params[:sEcho].to_i
@codespore
codespore / workorder_printout.html
Created June 22, 2012 10:45
Work Order Printout
<a href="javascript: void(0)" onclick="popup('<%= ticket_manager_request_url(:id=>@request.request_no) %>')">
Print Service Request Ticket
</a>
<script type="text/javascript">
<!--
function popup(url)
{
var width = 900;
var height = 500;
@codespore
codespore / Factory Girl Configs
Created July 31, 2012 18:27
Rails Application Development Cook Book
If repeating "FactoryGirl" is too verbose for you, you can mix the syntax methods in:
# rspec
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
# Test::Unit
class Test::Unit::TestCase
include FactoryGirl::Syntax::Methods
@codespore
codespore / Homebrew Git Wget ZSH Setup
Created August 6, 2012 19:21
Development Environment Setup
1) Setup Homebrew:
ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
2) Make sure Xcode Command Line Tools Package is installed:
https://developer.apple.com/downloads/index.action
3) brew install wget
4) brew install git