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 / 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 / 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 / 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 / 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 / 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 / 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 / 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)")
}