Skip to content

Instantly share code, notes, and snippets.

@mxcl
mxcl / detweet.swift
Last active August 16, 2024 15:38
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"
@rxwei
rxwei / ad-manifesto.md
Last active December 6, 2024 16:54
First-Class Automatic Differentiation in Swift: A Manifesto
@Eradash
Eradash / osxvpnrouting.markdown
Last active October 4, 2018 18:23 — forked from taldanzig/osxvpnrouting.markdown
Routing tips for VPNs on OS X

Routing tips for VPNs on OS X

When VPNs Just Work™, they're a fantastic way of allowing access to a private network from remote locations. When they don't work it can be an experience in frustration. I've had situations where I can connect to a VPN from my Mac, but various networking situations cause routing conflicts. Here are a couple of cases and how I've been able to get around them.

Specific cases

Case 1: conflicting additional routes.

In this example the VPN we are connecting to has a subnet that does not conflict with our local IP, but has additional routes that conflict in some way with our local network's routing. In my example the remote subnet is 10.0.x.0/24, my local subnet is 10.0.y.0/24, and the conflicting route is 10.0.0.0/8. Without the later route, I can't access all hosts on the VPN without manually adding the route after connecting to the VPN:

@DougGregor
DougGregor / dynamic_member_lookup_environment.swift
Created May 2, 2018 16:59
Using Swift 4.2's @dynamicMemberLookup to expose environment variables
import Darwin
@dynamicMemberLookup
struct Environment {
subscript(dynamicMember name: String) -> String? {
get {
guard let value = getenv(name) else { return nil }
return String(validatingUTF8: value)
}
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 10, 2025 19:06
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@hitvoice
hitvoice / plot_confusion_matrix.png
Last active October 16, 2024 13:24
Generate matrix plot for confusion matrix with pretty annotations.
plot_confusion_matrix.png
@brennanMKE
brennanMKE / BytesPlayground.swift
Last active December 16, 2023 18:30
Copy bytes from Data with Swift
import Foundation
let size = MemoryLayout<Int16>.stride
let data = Data(bytes: [1, 0, 2, 0, 3, 0]) // little endian for 16-bit values
let int16s = data.withUnsafeBytes { (bytes: UnsafePointer<Int16>) in
Array(UnsafeBufferPointer(start: bytes, count: data.count / size))
}
let length = data.count * MemoryLayout<Int16>.stride
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 16, 2025 12:19
Swift Concurrency Manifesto
@scturtle
scturtle / icp.py
Created March 31, 2017 12:57
Least-Squares Fitting of Two 3-D Point Sets
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from transforms3d import euler
fig = plt.figure()
ax = fig.gca(projection='3d')
p1 = np.zeros((3, 100))
p1[0, :] = np.linspace(1, 3, 100)
@CodaFi
CodaFi / Channel.swift
Created February 27, 2017 22:45
[WIP] Session Types as good as I could get em. Ported from the Rust implementation by Philip Munksgaard.
//
// Channel.swift
// Sessions
//
// Created by Robert Widmann on 2/27/17.
// Copyright © 2017 TypeLift. All rights reserved.
//
enum FakeError : Error {
case Error