Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Tri Vuong trivektor

🏠
Working from home
View GitHub Profile
View gist:9427630

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|  ... }
View AppDelegate.m
//
// AppDelegate.m
#import "AppDelegate.h"
#import "GoogleOpenSource/GTMOAuth2Authentication.h"
#import "MainViewController.h"
#import "SignInViewController.h"
@implementation AppDelegate
View gist:54c3bf83a59a0215eb12
Protocol
------------
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
Category
------------
@trivektor
trivektor / gist:2c98df1a22323e1a8ae0
Last active Aug 29, 2015
Data modelling for MySQL
View gist:2c98df1a22323e1a8ae0
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?
--------------
View gist:c098dd6bfb62ba7f061f
# Change this:
...
#!/usr/bin/ruby
require 'osx/cocoa'
# My Script…
View using_meld_on_mac.md

Using Meld merging tool on Mac

  1. Install XQuartz

  2. Install meld with brew

     brew install meld
    
  3. Copy PYTHONPATH

@trivektor
trivektor / gist:1033447
Created Jun 18, 2011
Escape single quotes to prepare for query
View gist:1033447
class String
def escape_single_quotes
self.gsub(/'/, "\\\\'")
end
end
View gist:1034602
array.inject{|sum,x| sum + x }
View gist:1049151
# Courtesy http://www.allerin.com/blog/?p=186
class ActiveRecord::Base
def self.skip_callback(callback, &block)
method = instance_method(callback)
remove_method(callback) if respond_to?(callback)
@trivektor
trivektor / gist:1053168
Created Jun 29, 2011
Convert number to currency
View gist:1053168
# Taken from http://codesnippets.joyent.com/posts/show/1812
# 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('.')