Skip to content

Instantly share code, notes, and snippets.

View ericcgu's full-sized avatar
🏠
Working remotely

Eric Gu (@ericguuu) ericcgu

🏠
Working remotely
  • New York, NY
View GitHub Profile
@ericcgu
ericcgu / optional chaining
Created September 20, 2014 20:57
optional chaining
func findApt (aptNumber: String ) ->String? {
let aptNumbers = ["101", "202", "303", "404"]
for tempAptNumber in aptNumbers {
if (tempAptNumber) == aptNumber {
return aptNumber
}
}
return nil
import UIKit
struct OrderedDictionary<Tk: Hashable, Tv> {
var keys: Array<Tk>
var values: Dictionary<Tk,Tv>
// 1
mutating func insert(value: Tv, forKey key: Tk, atIndex index: Int) -> Tv?
@ericcgu
ericcgu / UIPickerControl
Created October 9, 2014 13:51
UIPickerControl
//var double = array[pickerView.selectedRowInComponent(n)]
var localCurrency = currencies.currencyList[CurrencyPickerView.selectedRowInComponent(0)]
var foreignCurrency = currencies.currencyList[CurrencyPickerView.selectedRowInComponent(1)]
func convertCurrency(#localAmount:Double, localCurrency:String, foreignCurrency: String)-> Double {
let baseURL = NSURL(string: "http://www.freecurrencyconverterapi.com/api/v2/")
let query = String(localCurrency)+"_"+String(foreignCurrency)
let forecastURL = NSURL(string: "convert?q="+query, relativeToURL: baseURL)
//use a session object to manage.//like the sun
let sharedSession = NSURLSession.sharedSession()
var convertedAmount:Double = 0.0
@ericcgu
ericcgu / fx
Created October 9, 2014 16:26
fx
func convertCurrency(#localAmount:Double, localCurrency:String, foreignCurrency: String)-> Double {
let baseURL = NSURL(string: "http://www.freecurrencyconverterapi.com/api/v2/")
let query = String(localCurrency)+"_"+String(foreignCurrency)
let forecastURL = NSURL(string: "convert?q="+query, relativeToURL: baseURL)
//use a session object to manage.//like the sun
let sharedSession = NSURLSession.sharedSession()
var convertedAmount:Double = 0.0
// List all fonts on iPhone
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
@ericcgu
ericcgu / JSON
Created October 11, 2014 14:15
JSON
SYCRONOUS
var currencyList = Dictionary<String, String>()
currencyList = ["EUR":"European Euro" ,
"GPB":"British Pounds",
"USD":"US Dollar",
"JPY":"Japanese Yen",
"RMB":"Chinese Renminbi",
"HKD":"Hong Kong Dollar",
extension Dictionary {
static func loadJSONFromBundle(filename: String) -> Dictionary<String, AnyObject>? {
if let path = NSBundle.mainBundle().pathForResource(filename, ofType: "json") {
var error: NSError?
let data: NSData? = NSData(contentsOfFile: path, options: NSDataReadingOptions(), error: &error)
if let data = data {
let dictionary: AnyObject? = NSJSONSerialization.JSONObjectWithData(data,
options: NSJSONReadingOptions(), error: &error)
//
// GameScene.swift
// swiftSpriteKit
//
// Created by anjani on 07/11/2014.
// Copyright (c) 2014 anjani vangallu All rights reserved.
import SpriteKit
class GameScene: SKScene,SKPhysicsContactDelegate {
@ericcgu
ericcgu / Sandbox AppDelegate.m
Created December 15, 2014 17:51
Objective-C Syntax
//
// AppDelegate.m
// Sandbox
//
// Created by Eric Gu on 12/15/14.
// Copyright (c) 2014 egu. All rights reserved.
//
#import "AppDelegate.h"