This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func withCStrings(_ strings: [String], scoped: ([UnsafeMutablePointer<CChar>?]) throws -> Void) rethrows { | |
let cStrings = strings.map { strdup($0) } | |
try scoped(cStrings + [nil]) | |
cStrings.forEach { free($0) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
indirect enum SExpression { | |
struct Token { | |
var index: Int | |
var content: String | |
} | |
enum Atom { | |
case string(Token) | |
case symbol(Token) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSAttributedString { | |
func replaceHTMLTag(tag: String, withAttributes attributes: [String: AnyObject]) -> NSAttributedString { | |
let openTag = "<\(tag)>" | |
let closeTag = "</\(tag)>" | |
let resultingText: NSMutableAttributedString = self.mutableCopy() as NSMutableAttributedString | |
while true { | |
let plainString = resultingText.string as NSString | |
let openTagRange = plainString.rangeOfString(openTag) | |
if openTagRange.length == 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mkdir simple-made-easy | |
cd simple-made-easy | |
for i in `seq 1 39` | |
do | |
wget "https://res.infoq.com/presentations/Simple-Made-Easy/en/slides/sl$i.jpg" | |
done | |
for i in `seq 1 9` | |
do mv sl$i.jpg sl0$i.jpg | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum State { | |
enum String { | |
case normal | |
case escape | |
case unicode(Int) | |
} | |
} | |
final class Context { | |
let contents: [UnicodeScalar] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Run any command and suppress its output to stdin and stderr, unless it returns an error code. | |
OUTPUT=$(${@:1} 2>&1) | |
if [ $? -eq 0 ]; then | |
exit | |
fi | |
OLDLFS=$LFS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Decl { | |
struct Option { | |
enum Segment { | |
case one(String, [String]) | |
indirect case map(Segment, Segment) | |
} | |
typealias Field = (name: String?, type: Segment) | |
let name: String | |
let fields: [Field] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)guessMIMETypeFromFileName: (NSString *)fileName { | |
// Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database | |
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[fileName pathExtension], NULL); | |
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType); | |
CFRelease(UTI); | |
if (!MIMEType) { | |
return @"application/octet-stream"; | |
} | |
return (__bridge NSString *)(MIMEType); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum E { | |
final class P { var v = 0 } | |
case a(P) | |
var p: P { | |
switch self { | |
case .a(let p): return p | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Authored by sundance@ierne.eu.org as found in the following link: | |
# http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg18928.html | |
import sys | |
from PyQt4 import QtCore | |
from PyQt4 import QtGui | |
from PyQt4.QtCore import QObject | |
from PyQt4.QtCore import QUrl | |
from PyQt4.QtCore import QSizeF |