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
// Parse measurement expressions like `"5 m²"` and convert them into `Measurement` values. | |
// Uses the Objective-C runtime to find the known and valid symbols for a given unit | |
// (such as `UnitArea`). Adopts `ExpressibleByStringLiteral` for easy initialization. | |
import ObjectiveC | |
enum ObjectiveCRuntime { | |
class Class { | |
let base: AnyClass |
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
let str = "👨🏾🚒" | |
print(str.unicodeScalars.map { "0x\(String($0.value, radix: 16))" }) | |
// → ["0x1f468", "0x1f3fe", "0x200d", "0x1f692"] | |
print(str.utf16.map { "0x\(String($0, radix: 16))" }) | |
// → ["0xd83d", "0xdc68", "0xd83c", "0xdffe", "0x200d", "0xd83d", "0xde92"] | |
print(str.utf16.count) | |
// → 7 | |
let utf16Offset = 2 |
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
func ~= <T, U> (pattern: T.Type, value: U.Type) -> Bool { | |
return pattern == value | |
} | |
func f<T>(_ type: T.Type) { | |
switch T.self { | |
case Int.self: | |
print("Int") | |
default: | |
print("Something else") |
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
Process: Notes [17745] | |
Path: /Applications/Notes.app/Contents/MacOS/Notes | |
Identifier: com.apple.Notes | |
Version: 4.5 (863) | |
Build Info: Notes-863000000000000~1 | |
Code Type: X86-64 (Native) | |
Parent Process: ??? [1] | |
Responsible: Notes [17745] | |
User ID: 501 |
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
let s = "Hello World" | |
let evenIndices = s.indices.enumerated() | |
.filter { $0.offset % 2 == 0 } | |
.map { $0.element } | |
for idx in evenIndices { | |
print(s[idx]) | |
} |
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
#!/usr/bin/env ruby | |
# Determines the coordinates (latitude and longitude) of the places or | |
# addresses passed as arguments (either on the command line or via stdin) | |
# and prints the results. | |
# This script requires the Ruby Geocoder gem by Alex Reisner | |
# (http://www.rubygeocoder.com). | |
# To install the gem, run this command from a Terminal session: | |
# |
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 | |
import PlaygroundSupport | |
let bigFile = URL(string: "https://speed.hetzner.de/1GB.bin")! | |
let task = URLSession.shared.dataTask(with: bigFile) { (data, response, error) in | |
print("data: \(data)") | |
print("response: \(response)") | |
print("error: \(error)") | |
} | |
task.resume() |
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
#!/bin/sh | |
if ( [ "$CONFIGURATION" == "Debug" ] ) then | |
echo "Enabling filesharing flags for '$CONFIGURATION' configuration in "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"" | |
/usr/libexec/PlistBuddy -c "Set :UIFileSharingEnabled true" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" | |
/usr/libexec/PlistBuddy -c "Set :LSSupportsOpeningDocumentsInPlace true" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" | |
fi |
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
/// An unescaped string from a potentially unsafe | |
/// source (such as user input) | |
struct UnsafeString { | |
var value: String | |
} | |
/// A string that either comes from a safe source | |
/// (e.g. a string literal in the source code) | |
/// or has been escaped. | |
struct SanitizedHTML { |
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 | |
let containingRect = CGRect(x: 0, y: 0, width: 100, height: 100) | |
let path1 = UIBezierPath(rect: containingRect) | |
let circleRect = CGRect(x: 50, y: 10, width: 80, height: 80) | |
let circleCenter = CGPoint(x: circleRect.midX, y: circleRect.midY) | |
let radius = circleRect.height / 2 | |
/* |