Skip to content

Instantly share code, notes, and snippets.

View EricRabil's full-sized avatar
🤕
abusing the swift runtime

Eric Rabil EricRabil

🤕
abusing the swift runtime
View GitHub Profile
@EricRabil
EricRabil / AnoymouslyCodable.swift
Last active August 19, 2021 14:43
Write anonymous encoding and decoding functions that can convert any arbitrary values back and forth
import Foundation
// somewhere in a different module
struct MyArbitraryUncodableStruct {
let aBool: Bool
let aInt: Int
}
extension JSONEncoder {
private class CustomEncodable: Encodable {
@EricRabil
EricRabil / JSContext+Completion.swift
Created August 13, 2021 00:16
Completion suggestions for JavaScriptCore JSContext
//
// JSContext+Completion.swift
// BarcelonaJS
//
// Created by Eric Rabil on 8/12/21.
// Copyright © 2021 Eric Rabil. All rights reserved.
//
// Shamelessly ported from https://github.com/nodejs/node/blob/master/lib/repl.js
//
@EricRabil
EricRabil / Swiftygen.js
Created August 9, 2021 22:27
codegen a codable extension for enums with associated types (biased af)
const fs = require("fs");
function toChunk(lines) {
return lines.join("\n ");
}
function arg(key) {
const index = process.argv.indexOf(key);
if (index === -1) return null;
return process.argv[index + 1];
@EricRabil
EricRabil / enable-command-line-tools.py
Created August 5, 2021 13:36
build command line tools for ios. fuck you apple
# Excerpt from https://svn.webkit.org/repository/webkit/trunk/Tools/Scripts/configure-xcode-for-embedded-development
#!/usr/bin/env python3
#
# Copyright (C) 2014-2020 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
@EricRabil
EricRabil / Promise.swift
Created July 30, 2021 02:08
god dammit apple you suk
import Foundation
public enum PendingPromise<Output, Failure: Error>: Equatable {
public static func == (lhs: PendingPromise<Output, Failure>, rhs: PendingPromise<Output, Failure>) -> Bool {
switch lhs {
case .pending:
switch rhs {
case .pending:
return true
default:
@EricRabil
EricRabil / thing.md
Created July 28, 2021 18:45
Coding things I need in my life now
  • CLI tool for quickly entering all of the products directories of Xcode
  • Inquirer.js for swift
@EricRabil
EricRabil / SQLiteExpansion.swift
Created July 21, 2021 19:26
SQLite.swift expansion
import Foundation
import SQLite
protocol TableActionable {
associatedtype SelfType
@discardableResult
func insert(db: Connection) throws -> SelfType
@discardableResult
func update(db: Connection) throws -> SelfType
@EricRabil
EricRabil / withUnsafeMutablePointerConstructing.swift
Created July 21, 2021 19:25
withUnsafeMutablePointer for safe allocation interoperability
/**
Helper function for efficiently initializing a value based on a pointer
- Parameter type: the type of value the pointers value will be cast to
- Parameter closure: block of code that will handle the pointer
- Returns: tuple of (value the pointer was given, return type of closure)
*/
func withUnsafeMutablePointer<T, R>(ofType type: T.Type, _ closure: (UnsafeMutablePointer<T>) -> R) -> (T?, R) {
let ptr = UnsafeMutablePointer<T>.allocate(capacity: 1)
@EricRabil
EricRabil / thing.md
Created July 21, 2021 19:03
compilation of official apple bindings to private frameworks ❤️
@EricRabil
EricRabil / MachClient.swift
Last active August 7, 2024 04:43
mach ipc via exception ports
//
// MachClient.swift
//
// Created by Eric Rabil on 7/7/21.
//
import Foundation
public let kMachIPCGreet: UInt32 = 4