Skip to content

Instantly share code, notes, and snippets.

@marcoarment
marcoarment / parallelize.c
Last active August 12, 2024 08:09
A simple shell command parallelizer.
/* parallelize: reads commands from stdin and executes them in parallel.
The sole argument is the number of simultaneous processes (optional) to
run. If omitted, the number of logical CPUs available will be used.
Build: gcc -pthread parallelize.c -o parallelize
Demo: (for i in {1..10}; do echo "echo $i ; sleep 5" ; done ) | ./parallelize
By Marco Arment, released into the public domain with no guarantees.
@marcoarment
marcoarment / ATPLogoView.m
Created April 29, 2014 21:07
Source for the Accidental Tech Podcast (ATP) T-Shirt
// Source for the Accidental Tech Podcast (ATP) T-Shirt:
// http://www.marco.org/2014/04/29/atp-shirts
//
// By Marco Arment, April 28, 2014. MIT license.
@implementation ATPLogoView
- (void)drawRect:(CGRect)rectIgnored
{
NSString *fontName = @"MyriadPro-Semibold";
@marcoarment
marcoarment / apns_jwt_token.php
Last active October 14, 2024 13:36
Generate ES256 JWT tokens for Apple Push Notification Service (APNS) in PHP
<?php
function base64url_encode($binary_data) { return strtr(rtrim(base64_encode($binary_data), '='), '+/', '-_'); }
function apns_jwt_token($team_id, $key_id, $private_key_pem_str)
{
if (! function_exists('openssl_get_md_methods') || ! in_array('sha256', openssl_get_md_methods())) throw new Exception('Requires openssl with sha256 support');
$private_key = openssl_pkey_get_private($private_key_pem_str);
if (! $private_key) throw new Exception('Cannot decode private key');
@marcoarment
marcoarment / Sun.swift
Created January 17, 2021 16:43
Get sunrise, sunset, and the sun's position for a given time and location. Based on NOAA Solar Calculator.
// Sun.swift
// Created by Marco Arment on 1/17/21
//
// Solar-math functions are directly translated from the NOAA Solar Calculator:
// https://www.esrl.noaa.gov/gmd/grad/solcalc/
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
@marcoarment
marcoarment / S3.php
Last active June 18, 2024 14:15
A simple PHP class to perform basic operations against Amazon S3 and compatible services.
<?php
/*
A simple PHP class to perform basic operations against Amazon S3 and compatible
services. Requires modern PHP (7+, probably) with curl, dom, and iconv modules.
Copyright 2022 Marco Arment. Released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
import SwiftUI
extension UIColor: Identifiable {
public var id: String {
get { self.accessibilityName }
}
}
struct ContentView: View {
#!/bin/bash
shopt -s nullglob
LOCALUSER=marco # Change this for you, obviously
DISABLED_FILES_DIR=/Users/$LOCALUSER/.quit-adobe
# Are any Adobe user-facing apps running? Assuming they begin with "Adobe ", e.g. "Adobe Audition 2022"
ps ax -c -o 'command=' | egrep '^Adobe ' | fgrep -v 'Adobe Desktop Service' | fgrep -v 'Adobe Installer' > /dev/null
if [ $? -eq 1 ] ; then
import SwiftUI
struct ContentView: View {
@State var numbers = [1, 2, 3, 4, 5, 6, 7, 8]
var body: some View {
Button {
withAnimation {
numbers.append(Int.random(in: 9..<99))
numbers.sort()
@marcoarment
marcoarment / Text+InlineSymbol.swift
Last active October 26, 2023 17:13
SwiftUI Text with inline SF Symbols
import SwiftUI
extension Text {
public struct InlineSymbol {
public let name: String
public let accessibilityLabel: String
public let color: Color?
public init(name: String, accessibilityLabel: String, color: Color? = nil) {
self.name = name
@marcoarment
marcoarment / Searchable_iOS16.swift
Created July 11, 2023 19:23
Backporting iOS 17's SwiftUI .searchable($isPresented) binding for iOS 16
import SwiftUI
extension View {
public func searchable_iOS16(text: Binding<String>, isPresented: Binding<Bool>, placement: SearchFieldPlacement) -> some View {
modifier(Searchable_iOS16(text: text, isPresented: isPresented, placement: placement))
}
}
public struct Searchable_iOS16: ViewModifier {
@Binding var text: String