Skip to content

Instantly share code, notes, and snippets.

View EricRabil's full-sized avatar

Eric Rabil EricRabil

View GitHub Profile
@EricRabil
EricRabil / DispatchQueue+Current.swift
Created April 27, 2022 16:29
Get current dispatch queue in Swift
extension DispatchQueue {
private static let dispatch_get_current_queue = dlsym(dlopen(nil, RTLD_GLOBAL), "dispatch_get_current_queue")
static var current: DispatchQueue {
dispatch_get_current_queue.map {
unsafeBitCast($0, to: (@convention(c) () -> Unmanaged<DispatchQueue>).self)().takeUnretainedValue()
} ?? .global(qos: .background)
}
}

You'll need to get an access token first. The easiest way to do this is:

  1. Open Chrome
  2. Open devtools
  3. Go to the network inspector, and in the filter type "get_access_token"
  4. Navigate to https://open.spotify.com in that tab
  5. Click on the network request that shows up, then copy the entirety of the cookie header in the Request headers.

These access tokens expire, but the cookies appear to expire less frequently or not at all, so we will hold onto the cookies.

Whenever you need to get an access token, make a request to https://open.spotify.com/get_access_token?reason=transport&amp;productType=web_player with the cookie header we extracted previously.

@EricRabil
EricRabil / entitlements.plist
Created July 19, 2021 20:15
system.login.console authorization in Swift
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
entitlements.plist
kkkkkkk
Created by Eric Rabil on 7/18/21.
Copyright (c) 2021 ___ORGANIZATIONNAME___. All rights reserved.
-->
<plist version="1.0">
@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
@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 / 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 / objc-internals-minimal.h
Created October 14, 2021 23:53
Minimal derivative of objc internal headers for interacting with the runtime
#include <atomic>
#include <cstddef> // for nullptr_t
#include <stdint.h>
#include <assert.h>
#include <iterator>
#include <functional>
// MARK: - Defines
#if __LP64__
@_transparent private func CFDictionaryGetValue(_ dictionary: CFDictionary, _ key: CFString) -> UnsafeRawPointer? {
CFDictionaryGetValue(dictionary, Unmanaged.passUnretained(key).toOpaque())
}
@_transparent private func CFDictionaryUnwrap(_ type: CFTypeRef) -> CFDictionary? {
guard CFGetTypeID(type) == CFDictionaryGetTypeID() else {
return nil
}
return unsafeBitCast(type, to: CFDictionary.self)
}
@EricRabil
EricRabil / XCTHarness.swift
Last active August 1, 2024 08:32
XCTest doing absolutely nothing? Lack of documentation driving you insane? Avoiding a DTS ticket? Here's a Swift class that forcibly bootstraps XCTest when running inside of a test host and XCTest is not starting itself.
public class XCTHarness {
private typealias XCTestMainType = @convention(c) (_ something: AnyObject?) -> ()
private static func dlsymcast<T>(_ handle: UnsafeMutableRawPointer!, _ symbol: UnsafePointer<CChar>) -> T! {
dlsym(handle, symbol).map {
if T.self is AnyObject.Type {
return $0 as! T
} else {
return unsafeBitCast($0, to: T.self)
}
@EricRabil
EricRabil / DeferredFuture.swift
Created July 19, 2021 20:19
Swift Combine – Future vs. DeferredFuture
//
// main.swift
//
// Created by Eric Rabil on 7/19/21.
//
import Foundation
import Combine
public class DeferredFuture<Output, Failure> : Publisher where Failure : Error {