Skip to content

Instantly share code, notes, and snippets.

View AshishKapoor's full-sized avatar
💭
Here to build.

Ashish Kapoor AshishKapoor

💭
Here to build.
View GitHub Profile
@AshishKapoor
AshishKapoor / todo.json
Last active May 11, 2017 15:39
When in doubt...
{
"todo" : {
"1": "Watch that movie",
"2": "Write that code",
"3": "Read that book",
"4": "Call them",
"5": "Get some sleep"
}
}
@AshishKapoor
AshishKapoor / get-request-sample.swift
Last active May 11, 2017 15:40
Swift 3.1 Get Request
let url = URL(string: "https://api.themoviedb.org/3/discover/tv?" +
"include_null_first_air_dates=false&timezone=America%2FNew_York" +
"&page=1&sort_by=popularity.desc&language=en-US" +
"&api_key=<api_key>")
var request = URLRequest(url: url!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)
request.httpMethod = "GET"
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
let session = URLSession.shared
let dataTask = session.dataTask(with: request, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
@AshishKapoor
AshishKapoor / function-as-argument.swift
Last active May 11, 2017 16:23
Higher Order Functions
import UIKit
// Function as a argument.
/*
Reference: https://www.youtube.com/channel/UC-d1NWv5IWtIkfH47ux4dWA, The Swift Guy
*/
func animorphs(getMutation: (_ sugar: String, _ spice: String) -> String, humanSays: String, animalSays: String) -> String {
return getMutation(humanSays, animalSays)
@AshishKapoor
AshishKapoor / function-returns-function.swift
Last active May 11, 2017 16:23
Function returns another function
import UIKit
// Function returns another function.
/*
Reference: https://www.youtube.com/channel/UC-d1NWv5IWtIkfH47ux4dWA, The Swift Guy
*/
func shouldVerify(_ chooseAction: Bool) -> (String, String) -> String {
@AshishKapoor
AshishKapoor / Stack.swift
Created May 13, 2017 13:27
Stack implementation in Swift 3.1
import UIKit
// Stack implementation in Swift 3.1
class Node {
let value: Int
var nextNode: Node?
init(value: Int) {
self.value = value
@AshishKapoor
AshishKapoor / Stack-Generics.swift
Created May 13, 2017 14:08
Stack and Generics implementation in Swift 3.1
import UIKit
// Stack and Generics implementation in Swift 3.1
class Node<T> {
let value: T
var nextNode: Node<T>?
var prevNode: Node<T>?
init(value: T) {
@AshishKapoor
AshishKapoor / CountryCodes.json
Created July 3, 2017 19:09
Country Codes in a json file for future reference.
[
{"name":"Israel","dial_code":"+972","code":"IL"},
{"name":"Afghanistan","dial_code":"+93","code":"AF"},
{"name":"Albania","dial_code":"+355","code":"AL"},
{"name":"Algeria","dial_code":"+213","code":"DZ"},
{"name":"AmericanSamoa","dial_code":"+1 684","code":"AS"},
{"name":"Andorra","dial_code":"+376","code":"AD"},
{"name":"Angola","dial_code":"+244","code":"AO"},
{"name":"Anguilla","dial_code":"+1 264","code":"AI"},
{"name":"Antigua and Barbuda","dial_code":"+1 268","code":"AG"},
@AshishKapoor
AshishKapoor / timeago.swift
Created July 6, 2017 16:00 — forked from minorbug/timeago.swift
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
@AshishKapoor
AshishKapoor / HOF.swift
Created July 10, 2017 07:33
HOF quick ref
import UIKit
let numbers = [1,2,3,4,5,6,7,8,9]
struct Person {
let name: String
let age: Int
init(name: String, age: Int) {
self.name = name
@AshishKapoor
AshishKapoor / tmux-cheats.md
Created February 26, 2018 06:53 — forked from Starefossen/tmux-cheats.md
My personal tmux cheat sheet for working with sessions, windows, and panes. `NB` I have remapped the command prefix to `ctrl` + `a`.

Sessions

New Session

  • tmux new [-s name] [cmd] (:new) - new session

Switch Session

  • tmux ls (:ls) - list sessions
  • tmux switch [-t name] (:switch) - switches to an existing session