Skip to content

Instantly share code, notes, and snippets.

View younata's full-sized avatar

Rachel Brindle younata

View GitHub Profile
@younata
younata / BackgroundExecutorApp.swift
Created March 19, 2024 00:41
BackgroundExecutorTestApp
import SwiftUI
import Dispatch
// A simple app to verify https://mastodon.social/@calicoding/112118821467209266
// Allows you to check using Swift Tasks, or Dispatch Queues.
//
// I found this to not be the case, but maybe this isn't realistic?
// When compiled on Xcode 15.3 (either debug or release) and run on iOS 17.4,
// background QoS tasks are still executed even when Low Power Mode is enabled.
import Combine
class FakeCall<T> {
private(set) var calls = [T]()
func record(_ arguments: T) {
calls.append(arguments)
}
func reset() {
@younata
younata / layouthelpers.swift
Created December 19, 2020 21:02
UIView Autolayout Helpers
import UIKit
extension UIView {
func removeAllSubviews() {
for view in self.subviews {
view.removeFromSuperview()
}
}
@discardableResult
@younata
younata / BadCSVParser.swift
Created October 7, 2018 16:15
Bad CSV Parser in swift
// Quick and dirty CSV parser I wrote. Handles edge cases badly. Doesn't perform well. Doesn't handle large csv files.
// But, hey, it solved my use case!
// Swift 4.2+
func parseCSVBadly(csvData: Data) -> [[String]] {
guard let csv = String(data: csvData, encoding: .utf8) else { return [] }
return csv.components(separatedBy: CharacterSet.newlines).compactMap { line in
guard !line.hasPrefix("#") else { return nil }
return line.components(separatedBy: ",")
}
@younata
younata / concourse_deployment.yml
Last active November 8, 2016 19:55
ci.younata.com concourse manifest
---
name: concourse
director_uuid: RESULT OF bosh status --uuid
releases:
- name: concourse
version: latest
- name: garden-runc
version: latest
@younata
younata / NetworkSpec.swift
Created February 22, 2016 23:08
What Carthage/NetworkSpec.swift could have been
// I spent 2 hours working on this before I gave up. This is what I had when I declared it not worth the effort.
import Quick
import Nimble
import ReactiveCocoa
import CarthageKit
import OHHTTPStubs
class NetworkSpec: QuickSpec {
override func spec() {
@younata
younata / gist:8264679
Created January 5, 2014 05:12
weird output from stlparser.
you$ ./stlparser untitled.stl
(triangle 0:)
Normal: 0.000000, 0.000000, -1.000000
Vertex 0: 4.341105, 20.788564, 0.000000
Vertex 1: -19.261895, 0.018564, 0.000000
Vertex 2: -19.261895, 20.788564, 0.000000
(triangle 1:)
Normal: 0.000000, 0.000000, -1.000000
Vertex 0: -19.261895, 0.018564, 0.000000
Vertex 1: 4.341105, 20.788564, 0.000000
@younata
younata / gist:8264623
Created January 5, 2014 05:05
heisenbug in stlparser.
you$ ./stlparser untitled.stl
stlparser(71086,0x7fff77ac2310) malloc: *** error for object 0x7fbcd8d007a8: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
you$ ./stlparser untitled.stl # no change to the code/binary.
<normal output>
@younata
younata / blog.py
Created December 12, 2013 21:45
Very hacky blog script. I stuck it in cron, it gets run daily as me.
#!/usr/local/bin/python
from webhelpers.feedgenerator import Atom1Feed
import os
import datetime
def genPost(webRoot, homeDir):
f = open(homeDir + "flightSim/post1.html")
idx = f.read()
f.close()
@younata
younata / AssembleMapFromMapquest.py
Created November 30, 2013 06:24
Script to generate large satellite image maps by querying mapquest. note that the inputs is the zoom, far north, far west, [far south, far west]. If far_south and far_west are not given, they are the next lowest integers. everything is in degrees. for non-US areas, max zoom level is 11, for US-areas, max zoom level 18. Todo is pretty much parall…
#!/usr/bin/env python
from PIL import Image
import math
import requests
import StringIO
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom