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
// check if folder contains file with given name after having performed | |
// file coordination | |
func fileExists(_ filename: String, in folder: URL) async throws -> Bool { | |
let found: Bool = try await withCheckedThrowingContinuation { cont in | |
let array = NSMutableArray() | |
@Sendable func complete(_ ok: Bool, _ error: Error?) { | |
objc_sync_enter(array) | |
let completed = array.count > 0 | |
array.add(1) | |
objc_sync_exit(self) |
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
// | |
// Promise.swift | |
// ShellFish | |
// | |
// Created by Anders Borum on 25/02/2019. | |
// Copyright © 2019 Anders Borum. All rights reserved. | |
// | |
import Foundation |
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 Array where Element == UIImage { | |
func gifData(frameDelay: TimeInterval = 0.2) -> Data? { | |
let data = NSMutableData() | |
guard let destination = CGImageDestinationCreateWithData(data, kUTTypeGIF, self.count, nil) else { | |
return nil | |
} | |
let frameProperties: CFDictionary = [kCGImagePropertyGIFDictionary as String: [(kCGImagePropertyGIFDelayTime as String): frameDelay]] as CFDictionary | |
let fileProperties: CFDictionary = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]] as CFDictionary | |
CGImageDestinationSetProperties(destination, fileProperties) |
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
{ | |
"weather": { | |
"body": ["curl 'https://wttr.in/?0'\n"], | |
"description": "Weather from terminal" | |
}, | |
"external-ip": { | |
"body": ["dig @resolver4.opendns.com myip.opendns.com +short\n"], | |
"description": "Lookup external IP" | |
}, | |
"30-day-old-files": { |
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
# include this from .bashrc, .zshrc or | |
# another shell startup file | |
# this script does nothing outside ShellFish | |
if [ "$LC_TERMINAL" = "ShellFish" ]; then | |
printURIComponent() { | |
awk 'BEGIN {while (y++ < 125) z[sprintf("%c", y)] = y | |
while (y = substr(ARGV[1], ++j, 1)) | |
q = y ~ /[a-zA-Z0-9]/ ? q y : q sprintf("%%%02X", z[y]) | |
printf("%s", q)}' "$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
// Keep polling the memory usage (through number of wired pages) every millisecond to discover if usage | |
// stays below some limit. | |
// | |
// let limit = MemoryGrowthLimit(megabytes: 5) | |
// hardWorkingMemoryConsumingMethodCall() | |
// XCTAssertFalse(limit.exceeded) | |
// | |
class MemoryGrowthLimit { | |
private let pollingInterval = 0.001 | |
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
console.log("Hello World!") |
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: pink; icon-glyph: user; | |
// lookup gravatar for contacts without images. | |
var MD5 = function (string) { | |
function RotateLeft(lValue, iShiftBits) { | |
return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits)); | |
} |
NewerOlder