Skip to content

Instantly share code, notes, and snippets.

View fadhlirahim's full-sized avatar
💭
Most happiest building code that make sense.

Fadhli Rahim fadhlirahim

💭
Most happiest building code that make sense.
View GitHub Profile
@fadhlirahim
fadhlirahim / gist:1320181
Created October 27, 2011 17:17
Filter params allowed to go thru
# Make sure that we don't allow attributes to be mass assigned from Backbone saves
# http://www.quora.com/Backbone-js-1/How-well-does-backbone-js-work-with-rails
# Always whitelist and validate your incoming attributes.
#
# Usage
#
# model.update_attributes pick(params, :title, :description)
#
def pick(hash, *keys)
filtered = {}
@fadhlirahim
fadhlirahim / Gemfile
Created November 4, 2011 04:09 — forked from mattheworiordan/Gemfile
Test PDF within Cucumber and Capybara
# normal Gem dependancy declarations
# ...
group :test, :cucumber do
gem 'pdf-reader'
end
@fadhlirahim
fadhlirahim / gist:1363508
Created November 14, 2011 08:14
Create Tempfile
# Creates Tempfile
def ical_file
file = Tempfile.new("foo")
begin
file.path
file.write('foo')
file.rewind
file.read
ensure
file.close
@fadhlirahim
fadhlirahim / gist:1991616
Created March 7, 2012 07:23
rails return json for fullcalendar.js dates displays
# Model
class Meeting < ActiveRecord::Base
scope :date_range, lambda {|*args| where("start_date between ? and ?", args.first, args.last) }
end
#Controller
# fullcalendar.js dates displays
def meeting_dates
start_range = params[:start].present? ? Time.at(params[:start].to_i) : Date.civil(Time.now.year, Time.now.month, 1)
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
namespace :delayed_job do
desc "Stop the delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path}; script/delayed_job -e #{rails_env} stop"
end
@fadhlirahim
fadhlirahim / scheduled_job.rb
Created May 7, 2012 07:11 — forked from kares/scheduled_job.rb
Recurring Job using Delayed::Job
#
# Recurring Job using Delayed::Job
#
# Setup Your job the "plain-old" DJ (perform) way, include this module
# and Your handler will re-schedule itself every time it succeeds.
#
# Sample :
#
# class MyJob
# include Delayed::ScheduledJob
@fadhlirahim
fadhlirahim / cs-iife.coffee
Created July 7, 2012 03:17 — forked from ryanflorence/cs-iife.coffee
CoffeeScript Immediately Invoked Function Expressions
increment = do ->
x = 0
->
x++
@fadhlirahim
fadhlirahim / Gemfile
Created September 1, 2012 10:39
Sinatra app Authenticating with Viki API
source :rubygems
gem 'sinatra'
gem 'oauth2'
gem 'json'
group :test do
gem 'rspec'
gem 'rack-test'
end
# Add fixture-generation methods to ControllerExampleGroup. We load
# this file within our spec_helper.rb
# http://pivotallabs.com/users/jb/blog/articles/1152-javascripttests-bind-reality-
Spec::Rails::Example::ControllerExampleGroup.class_eval do
# Saves the markup to a fixture file using the given name
def save_fixture(markup, name)
fixture_path = File.join(RAILS_ROOT, '/tmp/js_dom_fixtures')
Dir.mkdir(fixture_path) unless File.exists?(fixture_path)
@fadhlirahim
fadhlirahim / theme.html
Created October 5, 2012 08:29 — forked from soemarko/theme.html
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->