Skip to content

Instantly share code, notes, and snippets.

View pythonicrubyist's full-sized avatar

Ramtin Vaziri pythonicrubyist

View GitHub Profile
data = [('SFO', 'HKO'), ('YYZ', 'SFO'), ('YUL', 'YYZ'), ('HKO', 'ORD')]
# extract nodes
nodes = list(set([val for s in data for val in s]))
# build a graph
graph = {}
for n in nodes:
graph[n] = []
paths = [path for path in data if n in path]
@pythonicrubyist
pythonicrubyist / iOS_dev_swift_notes
Last active August 29, 2015 14:16
IOS developments with Swift
// Actions are method invocations from View to View Controller.
// Outlets are method invocations from View Controller to view.
// Initial Setup for ViewControllers
// ViewDidLoad - Called when you create the class and load from xib. Great for initial setup and one-time-only work.
// ViewWillAppear - Called right before your view appears, good for hiding/showing fields or any operations that you want to happen every time before the view is visible. Because you might be going back and forth between views, this will be called every time your view is about to appear on the screen.
// ViewDidAppear - Called after the view appears - great place to start an animations or the loading of external data from an API.
// ViewWill/DidDisappear - Same idea as WillAppear.
// ViewDidUnload/ViewDidDispose - In Objective C, this is where you do your clean-up and release of stuff, but this is handled automatically so not much you really need to do here.
@pythonicrubyist
pythonicrubyist / swift_fundamentals
Last active August 29, 2015 14:16
Swift Fundamentals
// Variables in Swift
// Every variable in Swift is declared with the keyword "var".
// Swift is a type-safe language. It is strongly typed.
// All varables is Swift are of a specific type.
// Swift performs type inference if the type is not declared.
var s = "Hello World!" // Type inferred as string
var i = 7 // Type inferred as integer
var b = false // Type inferred as boolean
@pythonicrubyist
pythonicrubyist / collections_in_swift
Last active August 29, 2015 14:15
Collections in Swift
// Collections in Swift
// Two basic collection types in Swift, Arrays and Dictionaries.
// Arrays in Swift
// Ordered collections of items
// Zero based.
// Type safe
// If defined by let, it is immutable, can not be added or altered.
@pythonicrubyist
pythonicrubyist / control_flow_ in_swift
Last active August 29, 2015 14:15
Control Flow in Swift
// Playground - noun: a place where people can play
import UIKit
// Flow management in Swift
// Parentheses are optional, curly braces are mandatory.
// condition must evaluate as a boolean.
var a = 5
var b = 10
@pythonicrubyist
pythonicrubyist / variables_in_swift
Created February 11, 2015 17:17
Variables in Swift
// Variables in Swift
// Every variable in Swift is declared with the keyword "var".
// Swift is a type-safe language. It is strongly typed.
// All varables is Swift are of a specific type.
// Swift performs type inference if the type is not declared.
var s = "Hello World!" // Type inferred as string
var i = 7 // Type inferred as integer
var b = false // Type inferred as boolean
@pythonicrubyist
pythonicrubyist / redis_on_osx_mavericks
Created May 28, 2014 15:42
redis on Mac OSX Mavericks
# installing redis server
mkdir /usr/local/var/log
mkdir /usr/local/var/db
brew install redis
# start redis server
redis-server /usr/local/etc/redis.conf
@pythonicrubyist
pythonicrubyist / ruby_env_setup_on_os x_mavericks
Last active August 29, 2015 14:01
Ruby Development Environment Setup on OS X Mavericks
# Instlled Xcode, Github and Sublime Text 3 by runing their installation packages.
git config --global user.name "Your Full Name"
git config --global user.email "Your Email Address"
# Homebrew Installation:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew doctor
echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
@pythonicrubyist
pythonicrubyist / delete_git_commit
Created February 25, 2014 18:43
Deleting the last Git commit
git reset --hard HEAD~1
git push origin HEAD --force
@pythonicrubyist
pythonicrubyist / nil_empty_blank_present_ffdierence_in_ruby
Last active February 21, 2024 17:38
Difference between nil?, empty?, blank? and present? in Ruby and Ruby on Rasils.
# nil? can be used on any Ruby object. It returns true only if the object is nil.
nil.nil? # => true
[].nil? # => false
{}.nil? # => false
"".nil? # => false
" ".nil? # => false
true.nil? # => false
# empty? can be used on some Ruby objects including Arrays, Hashes and Strings. It returns true only if the object's length is zero.
nil.empty? # NoMethodError: undefined method `empty?' for nil:NilClass