Skip to content

Instantly share code, notes, and snippets.

View trivektor's full-sized avatar
🏠
Working from home

Tri Vuong trivektor

🏠
Working from home
View GitHub Profile
@trivektor
trivektor / range_intersection.rb
Created July 13, 2011 19:31 — forked from senorprogrammer/range_intersection.rb
Range intersections in Ruby
#!/usr/bin/env ruby
# From my blog post at http://www.postal-code.com/binarycode/2009/06/06/better-range-intersection-in-ruby/
class Range
def intersection(other)
raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)
my_min, my_max = first, exclude_end? ? max : last
other_min, other_max = other.first, other.exclude_end? ? other.max : other.last
@trivektor
trivektor / rspec-syntax-cheat-sheet.rb
Created September 9, 2011 06:02 — 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")
@trivektor
trivektor / validation.js
Created October 10, 2011 05:37 — forked from netzpirat/validation.js
Backbone Model Validation
_.extend(Backbone.Model.prototype, Backbone.Events, {
errors: [],
validate: function (attrs) {
//reset
this.errors = [];
var model = this;
@trivektor
trivektor / deploy.rb
Created November 23, 2011 19:20 — forked from netzpirat/deploy.rb
Capistrano recipe to sync rails database and files within a multi stage environment
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3
@trivektor
trivektor / 1.js
Created January 17, 2012 05:32 — forked from mxriverlynn/1.js
hacking jasmine-jquery setFixtures
function addFixture(html){
var fixtures = jasmine.getFixtures();
if (!fixtures.fixtureList){
fixtures.fixtureList = [];
}
fixtures.fixtureList.push(html);
fixtures.set(fixtures.fixtureList.join());
}
function clearMyFixtures(){

GitHub OAuth Busy Developer's Guide

This is a quick guide to OAuth2 support in GitHub for developers. This is still experimental and could change at any moment. This Gist will serve as a living document until it becomes finalized at Develop.GitHub.com.

OAuth2 is a protocol that lets external apps request authorization to private details in your GitHub account without getting your password. All developers need to register their application before getting started.

Web Application Flow

  • Redirect to this link to request GitHub access:
[16] pry(main)> client = Octokit::Client.new(:login => 'ctshryock', :password => '**********')
[11] pry(main)> client.issue_comments('ctshryock/octokit', 10).size
=> 4
[12] pry(main)> client.add_comment('ctshryock/octokit', 10, "here's a brand new comment")
=> {"url"=>
"https://api.github.com/repos/ctshryock/octokit/issues/comments/3768382",
"body"=>"here's a brand new comment",
"updated_at"=>"2012-02-01T22:18:32Z",
"user"=>
{"url"=>"https://api.github.com/users/ctshryock",
@trivektor
trivektor / deploy.rb
Created March 1, 2012 03:09 — forked from bkutil/deploy.rb
Start and Stop tasks for resque workers and resque scheduler with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
after "deploy:restart_workers", "deploy:restart_scheduler"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
@trivektor
trivektor / deploy.rb
Created March 17, 2012 01:37 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
...
# Restart Passenger
deploy.task :restart, :roles => :app do
...
# Restart the resque workers
run "cd #{current_path} && rake queue:restart_workers RAILS_ENV=production"
end