Skip to content

Instantly share code, notes, and snippets.

@kitschysynq
kitschysynq / gist:bab0797516f2e44fc6b7cff002599958
Created September 12, 2016 15:13
DigitalOcean Image Slugs
"coreos-beta"
"freebsd-10-1-x64"
"fedora-23-x64"
"centos-6-5-x32"
"centos-6-5-x64"
"debian-7-0-x32"
"debian-7-0-x64"
"fedora-24-x64"
"debian-7-x32"
"freebsd-10-3-x64-zfs"
@plumhead
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
@ymyzk
ymyzk / semaphore.swift
Created August 10, 2015 19:43
Grand Central Dispatch (GCD) dispatch semaphore examples
private func example1() {
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
for i in 0..<10 {
dispatch_async(queue) {
NSLog("Start: \(i)")
sleep(3)
NSLog("End: \(i)")
}
}
}
@JadenGeller
JadenGeller / Dynamic Swift.swift
Last active February 11, 2018 15:58
Dynamic Swift
import Foundation
// Dynamic swift!
/* * * * * * * * * * * * * * * * * * * * *
* Scroll to the bottom for sample code! *
* * * * * * * * * * * * * * * * * * * * */
// Disclaimer: Any resemblance to JavaScript or any other shitty language is completely accidental.
@wxs
wxs / gist:d773cb2a2e9891dbfd63
Last active March 13, 2020 11:50
Legal characters in Swift 1.2 Operators
Have you always wanted to define the sailboat operator in Swift? Well now you can!
3 ⛵4 == "sailboat"
Swift 1.2 significantly increased the number of legal characters in custom operators.
I've generated a list for ease of copy/paste below.
Generated from reference here: http://apple.co/1EEXHDQ
The characters
@natecook1000
natecook1000 / NSScanner+Swift.swift
Created March 3, 2015 20:13
Swift-friendly NSScanner methods
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension NSScanner {
// MARK: Strings
@natecook1000
natecook1000 / CalculatorView.swift
Last active June 6, 2022 01:00
An IBInspectable Calculator Construction Set
// CalculatorView.swift
// as seen in http://nshipster.com/ibinspectable-ibdesignable/
//
// (c) 2015 Nate Cook, licensed under the MIT license
/// The alignment for drawing an String inside a bounding rectangle.
enum NCStringAlignment {
case LeftTop
case CenterTop
case RightTop
@kristopherjohnson
kristopherjohnson / notifications.swift
Created January 18, 2015 16:42
Swift snippets for local and remote notifications
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
registerNotificationTypes()
return true
}
func registerNotificationTypes() {
let types: UIUserNotificationType = .Badge | .Sound | .Alert;
@abresler
abresler / wehrmacht
Last active September 13, 2017 22:55
German Wermacht Dygraph
library(rvest)
library(dypgraph)
library(pipeR)
library(magrittr)
library(dplyr)
options(viewer = NULL)
url <- "http://www.feldgrau.com/stats.html"
stats <-
html(url) %>%
let mainQueueA = dispatch_get_global_queue(qos_class_main(), 0)
let mainQueueB = dispatch_get_main_queue()
// This works fine
dispatch_apply(3, mainQueueA) { i in
println("A: \(i)")
}
println("Yep")
// This never calls the block and hangs the main thread