Skip to content

Instantly share code, notes, and snippets.

View robinkunde's full-sized avatar

Robin Kunde robinkunde

View GitHub Profile
func exportVisibleImages() {
for (windowIndex, window) in UIApplication.shared.windows.enumerated() {
let prefix = "iOS\(ProcessInfo.processInfo.operatingSystemVersion.majorVersion)_window\(windowIndex)_images"
exportImages(fromRootView: window, toDirectory: "/path/to/target/directory", prefix: prefix)
}
}
func exportImages(fromRootView rootView: UIView, toDirectory directory: String, prefix: String) {
let directoryURL = URL(fileURLWithPath: directory, isDirectory: true)
try! FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
@robinkunde
robinkunde / erx_generate_static_dhcp.py
Last active July 12, 2018 21:24
Use this script to generate `configure` commands for static DHCP IP address assignment on EdgeRouter X
#!/usr/bin/env python3
import argparse
import os
import csv
usage = '''Use this script to generate configure commands.
Expected input csv format: identifier,identifier_suffix(optional),ignored,mac-address-with-dashes,ip4-address
First line is ignored.
@robinkunde
robinkunde / fontNames.swift
Created August 21, 2019 02:24
Print certain font names
for familyName in UIFont.familyNames.sorted() {
var hasPrintedFamilyName = false
for fontName in UIFont.fontNames(forFamilyName: familyName).sorted() {
let font = UIFont(name: fontName, size: 16.0)!
guard font.fontDescriptor.symbolicTraits.contains(.traitMonoSpace) else { continue }
if !hasPrintedFamilyName {
print(familyName)
hasPrintedFamilyName = true
}
@robinkunde
robinkunde / DTMobileProvision.swift
Created October 17, 2019 20:02
ASN1 mobile provision parser using DTFoundation
struct MobileProvision {
private let dict: [String: Any]?
init() {
let mpURL = Bundle.main.bundleURL.appendingPathComponent("embedded.mobileprovision")
guard let data = try? Data(contentsOf: mpURL) else {
dict = nil
return
}
import UIKit
public extension UIApplication {
func clearLaunchScreenCache() {
do {
try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard")
} catch {
print("Failed to delete launch screen cache: \(error)")
}
import Foundation
struct LinearStringConsumer {
let str: String
private(set) var currentIndex: String.Index
var currentOffset: String.IndexDistance {
return str.distance(from: str.startIndex, to: currentIndex)
}
@robinkunde
robinkunde / dnsLookup.swift
Created May 28, 2021 22:15
Perform DNS lookups using Swift code
//
// dnsLookup.swift
//
// Created by Robin Kunde on 5/28/21.
//
import dnssd
import Foundation
typealias DNSResultHandler = (String, Int) -> Void
#if DEBUG
import Foundation
import UIKit
class SimPasteboardHelper {
static let shared = SimPasteboardHelper()
private var handle: FileHandle?
private var dispatchSource: DispatchSourceFileSystemObject?