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 / InteractivePlayground.swift
Last active January 23, 2017 15:05
swift 3.0, NSButton, NSTextField (Experiment) (standalone window)
//forked from: https://github.com/BergQuester/Interactive-Window-Swift-Playground
import Cocoa
import XCPlayground
// Window size
let windowRect = NSRect(x: 30, y: 30, width: 300, height: 300)
var window = NSWindow(contentRect: NSRect(x: 30, y: 30, width: 300, height: 300), styleMask: NSWindowStyleMask.titled, backing: .buffered, defer: false)
@eonist
eonist / playground.swift
Last active January 18, 2017 13:09 — forked from h2ero/playground.swift
InteractivePlayground with button that prints hello (swift 3.0.1)
import AppKit
import XCPlayground
import Cocoa
import PlaygroundSupport
extension NSLayoutConstraint {
convenience init(view item: NSView, to toItem: NSView, attribute: NSLayoutAttribute, constant c: CGFloat = 0) {
self.init(item: item, attribute: attribute,
relatedBy: .equal,
toItem: toItem, attribute: attribute,
@eonist
eonist / GraphicsLibPlayground.swift
Created January 19, 2017 12:50
GraphicsLib + Playground + Framework
import Cocoa
import XCPlayground
import PlaygroundSupport
@testable import MyFrameWork
class TouchView: NSView {
var (path, currentPath) = (NSBezierPath(), NSBezierPath())
override var isFlipped:Bool {return true}/*Organizes your view from top to bottom*/
override init(frame frameRect: NSRect) {
@eonist
eonist / VolumeSliderPlayground.swift
Last active January 23, 2017 14:06
Interactive playground demo
//: Playground - noun: a place where people can play
import Cocoa
import PlaygroundSupport
@testable import MyFramework
//Temp.test()
@testable import Utils
@testable import Element
@eonist
eonist / gist:a21a491496409ed3e203d3f47fdbe35c
Last active February 25, 2017 11:25 — forked from mickmaccallum/gist:c2b322e059c9b3379245
Swift recursive flatmap (Alternative version)
protocol AnyArray{}/*<--Neat trick to assert if a value is an Array, use-full in reflection and when the value is Any but really an array*/
extension Array:AnyArray{}//Maybe rename to ArrayType
func recFlatMap<T>(_ arr:[AnyObject]) -> [T]{
var result:[T] = []
Swift.print("arr.count: " + "\(arr.count)")
arr.forEach{
if($0 is AnyArray){
let a:[AnyObject] = $0 as! [AnyObject]
result += recFlatMap(a)
}else{
@eonist
eonist / URLRequest+cURLCommand.swift
Created March 2, 2017 21:19 — forked from ollieatkinson/URLRequest+cURLCommand.swift
Generate cURL command's from URLRequest's
extension URLRequest {
/// The cURL representation of the URLRequest, useful for debugging and executing requests outside of the app.
var cURLCommand: String {
var command = "curl"
if let httpMethod = httpMethod {
command.append(commandLineArgument: "-X \(httpMethod)")
}
function flatten(arr) {
return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []);
}
@eonist
eonist / String+HTML.swift
Created March 2, 2017 22:10 — forked from ollieatkinson/String+HTML.swift
Unescape HTML entities in Swift 3 == &#163; -> £
extension String {
func unescapeHTMLEntities() throws -> String {
guard contains("&#") else {
return self
}
guard let data = data(using: .utf8) else {
return self
@eonist
eonist / diff.mdown
Last active March 5, 2017 09:49 — forked from ndarville/diff.mdown
Paul Heckel's Diff Algorithm

oliveratkinson [12:50 AM] Paul Heckel's Diff Algorithm

[12:50]
http://dl.acm.org/citation.cfm?id=359467

eonist [12:53 AM] Instagram iOS dev interview question: How would you explain the “Paul Heckel's Diff Algorithm” to a child? go...

oliveratkinson [12:54 AM]

@eonist
eonist / TypeErasure.swift
Created March 11, 2017 10:48 — forked from russbishop/TypeErasure.swift
Type erasure with multiple adopting types
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
}