Skip to content

Instantly share code, notes, and snippets.

View eonist's full-sized avatar
🎯
Focusing

André J eonist

🎯
Focusing
View GitHub Profile
@eonist
eonist / Keychain.swift
Created March 19, 2016 12:03 — forked from jackreichert/Keychain.swift
Swift Keychain class ( supported Xcode Version 7.0 beta 4 (7A165t) )
import UIKit
import Security
class Keychain {
class func save(key: String, data: NSData) -> Bool {
let query = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrAccount as String : key,
kSecValueData as String : data ]
@eonist
eonist / base64.swift
Created March 19, 2016 18:15 — forked from ericdke/base64.swift
Base64 for Swift
let plainString = "foo"
// Encoding
guard let plainData = (plainString as NSString).dataUsingEncoding(NSUTF8StringEncoding) else {
fatalError()
}
let base64String = plainData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
print(base64String) // Zm9v
@eonist
eonist / DirectoryObserver
Created April 9, 2016 07:50
Researching file watching
class DirectoryObserver {
deinit {
dispatch_source_cancel(source)
close(fileDescriptor)
}
init(URL: NSURL, block: dispatch_block_t) {
@eonist
eonist / NSBezierPath+CGPath.swift
Created August 5, 2016 18:11 — forked from lukaskubanek/NSBezierPath+CGPath.swift
NSBezierPath+CGPath.swift
import AppKit
public extension NSBezierPath {
public convenience init(path: CGPath) {
self.init()
let pathPtr = UnsafeMutablePointer<NSBezierPath>.alloc(1)
pathPtr.initialize(self)
@eonist
eonist / methodNames.swift
Created August 25, 2016 10:10 — forked from kristopherjohnson/methodNames.swift
Get method names for an Objective-C class in Swift
import Foundation
/// Given pointer to first element of a C array, invoke a function for each element
func enumerateCArray<T>(array: UnsafePointer<T>, count: UInt32, f: (UInt32, T) -> ()) {
var ptr = array
for i in 0..<count {
f(i, ptr.memory)
ptr = ptr.successor()
}
}
@eonist
eonist / Range+Extensions.swift
Created January 12, 2017 23:57 — forked from emckee4/Range+Extensions.swift
Prospective Range+Extensions for swift 3 intensityAttributingKit
//
// Range+Extensions.swift
// IntensityAttributingKit
//
// Created by Evan Mckee on 3/23/16.
// Copyright © 2016 McKeeMaKer. All rights reserved.
//
import Foundation
@eonist
eonist / RangeTesting.swift
Created January 13, 2017 12:12
Swift 3 Range Idea: One range type to rule them all 👑
/*Assert methods*/
class RangeAsserter{
static func equals(_ a: IRange, _ b:IRange) -> Bool {
return a.start == b.start && a.end == b.end
}
}
/*Parser methods*/
class RangeParser{
static func length(_ range:IRange) -> Int {
@eonist
eonist / RangeOverview.swift
Created January 13, 2017 20:42
Swift 3 Range overview:
import Foundation
/*Range*/
let a:Range<Int> = 1..<3
print(type(of:a))//Range<Int>
a.upperBound//3
/*ClosedRange*/
let b:ClosedRange<Int> = 1...3
print(type(of:b))//ClosedRange<Int>
@eonist
eonist / Range.swift
Created January 13, 2017 21:13
Temp
import Foundation
/**
* EXAMPLE: Range(start:2,end:6).count//4
*/
extension Range {
/**
* EXAMPLE: Range<Int>(0,3).numOfIndecies()//4 -> because [0,1,2,3].count// 4
* NOTE: only works with Range<Int> for now
*/
init(_ start:Bound,_ end:Bound){/*Conveninence initializer*/
@eonist
eonist / touch.swift
Last active September 5, 2017 22:25 — forked from erica/touch.swift
Swift 3 update (playground oriented programming)
import Cocoa
import XCPlayground
import PlaygroundSupport
class TouchView: NSView {
var (path, currentPath) = (NSBezierPath(), NSBezierPath())
override func draw(_ dirtyRect: NSRect) {
guard let contextPtr = NSGraphicsContext.current()?.graphicsPort else {return}
let context = unsafeBitCast(contextPtr, to: CGContext.self)