Skip to content

Instantly share code, notes, and snippets.

@jonblatho
jonblatho / ModelName.swift
Last active April 18, 2024 23:11
An easy way to get a pretty name for an iOS device model.
import UIKit
extension UIDevice {
/// A "pretty" device name for the machine identifier.
///
/// Current for devices supporting iOS 9 and later and tvOS 9 and later, as of WWDC 2019.
var modelName: String {
var machineString = String()
var systemInfo = utsname()
@jonblatho
jonblatho / PointInPolygon.swift
Last active November 13, 2023 06:31
Some Swift code to determine whether a point is inside a polygon.
/// Contains the coordinates of a point in a 2D Cartesian coordinate system.
public struct Point: Hashable {
/// The x-coordinate of the point.
public var x: Double
/// The y-coordinate of the point.
public var y: Double
}
extension Array where Element == Point {
/// Returns only the unique points in the array.
@jonblatho
jonblatho / zcta-block.py
Last active March 30, 2021 04:32
Calculates the population of ZIP Code Tabulation Areas (ZCTAs) which intersect with Howell County, MO
import shapefile
from shapely.geometry import shape
def __shapely_polygon__(s):
return shape(s.shape.__geo_interface__)
# Read Missouri census block shapefile
block_file = shapefile.Reader("block/tabblock2010_29_pophu.shp")
# Obtained from https://www.census.gov/geographies/mapping-files/2010/geo/tiger-data.html
# Read ZIP code tabulation area shapefile
# Calculates the overlap area between two circles of radii r1 and r2 with
# center points d apart.
def circle_overlap_area(r1, r2, d):
try:
# Expression from http://mathworld.wolfram.com/Circle-CircleIntersection.html
return r2**2 * acos((d**2+r2**2-r1**2)/(2*d*r2))+r1**2*acos((d**2-r2**2+r1**2)/(2*d*r1)) - 1/2*sqrt((-d+r2+r1)*(d+r2-r1)*(d-r2+r1)*(d+r2+r1))
except:
# A few possible cases if there's a math domain error...
if r1 == r2 and d == 0:
# Identical circle radii and center points
extension UIStackView {
/**
Fills the given scroll view with this stack view. This method automatically creates
and activates constraints and adds the stack view to the scroll view.
- parameter scrollView: The scroll view into which this stack view should be inserted.
*/
internal func attachToScrollView(_ scrollView: UIScrollView) {
// Add this stack view to the given UIScrollView
scrollView.addSubview(self)
FROM swift:4
WORKDIR /build
COPY Sources ./Sources
COPY Package.swift .
RUN swift package resolve
RUN swift build
COPY pkg-swift-deps.sh /usr/bin/pkg-swift-deps
import sys
import re
import fileinput
# This script takes a list of air temperatures extracted from historical METARs
# obtained from https://mesonet.agron.iastate.edu/request/download.phtml.
#
# Use it in the command line with something along the lines of
# $ python2.7 asos-filter.py asos-1997.csv
# where the parameter is the text file you want to filter through. It only
//
// HomeTableViewController.swift
//
// Created by Jonathan Thornton on 12/22/17.
// Copyright © 2017 Jonathan Thornton. All rights reserved.
//
import UIKit
class HomeTableViewController: UITableViewController {

Keybase proof

I hereby claim:

  • I am jonblatho on github.
  • I am jonblatho (https://keybase.io/jonblatho) on keybase.
  • I have a public key whose fingerprint is 6917 A05E 6986 965B C18B E13E 027C D5CD BAFF 8E89

To claim this, I am signing this object: