Skip to content

Instantly share code, notes, and snippets.

@mxcl
mxcl / tea-rfc1.md
Last active February 20, 2023 13:36 — forked from mfts/tea-rfc1.md
RFC: Dependency Manager Install Location
View tea-rfc1.md

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.

View chalk-demo.swift
#!/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 April 15, 2022 08:33
Delete all tweets and favorites older than two months ago. Instructions in comment.
View detweet.swift
#!/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"
View UUID+ascii85.swift
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)
View apple-receipt-validation-response-decodable.swift
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
View UIAlertController+Error.swift
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))
View Error+legibleDescription.swift
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):
View Error+legibleDescription.swift
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 {
View Hexagon-hard-way.swift
// 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)
View UIImage+Blur+Swift4.swift
extension UIImage {
func blurred(radius: CGFloat) -> UIImage {
let ciContext = CIContext(options: nil)
guard let cgImage = cgImage else { return self }
let inputImage = CIImage(cgImage: cgImage)
guard let ciFilter = CIFilter(name: "CIGaussianBlur") else { return self }
ciFilter.setValue(inputImage, forKey: kCIInputImageKey)
ciFilter.setValue(radius, forKey: "inputRadius")
guard let resultImage = ciFilter.value(forKey: kCIOutputImageKey) as? CIImage else { return self }