Skip to content

Instantly share code, notes, and snippets.

View kareman's full-sized avatar

Kare Morstol kareman

View GitHub Profile
@kareman
kareman / Queue.swift
Last active July 31, 2020 19:16
A standard queue (FIFO - First In First Out) implemented in Swift. Supports simultaneous adding and removing, but only one item can be added at a time, and only one item can be removed at a time. Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks.
//
// Queue.swift
// NTBSwift
//
// Created by Kåre Morstøl on 11/07/14.
//
// Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks.
// should be an inner class of Queue, but inner classes and generics crash the compiler, SourceKit (repeatedly) and occasionally XCode.
@kareman
kareman / trash.swift
Last active April 14, 2020 13:40 — forked from beccadax/trash.swift
Swift 3 script for sending files and folders to the trash, using the SwiftShell framework from https://github.com/kareman/SwiftShell .
#!/usr/bin/env swiftshell
/*
* Released under the MIT License (MIT), http://opensource.org/licenses/MIT
*/
import SwiftShell
import Dispatch
import Cocoa
@kareman
kareman / listallexecutablesinpath.swift
Last active August 29, 2015 14:10
Lists all executables currently available in PATH, using the SwiftShell framework (http://github.com/kareman/SwiftShell)
#!/usr/bin/env swiftshell
import SwiftShell
/*
let directories = environment["PATH"]!.split(":")
for directory in directories {
run("find \"\(directory)\" -type f -perm +ugo+x -print") |> writeTo(standardoutput)
}
import Foundation
class NSFileHandle {
}
struct String {
}
protocol Streamable {
}
@kareman
kareman / prepare-xcode-project.bash
Created January 18, 2015 22:03
Prepare an Xcode project for Git version control.
#!/bin/bash -x
# create the ignore file
cat > .gitignore <<_EOF_
# Xcode
#
.DS_Store
build/
*.pbxuser
!default.pbxuser