Skip to content

Instantly share code, notes, and snippets.

@ptoffy
ptoffy / XCTAssertEqual
Last active September 22, 2024 09:23
Swift Testing Migration Utilities
replace: XCTAssertEqual\(([^,]+),\s*(.+?)\)
with: #expect($1 == $2)
@ptoffy
ptoffy / mysql-dump-container.sh
Created June 25, 2024 15:20
Create a MySQL 5.7 container from an SQL dump
docker run --platform linux/x86_64 \
--name resurva-delete-manager-mysql \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=database \
-e MYSQL_USER=username \
-e MYSQL_PASSWORD=password \
-v .../some_dump.sql:/docker-entrypoint-initdb.d/dump.sql \
-p 3306:3306 \
-d mysql:5.7
import json
import base64
from pyspx import sha2_128s
import os
# 48 bytes seed
seed = "0123456789abcdef0123456789abcdef0123456789abcdef".encode('utf-8')
public_key, secret_key = sha2_128s.generate_keypair(seed)
@ptoffy
ptoffy / RSAPrimeGenerator.swift
Created January 20, 2024 14:38
Generate RSA Prime Factors in Swift
/// The following algorithm recovers the prime factors of a modulus, given the public and private exponents.
/// The algorithm is based on Fact 1 in [Boneh 1999].
static func calculatePrimeFactors(n: BigUInt, e: BigUInt, d: BigUInt) throws -> (p: BigUInt, q: BigUInt) {
let k = (d * e) - 1
guard k & 1 == 0 else {
throw RSAError.keyInitializationFailure
}
let t = k.trailingZeroBitCount, r = k >> t
@ptoffy
ptoffy / ee.js
Last active September 22, 2023 16:53
Draw NDVI on Google EE
// Define function to compute NDVI
function addNDVI(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']).rename('ndvi'));
}
// Define function to filter and compute NDVI for a given year and region
function processYearlyData(year, region) {
var startDate = ee.Date.fromYMD(year, 4, 1);
var endDate = ee.Date.fromYMD(year, 9, 30);
@ptoffy
ptoffy / DummyNIOTest.swift
Created July 23, 2023 15:41
SwiftNIO Dummy Test
class DummyTests: XCTestCase {
var eventLoopGroup: EventLoopGroup!
var serverChannel: Channel?
var serverAddress: SocketAddress?
override func setUpWithError() throws {
eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
try startTestServer()
}