Skip to content

Instantly share code, notes, and snippets.

View romyilano's full-sized avatar
😎
improving

Romy romyilano

😎
improving
View GitHub Profile
@romyilano
romyilano / ParentViewController.swift
Created March 23, 2019 23:55
Handling container views in code
// thanks dude
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6
override func viewDidLoad() {
super.viewDidLoad()
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else {
return
}
addChildViewController(childVC)
@romyilano
romyilano / ParentViewController.swift
Created March 23, 2019 23:55
Handling container views in code
// thanks dude
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6
override func viewDidLoad() {
super.viewDidLoad()
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else {
return
}
addChildViewController(childVC)
@romyilano
romyilano / ListNode.swift
Last active April 1, 2019 15:35
ListNode helpers for LeetCode
public class ListNode {
public var val: Int
public var next: ListNode?
public init(_ val: Int) {
self.val = val
self.next = nil
}
convenience init?(withArray array: [Int]) {
guard let firstVal = array.first else { return nil }
@romyilano
romyilano / AutoreleasePoolSample.m
Created February 18, 2019 16:53
This is SO useful!
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html
– (id)findMatchingObject:(id)anObject {
id match;
while (match == nil) {
@autoreleasepool {
/* Do a search that creates a lot of temporary objects. */
match = [self expensiveSearchForObject:anObject];
func hasCycle(head: ListNode) -> Bool {
while let hareNext = hare.next?.next, let tortoiseNext = tortoise.next {
hare = hareNext
tortoise = tortoiseNext
if hare.val == tortoise.val {
return true
}
}
return false
}
// assuming nodes have no duplicate values
var head = ListNode(5)
head.next = ListNode(7)
let secondNode = head.next
head.next?.next = ListNode(8)
head.next?.next?.next = ListNode(12)
head.next?.next?.next?.next = secondNode
var tortoise = head
var hare = head
typedef struct node {
int val;
struct node * next;
} node_t;
let head = ListNode(1)
head.next = ListNode(5)
head.next?.next = ListNode(42)
var runner = head
while let nextNode = runner.next {
runner = nextNode
}
class Node:
def __init__(self, dataval=None):
self.dataval = dataval
self.nextval = None
public class LinkedList {
public var head: ListNode?
public var tail: ListNode?
public init() {}
public var isEmpty: Bool {
return head == nil
}