Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Shaps shaps80

🏠
Working from home
View GitHub Profile
View type-safe-routing.swift
//
// main.swift
// RoutingApproaches
//
// Created by Chris Eidhof on 01.08.18.
// Copyright © 2018 objc.io. All rights reserved.
//
import Foundation
@jordwalke
jordwalke / watch.sh
Last active Sep 19, 2018
Watcher Script Using Unix Find.
View watch.sh
#!/bin/bash
# Invoke like this:
# ./watch.sh my command here
# And it will run 'my command here' once, and then when it detects changes.
# TODO: Don't just search in the last second. Search for updates since the last
# completed build. Otherwise for big directories, midway through your search
# you've already taken 1s and you will miss updates.
View ocr-shot.sh
#!/bin/bash
set -e
CONTENTS=$(tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/tessdata/ "$1" stdout -l eng | xml esc)
hex=$((cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@macguru
macguru / MXSEventTrackingWindow.h
Created Sep 2, 2016
Tell if a user interaction is currently happening though a touch event in a view's window or something else – like an external keyboard or interaction in a different window (keyboard window). Example use: check if selection change was through touch or external keyboard.
View MXSEventTrackingWindow.h
//
// MXSEventTrackingWindow.h
//
// Created by Max Seelemann on 01.09.16.
// Copyright © 2016 The Soulmen. All rights reserved.
//
/*!
@abstract Special window class used for advanced event processing.
*/
@lucianomarisi
lucianomarisi / NSObject+MemoryLeak.swift
Created Apr 16, 2016
Extension for ensuring one instance of a class is live at any one point
View NSObject+MemoryLeak.swift
extension NSObject {
// Call this when the class being debugged is initialized
func debug_ensureOnlyOneInstanceSetup() {
let type = self.dynamicType
let currentCreatedCount = createdCount(type)
assert(currentCreatedCount == 0, "More that 1 \(self) created, potential memory leak")
setCreateCount(currentCreatedCount + 1, classType: type)
}
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active Feb 12, 2021
Type-safe value-oriented collection view data source
View CollectionViewDataSource.swift
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@steipete
steipete / CaseInsensitiveDictionary.m
Created Dec 1, 2013
Implemented as a category on NSDictionary.
View CaseInsensitiveDictionary.m
static Boolean PSPDFCaseInsensitiveEqualCallback(const void *a, const void *b) {
id objA = (__bridge id)a, objB = (__bridge id)b;
Boolean ret = FALSE;
if ([objA isKindOfClass:NSString.class] && [objB isKindOfClass:NSString.class]) {
ret = ([objA compare:objB options:NSCaseInsensitiveSearch|NSLiteralSearch] == NSOrderedSame);
}else {
ret = [objA isEqual:objB];
}
return ret;
}