Skip to content

Instantly share code, notes, and snippets.

@mxcl
mxcl / stargazer.sh
Last active October 31, 2023 17:22
All-in-one Script to Generate your @pomber/stargazer video
#!/usr/bin/env -S pkgx +git +gum +gh +npm +jq bash
# ^^ curl https://pkgx.sh | sh
# ^^ pkgx makes all those tools (including bash!) available to the script
# no packages are installed; your system remains pristine
set -eo pipefail
if [ -d stargazer/.git ]; then
cd stargazer
elif [ ! -d .git ] && gum confirm 'clone to ./stargazer?'; then
@mxcl
mxcl / tea-rfc1.md
Last active February 20, 2023 13:36 — forked from mfts/tea-rfc1.md
RFC: Dependency Manager Install Location

Motivation

One of the core benefits of tea: it's relocatable. tea does not pollute your system environment, everything gets "installed" in a relocatable folder ~/.tea.

tea can also install languages like node and ruby and it's dependency managers, npm and gem, respectively. However, these language dependency managers install packages to global directories like ~/.npm and ~/.gem. Tools from these ecosystems expect to find packages in these locations.

In this RFC, we would love to hear feedback from the community.

#!/usr/bin/swift sh
import Foundation
import Chalk // @mxcl == 0.3
extension Int {
var fg: UInt8 {
if !(16..<250 ~= self) || 24...36 ~= (self - 16) % 36 {
return 16
} else {
return 255
@mxcl
mxcl / detweet.swift
Last active December 23, 2023 23:22
Delete all tweets and favorites older than two months ago. Instructions in comment.
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
private extension UUID {
/// a more concise representation of UUIDs
var ascii85: String {
func convert(_ a: UInt8, _ b: UInt8, _ c: UInt8, _ d: UInt8) -> [UInt8] {
if a == 0, b == 0, c == 0, d == 0 {
return [122] // "z"
}
let x = UInt(a) * 52200625 + UInt(b) * 614125 + UInt(c) * 7225 + UInt(d)
struct AppleReceiptValidationResponse: Decodable {
let status: Int
let environment: String
struct Receipt: Decodable {
let receipt_type: String
let adam_id: Int
let app_item_id: Int
let bundle_id: String
let application_version: String
let download_id: Int
import PromiseKit
public extension UIViewController {
@discardableResult
func alert(error: Error, title: String? = nil, file: StaticString = #file, line: UInt = #line) -> Guarantee<Void> {
let (promise, seal) = Guarantee<UIAlertAction>.pending()
let alert = UIAlertController(title: title ?? String(describing: type(of: error)), message: error.legibleDescription, preferredStyle: .alert)
alert.addAction(.init(title: "OK", style: .default, handler: seal))
extension Error {
public var legibleDescription: String {
switch errorType {
case .swiftError(.enum?):
return "\(type(of: self)).\(self)"
case .swiftError:
return String(describing: self)
case .swiftLocalizedError(let msg):
return msg
case .nsError(_, "kCLErrorDomain", 0):
public extension Error {
var legibleDescription: String {
if let error = self as? LocalizedError, let description = error.errorDescription {
return description
} else if (self as AnyObject).isKind(of: NSError.self) {
return localizedDescription
} else {
let mirror = Mirror(reflecting: self)
switch mirror.displayStyle {
// without turtle drawing a hexagon is math heavy and not trivial to modify
let numberOfSides: CGFloat = 6
let radiusOuterCircle: CGFloat = bounds.width
let sideLength = radiusOuterCircle / 2
let theta = (CGFloat.pi * 2) / numberOfSides
let centerX = sideLength / 2
let centerY = sideLength / 2
let initialPoint = CGPoint(x: radiusOuterCircle * cos(2 * CGFloat.pi * 0/numberOfSides + theta) + centerX, y: radiusOuterCircle * sin(2 * CGFloat.pi * 0/numberOfSides + theta) + centerY)