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
Protocol in Objective-C is like interface in Java
Apple tends to favor using subclasses than protocol
NSObject is a class but also a protocol
trivektor / gist:2c98df1a22323e1a8ae0
Last active August 29, 2015 14:05
Data modelling for MySQL
What is a Relational Database?
A set of true propositions
Every row in a table is the statement about the truth related to the table
Enforces logical integrity (business rules)
Application independent store (this is the reason why relational database was created)
Why Normalize?
# Change this:
require 'osx/cocoa'
# My Script…

Using Meld merging tool on Mac

  1. Install XQuartz

  2. Install meld with brew

     brew install meld

trivektor / gist:1033447
Created June 18, 2011 19:54
Escape single quotes to prepare for query
class String
def escape_single_quotes
self.gsub(/'/, "\\\\'")
array.inject{|sum,x| sum + x }
trivektor / gist:1049151
Created June 27, 2011 16:01
Skip callbacks
# Courtesy
class ActiveRecord::Base
def self.skip_callback(callback, &block)
method = instance_method(callback)
remove_method(callback) if respond_to?(callback)
trivektor / gist:1053168
Created June 29, 2011 04:42
Convert number to currency
# Taken from
# takes a number and options hash and outputs a string in any currency format
def currencify(number, options={})
# :currency_before => false puts the currency symbol after the number
# default format: $12,345,678.90
options = {:currency_symbol => "$", :delimiter => ",", :decimal_symbol => ".", :currency_before => true}.merge(options)
# split integer and fractional parts
int, frac = ("%.2f" % number).split('.')