This file contains hidden or 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
protocol EnumCollection {} | |
extension EnumCollection where Self: Hashable { | |
static func sequence() -> AnySequence<Self> { | |
return AnySequence { () -> AnyIterator<Self> in | |
var raw = 0 | |
return AnyIterator { | |
let `case` : Self = withUnsafePointer(to: &raw) { $0.withMemoryRebound(to: Self.self, capacity: 1) { $0.pointee } } | |
guard `case`.hashValue == raw else { return nil } | |
raw += 1 | |
return `case` |
This file contains hidden or 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/bash | |
# set disk size for 512 MB | |
disksize=$((512*(512*4))) | |
# mounting DerivedData virtual disk | |
disknum=$(hdid -nomount ram://$disksize | tr -cd '[0-9]') | |
newfs_hfs -v DerivedData /dev/rdisk$disknum | |
diskutil mount -mountPoint ~/Library/Developer/Xcode/DerivedData /dev/disk$disknum |
This file contains hidden or 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/bash | |
# Script to remove all Xcode DerivedData, | |
# provided Xcode is set to default folder locations | |
printf "clearing DerivedData..." | |
rm -rfv ~/Library/Developer/Xcode/DerivedData/* | |
echo "done" | |
exit 0 |
This file contains hidden or 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/bash | |
# Script to remove all Xcode DeveloperTools Cache files, | |
# provided Xcode is set to default folder locations | |
printf "clearing Xcode DeveloperTools cache..." | |
rm -rfv /var/folders/**/**/**/com.apple.DeveloperTools/* | |
rm -rfv ~/Library/Caches/com.apple.dt.Xcode/* | |
echo "done" | |
exit 0 |
This file contains hidden or 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
/** | |
* This software is in the public domain. Where that dedication is not recognized, | |
* you are granted a perpetual, irrevokable license to copy and modify this file | |
* as you see fit. | |
* | |
* Requires SDL 2.0.4. | |
* Devices that do not support Metal are not handled currently. | |
**/ | |
#import <UIKit/UIKit.h> |
This file contains hidden or 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
// Mini memory editor for ImGui (to embed in your game/tools) | |
// Animated GIF: https://cloud.githubusercontent.com/assets/8225057/9028162/3047ef88-392c-11e5-8270-a54f8354b208.gif | |
// | |
// You can adjust the keyboard repeat delay/rate in ImGuiIO. | |
// The code assume a mono-space font for simplicity! If you don't use the default font, use ImGui::PushFont()/PopFont() to switch to a mono-space font before caling this. | |
// | |
// Usage: | |
// static MemoryEditor mem_edit_1; // store your state somewhere | |
// mem_edit_1.Draw("Memory Editor", mem_block, mem_block_size, 0x0000); // run | |
// |
This file contains hidden or 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
/// Generates array form a tuple. Given tuple's elements must have homogenous type. | |
/// | |
/// - Parameter tuple: a (homogenous) tuple | |
/// - Returns: array of tuple elements | |
func makeArray<Tuple, Value>(from tuple: Tuple) -> [Value] { | |
let tupleMirror = Mirror(reflecting: tuple) | |
assert(tupleMirror.displayStyle == .tuple, "Given argument is no tuple") | |
assert(tupleMirror.superclassMirror == nil, "Given tuple argument must not have a superclass (is: \(tupleMirror.superclassMirror!)") | |
assert(!tupleMirror.children.isEmpty, "Given tuple argument has no value elements") | |
func convert(child: Mirror.Child) -> Value? { |
This file contains hidden or 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
/// Generates dictionary from a tuple. Given tuple's elements must have homogenous type. | |
/// | |
/// - Parameter tuple: a (homogenous) tuple | |
/// - Returns: dict of tuple elements | |
func makeDictionary<Tuple, Value>(from tuple: Tuple) -> [String:Value] { | |
let tupleMirror = Mirror(reflecting: tuple) | |
assert(tupleMirror.displayStyle == .tuple, "Given argument is no tuple") | |
assert(tupleMirror.superclassMirror == nil, "Given tuple argument must not have a superclass (is: \(tupleMirror.superclassMirror!)") | |
assert(!tupleMirror.children.isEmpty, "Given tuple argument has no value elements") |
This file contains hidden or 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
/// Calculates the combined hash of two values. This implementation is based on boost::hash_combine. | |
/// Will always produce the same result for the same combination of seed and value during the single run of a program. | |
/// | |
/// - Parameters: | |
/// - seed: seed hash. | |
/// - value: value to be combined with seed hash. | |
/// - Returns: combined hash value. | |
func hash(combine seed: Int, _ value: Int) -> Int { | |
/// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/combine.html | |
/// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/reference.html#boost.hash_combine |
This file contains hidden or 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
/** A pthread-based recursive mutex lock. */ | |
public class Mutex { | |
private var mutex: pthread_mutex_t = pthread_mutex_t() | |
public init() { | |
var attr: pthread_mutexattr_t = pthread_mutexattr_t() | |
pthread_mutexattr_init(&attr) | |
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) | |
let err = pthread_mutex_init(&self.mutex, &attr) |
OlderNewer