Skip to content

Instantly share code, notes, and snippets.

View mikekavouras's full-sized avatar

Mike Kavouras mikekavouras

View GitHub Profile
@mikekavouras
mikekavouras / memory_leak.swift
Last active September 3, 2016 04:21
Memory Leak
// Passing a closure with a reference to `self` which is ultimately stored as
// an instance property. Strong reference = retain cycle.
collectionView?.addInfiniteScrollWithHandler { collectionView in
self.update(false)
}
// Fixed: Make sure `self` that is being passed is explicitly marked as `weak`
// to force a weak reference.
collectionView?.addInfiniteScrollWithHandler { [weak self] collectionView in
self?.update(false)
class Thing {
// retain cycle
lazy var wifi: Wifi = {
return Wifi { state in
self.onConnectionHandler(state: state)
}
}()
// no retain cycle
ROOT=$SRCROOT/SellerReports/SupportingFiles
cp $ROOT/Configuration.$CONFIGURATION.plist $ROOT/Configuration.plist;
func showWebpage(URL: NSURL) {
let vc = SFSafariViewController(URL: URL)
let navController = UINavigationController(rootViewController: vc)
navController.navigationBarHidden = true
RootViewController.sharedInstance.presentViewController(navController, animated: true, completion: nil)
}
struct User {}
enum ResultType<T> {}
enum Auth {
case email(email: String, password: String)
case facebook
func login(completion: ResultType<User> -> Void) {
switch self {
case .email(let email, let password):
//: Playground - noun: a place where people can play
import UIKit
typealias JSON = [String: AnyObject]
protocol Authable {
static func login(params: JSON?, completion: (ResultType<User>) -> Void)
static func logout()
}
# https://github.com/Quick/Quick/blob/master/Documentation/en-us/InstallingQuick.md#carthage
github "Quick/Quick" ~> 0.9.2
github "Quick/Nimble" ~> 4.1.0
# https://github.com/Quick/Quick/blob/master/Documentation/en-us/InstallingQuick.md#carthage
github "Alamofire/Alamofire" ~> 3.4
# http://snapkit.io/docs/#carthage
github "SnapKit/SnapKit" >= 0.15.0
var script = document.createElement("script");
script.src = "http://code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
function shirtIt(name) {
var xhr = new XMLHttpRequest();
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
alert(JSON.parse(xhr.responseText));
}
}
};
function gifAllTheThings(images) {
var div = document.getElementById('my-div');
var index = 0;
var duration = 400; // duration of each image. 400 is arbitrary. change as you please
setInterval(function() {
var image = images[index % arr.length];
div.style.backgroundImage = 'url(' + image + ')';
index++;
}, duration);
}