This file contains 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
// Demonstrating a bug with what the table view reports as the destination index path when dragging within | |
// the same section | |
import UIKit | |
class TableViewController: UITableViewController, UITableViewDragDelegate, UITableViewDropDelegate { | |
var data: [(String, [String])] = [("One", ["A", "B", "C"]), ("Two", ["1", "2", "3"])] | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains 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
import Foundation | |
/// Represents a sequence of Data split at a certain value | |
struct DataSplitSequence: Sequence { | |
typealias Element = Data | |
struct Iterator: IteratorProtocol { | |
private let sequence: DataSplitSequence | |
private var index: Int = -1 | |
This file contains 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
import UIKit | |
import WebKit | |
class WorkaroundWebViewController: UIViewController, WKNavigationDelegate { | |
let request: URLRequest | |
private let websiteDataStore = WKWebsiteDataStore.default() | |
private var webView: WKWebView! | |
private var initialDummyNavigation: WKNavigation? | |
This file contains 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
//: Playground - noun: a place where people can play | |
import Cocoa | |
enum ImageError: Error { | |
case couldNotCreateBitmapImage | |
case couldNotCreatePNGRepresentation | |
} | |
func renderIcon(text: String, backgroundColor: NSColor, sizeInPixels: Int) throws -> Data { |
This file contains 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
# Extension for zsh that cd to a simulator data container of the app with the given bundle identifier. | |
# | |
# See blog post at https://skagedal.github.io/2018/01/02/simcd.html | |
function simdir () { | |
xcrun simctl get_app_container booted $1 data | |
} | |
function simcd () { | |
cd `simdir $1` |
This file contains 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
// Demo for SO question: | |
// | |
// http://stackoverflow.com/questions/42659251/can-a-table-view-row-stay-put-while-its-section-is-moving | |
import UIKit | |
enum State: Int { | |
case first | |
case second | |
} |
This file contains 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
// Example code for https://openradar.appspot.com/radar?id=4975264899530752 since I can't attach | |
// a zip there and am to lazy to create a git repo for the whole thing. | |
// Create a standard iOS "Single View" application with Core Data in Xcode 7.3.1 | |
// Create one Core Data entity called Thing with an integer "order" and a string "name" | |
// Hook up a simple view controller to these actions | |
#import "AppDelegate.h" | |
#import "ViewController.h" | |
#import "Thing.h" |
This file contains 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
extension UIViewController { | |
func rz_smoothlyDeselectRows(tableView tableView: UITableView?) { | |
let selectedIndexPaths = tableView?.indexPathsForSelectedRows ?? [] | |
if let coordinator = transitionCoordinator() { | |
coordinator.animateAlongsideTransitionInView(parentViewController?.view, animation: { context in | |
selectedIndexPaths.forEach { | |
tableView?.deselectRowAtIndexPath($0, animated: context.isAnimated()) | |
} |
This file contains 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
from urllib.request import urlopen | |
counter = 1 | |
while True: | |
url = 'http://libris.kb.se/xsearch?d=swepub&hitlist&q=l%C3%A4ros%C3%A4te%3agu&f=ext&spell=true&hist=true&n=200&format=json&start=' + str(counter) | |
print ("Fetching: " + url) | |
data = urlopen(url).read() | |
if not data.find(b'"identifier"') >= 0: | |
print("No more records!") |
This file contains 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
import json | |
import re | |
from os import listdir | |
def fix_escapes(string): | |
# Libris over-escapes some backslashes. | |
string = string.replace("\\\\\"","\\\"") | |
# Libris fails to properly escape backslashes in strings, which occurs for example with inline | |
# LaTeX codes like "$\geq" which should be escaped as "$\\geq". They do seem to properly | |
# escape quote chars, however. Now, we can't easily know whethera string liike "\n" should be |
NewerOlder