Skip to content

Instantly share code, notes, and snippets.

func Options(set int, options *[]int) {
var shift uint = 0
for set >= (1 << shift) {
if (1 << (shift + 1)) > set {
enum := (1 << shift)
*options = append(*options, enum)
set = set - enum
import Foundation
private class Weak<T : AnyObject> {
private weak var pointer : T?
private init(pointer:T) { self.pointer = pointer }
}
prefix operator § {}
postfix operator § {}
// Generated with Jenerator : github.com/romainmenke/Jenerator
import Foundation
/**
* Your Description For WFJenerator Goes Here
*/
class WFJenerator {
var elements : [WFJeneratorElement]
// Generated with Jenerator : github.com/romainmenke/Jenerator
import Foundation
/**
* Your Description For GFSRestaurants Goes Here
*/
class GFSRestaurants {
#!/bin/bash
# setup directories
mkdir swift-src
cd swift-src
# get swift
git clone https://github.com/apple/swift.git
# get utils
var reservedWords = ["associatedtype", "class", "deinit", "enum", "extension", "func", "import", "init", "inout", "internal", "let", "operator", "private", "protocol", "public", "static", "struct", "subscript", "typealias", "var", "break", "case", "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if", "in", "repeat", "return", "switch", "where", "while", "as", "catch", "dynamicType", "false", "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws", "true", "try", "#column", "#file", "#function", "#line", "_,#available", "#column", "#else#elseif", "#endif", "#file", "#function", "#if", "#line", "#selector", "associativity", "convenience", "dynamic", "didSet", "final", "get", "infix", "indirect", "lazy", "left", "mutating", "none", "nonmutating", "optional", "override", "postfix", "precedence", "prefix", "Protocol", "required", "right", "set", "Type", "unowned", "weak", "willSet"]
FROM ubuntu:15.10
RUN buildDeps='git cmake ninja-build uuid-dev icu-devtools libbsd-dev \
libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev \
libncurses5-dev pkg-config ca-certificates python rsync file'; \
runDeps='libicu-dev clang'; \
apt-get update \
&& apt-get -y install $buildDeps $runDeps --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
import KituraNet
// Replacement for NSData(contentsOfURL:NSURL)
extension NSData {
public static func contents(ofUrl urlString:String, completionHandler:((data:NSData?) -> Void)) {
let request = HTTP.request(urlString) { (response) in
guard let response = response else {
import UIKit
// Swift rewrite challenge
// Starting point: https://gist.github.com/jkereako/200342b66b5416fd715a#file-scale-and-crop-image-swift
extension CGSize {
func scale(toSize newSize: CGSize, fit: Bool) -> CGSize {
let test : (CGFloat,CGFloat) -> CGFloat = fit ? { max($0, $1) } : { min($0, $1) }
let scale : CGFloat = test(width / newSize.width, height / newSize.height)
extension NSDate {
func yearsFrom(date:NSDate) -> Int{
return NSCalendar.currentCalendar().components(.Year, fromDate: self, toDate: date, options: []).year
}
func monthsFrom(date:NSDate) -> Int{
return NSCalendar.currentCalendar().components(.Month, fromDate: self, toDate: date, options: []).month
}
func weeksFrom(date:NSDate) -> Int{
return NSCalendar.currentCalendar().components(.WeekOfYear, fromDate: self, toDate: date, options: []).weekOfYear
}