Skip to content

Instantly share code, notes, and snippets.

View wildthink's full-sized avatar

Jason Jobe wildthink

  • 08:18 (UTC -05:00)
View GitHub Profile
@wildthink
wildthink / transducers.swift
Created November 21, 2016 18:21 — forked from rjchatfield/transducers.swift
Transducers & Reducers in Swift 2
//-- This is an introduction to Transducers in Swift, inspired by
// Talk: https://www.youtube.com/watch?v=estNbh2TF3E
// Code: https://github.com/mbrandonw/learn-transducers-playground
// Updated with Swift 2
/**
* Define a few test methods
*/
/// REDUCER
func append <A> (xs: [A], x: A) -> [A] { return xs + [x] }
@wildthink
wildthink / StringLiteral.swift
Created December 30, 2016 19:23 — forked from russbishop/StringLiteral.swift
Make ExpressibleByStringLiteral tolerable
// If you want types initializable from String literals
// but don't want to implement three separate initializers.
extension ExpressibleByUnicodeScalarLiteral where Self: ExpressibleByStringLiteral, Self.StringLiteralType == String {
public init(unicodeScalarLiteral value: String) {
self.init(stringLiteral: value)
}
}
@wildthink
wildthink / dawg.py
Created January 10, 2017 19:37 — forked from smhanov/dawg.py
Use a DAWG as a map
#!/usr/bin/python3
# By Steve Hanov, 2011. Released to the public domain.
# Updated 2014 to use DAWG as a mapping.
import sys
import time
DICTIONARY = "/usr/share/dict/words"
QUERY = sys.argv[1:]
# This class represents a node in the directed acyclic word graph (DAWG). It
@wildthink
wildthink / CGRectAspectFit.m
Created March 22, 2017 17:15 — forked from lanephillips/CGRectAspectFit.m
Objective-C code to fit a CGRect inside or outside another CGRect while maintaining aspect ratio. The fitted rectangle is centered on the target rectangle.
CGFloat ScaleToAspectFitRectInRect(CGRect rfit, CGRect rtarget)
{
// first try to match width
CGFloat s = CGRectGetWidth(rtarget) / CGRectGetWidth(rfit);
// if we scale the height to make the widths equal, does it still fit?
if (CGRectGetHeight(rfit) * s <= CGRectGetHeight(rtarget)) {
return s;
}
// no, match height instead
return CGRectGetHeight(rtarget) / CGRectGetHeight(rfit);
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;
@wildthink
wildthink / WeakSet.swift
Created July 11, 2017 18:29 — forked from preble/WeakSet.swift
A pure Swift weak set.
//
// Created by Adam Preble on 2/19/15.
//
/// Weak, unordered collection of objects.
public struct WeakSet<T where T: AnyObject, T: Hashable> {
typealias Element = T
/// Maps Element hashValues to arrays of Entry objects.
/// Invalid Entry instances are culled as a side effect of add() and remove()
@wildthink
wildthink / spaceutil.c
Created February 20, 2018 16:55 — forked from camillol/spaceutil.c
Two ways of messing with spaces
#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
typedef int CGSConnection;
extern OSStatus CGSGetWorkspace(const CGSConnection cid, int *workspace);
extern OSStatus CGSSetWorkspace(const CGSConnection cid, int workspace);
extern CGSConnection _CGSDefaultConnection(void);
int get_space_id(void);
@wildthink
wildthink / Swift – func deepDescription
Last active July 20, 2018 20:31 — forked from mhuusko5/Swift – func deepDescription
Swift – func deepDescription(any: Any) -> String (pretty print any object, recursively)
func deepDescription(_ any: Any) -> String {
guard let any = deepUnwrap(any) else {
return "nil"
}
if any is Void {
return "Void"
}
if let int = any as? Int {
@wildthink
wildthink / CodableExtension.swift
Created March 8, 2020 01:21 — forked from sukov/CodableExtension.swift
Codable (Encode & Decode) [Any] and [String: Any] Swift 5
// Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
import Foundation
private struct JSONCodingKeys: CodingKey {
var stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}
@wildthink
wildthink / .lldbinit
Created April 9, 2020 17:31 — forked from maxchuquimia/.lldbinit
My .lldbinit
command alias objc expression -l objc -O --
command regex swift 's#(.+)#expression -l Swift -O -- defer { CATransaction.flush() }; %1#'
breakpoint set -n AppDelegate.application --one-shot true --auto-continue true
breakpoint command add
swift import Foundation
swift import UIKit
swift import MyApp_tvOS
swift import MyApp_iOS
swift func $printSubviews(of view: UIView) { print(view.perform("recursiveDescription")!) }