Skip to content

Instantly share code, notes, and snippets.

View epatel's full-sized avatar

Edward Patel epatel

View GitHub Profile
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.topAnchor),
extension Optional {
func both_then<T, U>(_ other: Optional<U>, f: (Wrapped, U) -> T) -> Optional<T> {
guard let a = self, let b = other else { return nil }
return f(a, b)
}
func neither<T>(_ other: Optional<T>) -> Bool {
return self == nil && other == nil
}
@chriseidhof
chriseidhof / json.swift
Last active March 21, 2019 07:45
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@peterhellberg
peterhellberg / twitter_friends_on_alpha.rb
Created August 17, 2012 11:43
Find your Twitter friends on Alpha (app.net)
require 'net/http'
require 'open-uri'
require 'json'
screen_name = ARGV[0]
if screen_name.nil?
puts "ruby twitter_friends_on_alpha.rb twitter_username"
exit
end
@peterhellberg
peterhellberg / tomtelizer_view_controller.rb
Created June 4, 2012 08:38
Main view for the Tomtelizer written in RubyMotion
# Main controller for the Tomtelizer
#
class TomtelizerViewController < UIViewController
# Load the view
#
def loadView
self.view = UIImageView.alloc.init
@debug_face = false
end