Skip to content

Instantly share code, notes, and snippets.

View palmin's full-sized avatar

Anders Borum palmin

View GitHub Profile
var _require_cache_ = {};
function require(name) {
let local = FileManager.local();
// look for script with the given name in iCloud documents
// and current directory adding .js to filename is not present
let resolve = function(name) {
var filename = name;
if(name.indexOf('.js') < 0) {
filename += '.js';
//
// Promise.swift
// ShellFish
//
// Created by Anders Borum on 25/02/2019.
// Copyright © 2019 Anders Borum. All rights reserved.
//
import Foundation
import SwiftUI
#if os(iOS)
import UIKit
struct BranchPickerButton: UIViewRepresentable {
public var title: String = ""
public let producer: () async throws -> [(String, String)]
@Binding public var value: String
@palmin
palmin / Merge Pull Request.py
Last active March 30, 2023 15:39
Merge Pull Request.py
#!python2
# coding: utf-8
#
# This script is meant to be used from the Pythonista action extension when Safari is showing
# a GitHub Pull Request and will ask Working Copy to merge+pull the pull-request thus fullfulling it.
# You need to already have this repository cloned in Working Copy.
#
# It only works on public repositories, since the script lacks a way to authorize, but things
# happening in Working Copy can be fully authorized with either SSH Key or username / password.
#
@palmin
palmin / gist:14300e8bf529d05e7e53
Last active September 25, 2022 07:55 — forked from shannoga/gist:1008678
Get fonts family and font names list on iOS
// List all fonts on iPhone
for (NSString* family in [UIFont familyNames]) {
NSLog(@"Family name: %@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family]) {
NSLog(@" Font name: %@", name);
}
}
@palmin
palmin / .shellfishrc
Last active September 25, 2022 07:54
# 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"
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)
private var constantFloatSelection = NSMakeRange(0, 0)
public override func beginFloatingCursor(at point: CGPoint) {
// remember how it starts out
constantFloatSelection = selectedRange
super.beginFloatingCursor(at: point)
}
public override func updateFloatingCursor(at point: CGPoint) {
// 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