Skip to content

Instantly share code, notes, and snippets.

Avatar

Max Howell mxcl

View GitHub Profile
View uninstall_homebrew.sh
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
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 }
@mxcl
mxcl / detweet.swift
Last active Aug 4, 2020
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"
@mxcl
mxcl / rsync+watcher.rb
Created Jul 18, 2009
rsync whenever the directory the script is in changes using the OS X FSEvents API
View rsync+watcher.rb
#!/usr/bin/ruby
require 'osx/foundation'
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
include OSX
$d=File.basename Dir.pwd
Dir.chdir '..'
fsevents_cb = proc do |stream, ctx, numEvents, paths, marks, eventIDs|
system "rsync --delete -rt --rsh=ssh '#{$d}' 'methylblue.com:public_html/'"
@mxcl
mxcl / install_homebrew.markdown
Created Mar 6, 2010
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
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 zodiac.swift
enum Zodiac: String {
case aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, sagittarius, capricorn, aquarius, pisces
}
extension Zodiac {
var dateRangeString: String {
let df = DateFormatter()
df.dateFormat = "MMM d"
let from = df.string(from: dateRange.lowerBound)
let to = df.string(from: dateRange.upperBound)
View UIImage+darken.swift
extension UIImage {
func darkened() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
defer { UIGraphicsEndImageContext() }
guard let ctx = UIGraphicsGetCurrentContext(), let cgImage = cgImage else {
return nil
}
// flip the image, or result appears flipped
View PMK5.swift
import Foundation
// Caveats (specify fixes alongside)
// * Promise { throw E.dummy } is interpreted as `Promise<() throws -> Void>` of all things
// * Promise(E.dummy) is interpreted as `Promise<E>`
// Remarks:
// * We typically use `.pending()` to reduce nested insanities in your backtraces
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)
You can’t perform that action at this time.