Skip to content

Instantly share code, notes, and snippets.

@yvesvanbroekhoven
yvesvanbroekhoven / harvest-basecamp.js
Last active August 2, 2023 13:51
UserScript Harvest Basecamp
// ==UserScript==
// @name Basecamp
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://basecamp.com/*
// @grant none
// ==/UserScript==
class BasecampHelpers {
@seabaylea
seabaylea / BuildWithNSURLSession.md
Created June 11, 2016 16:02
How to build a Swift toolchain on Linux with full Dispatch and NSURLSession support

Follow the instructions to checkout a full Swift build for Linux:

git clone https://github.com/apple/swift.git
cd swift
./utils/update-checkout --clone

Update the libdispatch component to use the 'experimental/foundation' branch:

cd swift-corelibs-libdispatch
@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)
@JeanMeche
JeanMeche / gist:50102a47937e9896e4f4
Created April 19, 2015 16:47
Levenshtein — swift
/**
* Levenshtein edit distance calculator
* Usage: levenstein <string> <string>
*
* Inspired by https://gist.github.com/bgreenlee/52d93a1d8fa1b8c1f38b
* Improved with http://stackoverflow.com/questions/26990394/slow-swift-arrays-and-strings-performance
*/
class Tools {
@grosch
grosch / GSRegex.swift
Last active October 17, 2015 03:24
Implement regex in Swift, based off http://nshipster.com/swift-literal-convertible/
import Foundation
public protocol GSRegularExpressionMatchable {
func match(regex: GSRegex) -> Bool
func match(regex: NSRegularExpression) -> Bool
}
public class GSRegex: StringLiteralConvertible {
let regex: NSRegularExpression?
@mattt
mattt / regex.swift
Created August 11, 2014 18:08
Creating a regular expression object from a String literal
class Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: nil, error: nil)
}
required init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern