Skip to content

Instantly share code, notes, and snippets.

View lin's full-sized avatar

Albert Lin lin

View GitHub Profile
@lin
lin / 1_basic.md
Last active August 29, 2015 14:10
AWS setup for rails (apache and passenger) and mongodb

Create an ec2 instance

ssh -i ~/.ssh/keypair.pem ec2-user@123.456.789.101

Set up ssh alias.

vi ~/.ssh/config
@lin
lin / commands.md
Last active August 29, 2015 14:10

Processes Snapshot (ps)

And to see every process on the system using BSD syntax: (aux)

ps aux | grep unicorn
kill -9 
db.createUser(
{
user: "username",
pwd: "password",
roles:
[
{
role: "dbOwner",
db: "dbname"
}
@lin
lin / basic.m
Created January 29, 2015 03:44
void (^logMessage) = ^{
NSLog(@"Hello from inside the block");
};
void (^sumNumbers)(NSUInteger, NSUInteger) = ^(NSUInteger num1, NSUInteger num2){
NSLog(@"The sum of the numbers is %lu", num1 + num2);
};
for (NSString *word in funnyWords) {
NSLog(@"%@ is a funny word", word);
@lin
lin / gist:b64625479ff8f3199981
Created February 2, 2015 21:54
Ruby Revisit
tweets = timeline.tweets || []
options[:country] ||= 'us'
options[:privacy] ||= true
def sign_in
current_session || sign_user_in
en
if list_name
"/#{user_name}/#{list_name}"
function arrayToObject_recursive ( $data ) {
// if the passed data is just a value, return it, and terminate the recursion.
if ( !is_array( $data ) )
return $data;
// otherwise, read the class name out of the data.
if ( array_keys($data) !== range(0, count($data) - 1) ) {
if ( !empty( $data['_model_class'] ) ) {
$class = $data['_model_class'];
function arrayToObject_recursive ( $data, $key = NULL) {
// if the passed data is just a value, return it, and terminate the recursion.
if ( !is_array( $data ) )
return $data;
// otherwise, read the class name out of the data.
if ( array_keys($data) !== range(0, count($data) - 1) ) {
if ( !empty( $data['_model_class'] ) ) {
$class = $data['_model_class'];
// This function simply processes a Mongo query, and returns an array of objects of the specified type. The type is saved in the _model_class
// parameter (which is saved along with the mongo data). This allows us to know which concrete subclass was saved, and how to load it again.
protected static function get_withQuery ( $query, $collection_name, $sort = null, $limit = null, $skip = null ) {
$mongo = new MongoConnection();
$collection = $mongo->get_db()->selectCollection( $collection_name );
$resultCursor = $collection->find( $query );
if ( !empty($sort) ) $resultCursor->sort( $sort );
if ( !empty($limit) ) $resultCursor->limit( $limit );
if ( !empty($skip) ) $resultCursor->skip( $skip );
@lin
lin / cocoapod.shell
Created February 16, 2015 16:38
Cocoa Pod install
$ sudo gem install cocoapods
$ pod setup
$ pod install
@lin
lin / block.rb
Last active August 29, 2015 14:15
def hello str, &block
pre_str = str + " world!"
block.call pre_str
after_str = "say " + str
puts after_str
end
hello "hello" do |str|
puts "MC says #{str}"
end