Skip to content

Instantly share code, notes, and snippets.

View eonist's full-sized avatar
🎯
Focusing

André J eonist

🎯
Focusing
View GitHub Profile
- [ ] %| | mtd
[%filltext:name=the title:default=here%](%clipboard) | lnk
![%filltext:name=img:default=img%](%clipboard) | img
```%filltext:name=lang% %| ``` | fence
**%clipboard** | bld
~~%clipboard~~ | strike
<img width="%filltext:name=width:default=320%" alt="%filltext:name=img:default=img%" src="https://dl.dropboxusercontent.com/u/2559476/%clipboard"> | rimg
``` %clipboard%| ``` | fe
* [[%clipboard]] | sbi
_%clipboard_ | italic
@eonist
eonist / swift_factory_pattern.swift
Created March 7, 2016 14:49
swift factory pattern
import Foundation
protocol ILayout{
init(_ args:Double...)
}
class Fillet:ILayout{
required init(_ args:Double...){
Swift.print("Fillet: " + "\(args.count)")
}
}
class Margin:ILayout{
@eonist
eonist / CVDisplayLinkOutputCallback.swift
Created March 10, 2016 19:23 — forked from eyeplum/CVDisplayLinkOutputCallback.swift
CVDisplayLinkOutputCallback in Swift
private func createDisplayLink() {
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink)
guard let displayLink = displayLink else {
return
}
let callback: CVDisplayLinkOutputCallback = { (_, _, _, _, _, userInfo) -> CVReturn in
let myView = Unmanaged<MyView>.fromOpaque(COpaquePointer(userInfo)).takeUnretainedValue()
dispatch_async(dispatch_get_main_queue()) {
myView.update()
@eonist
eonist / Retina Mac Icon
Last active March 17, 2016 02:13
Creates Retina Mac Icon
//terminal script:(takes 3 sec to setup) http://stackoverflow.com/questions/12306223/how-to-manually-create-icns-files-using-iconutil
//or drag and drop solution (sketchy website, download is a hex file, no link to devs): https://iconverticons.com/online/
Here's a script to convert a 1024x1024 png (named "Icon1024.png") to the required icns file. Save it to a filed called "CreateICNS.src" in the folder where your png file is then in terminal "cd" to the same folder and type "source CreateICNS.src" to call it:
mkdir MyIcon.iconset
sips -z 16 16 Icon1024.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64 Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
@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 / TheEventSystem.swift
Last active April 8, 2016 18:27
A simple event system that propagates events through hierarchical classes
import Foundation
/*
* TODO: Implement the immediate variable if its needed (it would be a way to get assert the 1-level down immediate child an event came from, rather than the origin child which can be many levels deeper in the hirarchy)
*/
class Event{
static var update:String = "eventUpdate"/*Idealy I would name this change but apparently then subclasses can name their const the same*/
var type:String
var origin:AnyObject/*origin sender of event, this could also be weak if you discover a memory leak*/
/*var immediate:Any?*///prev sender of event, may be implemented in the future if needed
@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 / 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) {