Skip to content

Instantly share code, notes, and snippets.

@ccstone
ccstone / BBEdit-TextWrangler_RegEx_Cheat_Sheet.txt
Last active March 25, 2025 18:03
BBEdit-TextWrangler Regular Expression Cheat-Sheet
————————————————————————————————————————————————————————————————————————————————————————————————————
BBEdit / BBEdit-Lite / TextWrangler Regular Expression Guide Modified: 2018/08/10 01:19
————————————————————————————————————————————————————————————————————————————————————————————————————
NOTES:
The PCRE engine (Perl Compatible Regular Expressions) is what BBEdit and TextWrangler use.
Items I'm unsure of are marked '# PCRE?'. The list while fairly comprehensive is not complete.
@chockenberry
chockenberry / gist:11056920
Last active October 22, 2020 19:23
NSFont+SystemFont
//
// NSFont+SystemFont.h
// xScope
//
// Created by Craig Hockenberry on 4/17/14.
//
// Thanks to http://nshipster.com/method-swizzling/
#import <Cocoa/Cocoa.h>
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@correia
correia / command-line-args.swift
Last active August 29, 2015 14:02
A verbose alternative to NSProcessInfo.processInfo().arguments
//
// command-line-args.swift
//
// Created by Jim Correia on 6/4/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
print("PROG_NAME = \(Process.arguments[0])")
print("ARGC = \(Process.argc)")
print("ARGV = \(Process.arguments)")
// Playground - noun: a place where people can play
import Cocoa
struct Regex {
let pattern: String
let expressionOptions: NSRegularExpressionOptions
let matchingOptions: NSMatchingOptions
init(pattern: String, expressionOptions: NSRegularExpressionOptions, matchingOptions: NSMatchingOptions) {
@kerker00
kerker00 / gist:63d52c7b0e6a5df1d2bc
Last active October 3, 2018 19:16
Self relaunch of Cocoa application (Swift version of https://gist.github.com/cdfmr/2204627)
var task = NSTask()
var args: NSMutableArray
args = NSMutableArray()
args.addObject("-c")
args.addObject("sleep 0.2; open \"\(NSBundle.mainBundle().bundlePath())\"")
task.setLaunchPath("/bin/sh")
task.setArguments(args)
task.launch()
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)
}
init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern
let task = NSTask()
task.launchPath = "/bin/sh"
task.arguments = ["-c", "sleep 0.2; open \"\(NSBundle.mainBundle().bundlePath)\""]
task.launch()
NSApplication.sharedApplication().terminate(nil)
import Cocoa
enum CoroutineState {
case Fresh, Running, Blocked, Canceled, Done
}
struct CoroutineCancellation: ErrorType {}
class CoroutineImpl<InputType, YieldType> {
let body: (yield: YieldType throws -> InputType) throws -> Void
static inline const uint8_t *DecodeOneUTF8(const uint8_t *utf8, uint32_t *outCodepoint) {
uint8_t byteOne = utf8[0];
uint8_t byteTwo = utf8[1];
uint8_t byteThree = utf8[2];
uint8_t byteFour = utf8[3];
uint8_t bit1 = byteOne >> 7;
// uint8_t bit2 = (byteOne >> 6) & 1;
uint8_t bit3 = (byteOne >> 5) & 1;
uint8_t bit4 = (byteOne >> 4) & 1;