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

Using Obj-C with MacRuby/Rubymotion

This little post aims to help you to translate Objective-C Blocks into Ruby blocks. Let's start by taking a look at few examples of iOS API call where blocks are used for animations and enumeration

Ruby Lambda Syntaxes:

Im Rubymotion and MacRuby you can use all the Ruby Lambda syntaxes that are:

block = lambda { |param|  ... }
//
// AppDelegate.m
#import "AppDelegate.h"
#import "GoogleOpenSource/GTMOAuth2Authentication.h"
#import "MainViewController.h"
#import "SignInViewController.h"
@implementation AppDelegate
# Change this:
...
#!/usr/bin/ruby
require 'osx/cocoa'
# My Script…

Using Meld merging tool on Mac

  1. Install XQuartz

  2. Install meld with brew

     brew install meld
    
  3. Copy PYTHONPATH

@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: