Skip to content

Instantly share code, notes, and snippets.

View misbell's full-sized avatar

Michael Prenez-Isbell misbell

View GitHub Profile
import Foundation
import UIKit
//1 create view with a title property
class TestView : UIView {
var title: String?
var rank: Int?
init(title: String, rank: Int) {
self.title = title
self.rank = rank
@misbell
misbell / gist:97ffc4aaa9c81f7e53ede3c28c95051e
Created December 3, 2016 04:10
The Map , Filter, Reduce code chapter from Fatih Nayebi, adapted for Swift 3.0.1 from Swift 2
// This code runs in a playground in Swift 3.0.1
import Cocoa
var str = "Hello, playground"
/*
MPI
dec 2 2016
@misbell
misbell / gist:90a39719a45cf456398854627f672d09
Created October 23, 2016 02:08
Functions return [String:Any] and [AnyHashable:Any] , consumed in for-in loop, String conversions
// Wrote this to test out how Arrays of Dictionaries are handled
// was surprised to see they become tuples in a for-in
// also some unintuitive string conversions
import Cocoa
func c() -> [String:Any] {
print ( "ok" )
@misbell
misbell / gist:fa7ecd562a9b0d9c1237eed5e1a6d89e
Created October 16, 2016 01:43
example Swift 3 withMemoryRebound
so A and B are structurally identical
C reverses the order of the 8 and 32 bit Ints
and D substitutes a string for the Int8
then I try to read aaaa’s bits using B C and D overlays 😊
C is printing the 8 bits of the A integer j and then the first 8 bits of integer k but somehow that still works out to one
when I hit D it doesn’t find a string so prints a blank
but the important point is: it doesn’t check anything, and doesn’t crash
@misbell
misbell / gist:bae00230c42e9ff48d53e609618eb4a3
Created October 6, 2016 21:45
DispatchWorkItem barrier attribute
so this works as expected:
let conq = DispatchQueue(label: "ok", qos: .background, attributes: .concurrent )
// let conq = DispatchQueue.global(qos: .userInitiated)
let dw1 = DispatchWorkItem {
//sleep(2)
print("dw1")
}
@misbell
misbell / gist:2dc38c47ff56f91c6775dde2be1fceb4
Created October 5, 2016 18:27
os_unfair_lock, simple useage from wwdc 2016 concurrency talk by Pierre Habouzit, objective-c, bridging header and Swift 3
#import "FoundationLocks.h"
#import "os/lock.h"
@implementation LockableObject
os_unfair_lock _lock;
- (instancetype) init {
@misbell
misbell / gist:97f3c840a570598270fa8e406a7c60c8
Created October 4, 2016 21:00
Returning value from subsystem with DispatchQueue.sync - Swift 3.0 - October 4 2016
// pretending this is a subsystem
let holdval = HoldAValue()
var avalue: Int {
var i: Int = 0
DispatchQueue.global(qos: .userInitiated).sync {
i = holdval.anIntValue
}
return i
}
@misbell
misbell / gist:c2f5aea998ba64174a23e538172243f1
Created October 4, 2016 18:24
DispatchQueue and DispatchGroup in Swift 3.0 as of Oct 4 2016
let dispatchGroup = DispatchGroup()
let dq = DispatchQueue.global(qos: .utility)
dq.async {
for i in 0...3{
dq.async {
print("\n i - \(i)")
@misbell
misbell / .gitignore
Created January 13, 2013 01:04 — forked from adamgit/.gitignore
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
# For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#########################