Skip to content

Instantly share code, notes, and snippets.

View ericcgu's full-sized avatar
🌍

Eric Gu (@ericguuu) ericcgu

🌍
  • New York, NY
View GitHub Profile
@ericcgu
ericcgu / gist:ee066e7ba6c838a42c65
Last active August 29, 2015 14:16
Closures and Functions
Function is a Special type of Closure.
Function is a named closure
// This is a function that takes an Int and prints it.
let a = {(i: Int) -> (Int) in i * 3}
//{(parameters) -> (return type) in expression statements}
a(3)
let x = [1, 2, 3, 4, 5]
@ericcgu
ericcgu / gist:9aedd45159ec69007a33
Last active August 29, 2015 14:16
Inheritance and Classes/Subclassing
https://wireframe.cc/DMi11X
You work for Apple Inc headed by CEO Tim Cook.
He hires you as a Data Analytics CTO. You are responsible for helping Tim Cook run reports on Sales Dept as well and Accounting to see Profit and Loss.
Tim Cook says welcome to you and says I need a report on all product lines iOS, MacBook, and Apple Watch. A Total of 6 reports.
Tim says: There are certain things I want, which is I want them emailed to me, I want the font to be the font of Late Steve Jobs and I don't want it more than one page per report.
But I'm not going to micromanage this process I'm going to let my Senior Vice Presidents dictate the rest.
https://www.apple.com/pr/bios/
Senior Vice President of Sales
@ericcgu
ericcgu / gist:b5f393156c58b891a2ea
Last active August 29, 2015 14:16
Swift Dictionaries
var airports: [String: String] = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]
airports["LHR"] = "London"
for airportCode in airports.keys {
println("Airport code: \(airportCode)")
}
Talk about relationship to JSON and JSON Viewer. Show him Currency App
@ericcgu
ericcgu / gist:85a828ea21391ffffee0
Last active August 29, 2015 14:16
Classes vs Structs: By Ref and By Value
//Classes vs Structs
struct Resolution {
var width = 0
var height = 0
}
class VideoMode {
var resolution = Resolution()
var interlaced = false
class Currencies: NSObject {
class func getExchangeRate(#baseCurrency: String, foreignCurrency:String){
let baseURL = kAPIEndPoint
let query = String(baseCurrency)+"_"+String(foreignCurrency)
var finalExchangeRate = 0.0
if let url = NSURL(string: baseURL + query) {
@ericcgu
ericcgu / gist:ccefc6300292cfbf6c4d
Created February 27, 2015 15:47
Vacation Accrual
USE [HRData]
GO
/****** Object: StoredProcedure [dbo].[usp_Calculate_PTOAccrual] Script Date: 02/27/2015 10:46:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_Calculate_PTOAccrual] (
@UserID INT = NULL
@ericcgu
ericcgu / gist:3f816db1e5b1f977c77f
Last active August 29, 2015 14:15
Parse Image Upload
let pickedImage:UIImage = "SOME IMAGE"
let scaledImage = scaleImageWith(pickedImage)
let imageData = UIImagePNGRepresentation(scaledImage)
let imageFile:PFFile = PFFile(data: imageData)
PFUser.currentUser().setObject(imageFile, forKey: "imageFieldName")
@ericcgu
ericcgu / gist:4f50d9bc33f239f0ae55
Last active August 29, 2015 14:15
ParseUI Hack
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> JPUserTableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as JPUserTableViewCell
cell.imageView.hidden = true
(cell.viewWithTag(1) as PFImageView).image = kProfileDefaultProfileImage
dispatch_async(dispatch_get_main_queue(),{
//cell.textLabel?.text = object["username"] as? String
if let profileImageData = object["profileImage"] as? PFFile {
println(profileImageData)
cell.imageView.file = profileImageData
//
// JPUsersTableViewController.swift
// BaseballCardSocialNetwork
//
// Created by Eric Gu on 2/19/15.
// Copyright (c) 2015 Eric Gu. All rights reserved.
//
import UIKit
@ericcgu
ericcgu / gist:c96c93795b94645c4b6a
Created February 17, 2015 20:33
Win Condition
func checkWinCondition (column: Int, row: Int){
let alert = UIAlertView()
alert.title = "Four In a Row! Game Over!"
alert.addButtonWithTitle("OK")
for row in 0..<gameBoard.rows {
for column in 0..<gameBoard.columns {
//horizontal
if(isLinearMatch(column: column, row: row, stepX: 1, stepY: 0)){