Skip to content

Instantly share code, notes, and snippets.

View brandonasuncion's full-sized avatar

Brandon Asuncion brandonasuncion

View GitHub Profile
@brandonasuncion
brandonasuncion / HookedSession.swift
Created June 20, 2025 16:48 — forked from buranmert/HookedSession.swift
Adding hooks to URLSession
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/
import Foundation
public extension URLSession {
internal typealias RequestInterceptor = HookedSession.RequestInterceptor
@brandonasuncion
brandonasuncion / ISMCTS.py
Created March 23, 2025 18:08 — forked from kjlubick/ISMCTS.py
An example of Information Set Monte Carlo Tree Search from http://www.aifactory.co.uk/newsletter/2013_01_reduce_burden.htm
# This is a very simple Python 2.7 implementation of the Information Set Monte Carlo Tree Search algorithm.
# The function ISMCTS(rootstate, itermax, verbose = False) is towards the bottom of the code.
# It aims to have the clearest and simplest possible code, and for the sake of clarity, the code
# is orders of magnitude less efficient than it could be made, particularly by using a
# state.GetRandomMove() or state.DoRandomRollout() function.
#
# An example GameState classes for Knockout Whist is included to give some idea of how you
# can write your own GameState to use ISMCTS in your hidden information game.
#
# Written by Peter Cowling, Edward Powley, Daniel Whitehouse (University of York, UK) September 2012 - August 2013.
@brandonasuncion
brandonasuncion / branchlessBinarySearch.swift
Created August 15, 2023 21:05
fast branchless binary search that uses the cmov instruction in Swift
// branchless binary search
// https://news.ycombinator.com/item?id=37086796
func binarySearch<T: Comparable>(_ value: T, in values: UnsafePointer<T>, length: Int) -> Int {
let values = Int(bitPattern: values)
var first = values
var length = length
while length != 0 {
let half = length &>> 1
if UnsafePointer<T>(bitPattern: first).unsafelyUnwrapped[half] < value {
@resultBuilder
struct MenuItemsBuilder {
static func buildBlock(_ components: NSMenuItem...) -> [NSMenuItem] {
components
}
}
extension NSMenu {
convenience init(title: String? = nil, @MenuItemsBuilder menuItems: () -> [NSMenuItem]) {
self.init()
@brandonasuncion
brandonasuncion / minimalSwiftUI-macOS11+.swift
Last active August 30, 2024 20:56
minimal macOS SwiftUI app from complete scratch
import SwiftUI
class AppDelegate: NSObject, NSApplicationDelegate { }
@main
struct CustomApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
# https://github.com/uBlockOrigin/uAssets/pull/3517
twitch-videoad.js application/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
var realFetch = window.fetch;
window.fetch = function(input, init) {
if ( arguments.length >= 2 && typeof input === 'string' && input.includes('/access_token') ) {
var url = new URL(arguments[0]);
url.searchParams.forEach(function(value, key) {
url.searchParams.delete(key);
(function() {
console.log("Creating compressor");
let context = new AudioContext();
let compressor = context.createDynamicsCompressor();
compressor.threshold.value = -50;
compressor.knee.value = 40;
compressor.ratio.value = 12;
@brandonasuncion
brandonasuncion / SquircleTest.swift
Created April 6, 2019 20:41
Example of creating "Squircles", as seen in Apple's iOS interface
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
self.view = view
@brandonasuncion
brandonasuncion / Custom NSLayoutManager.swift
Created March 29, 2019 10:33
Using a custom NSLayoutManager
let textStorage = NSTextStorage()
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: bounds.size)
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)
let textView = UITextView(frame: bounds, textContainer: textContainer)
class CustomUrlProtocol: URLProtocol {
static var requestCount = 0
open override class func canInit(with request: URLRequest) -> Bool {
guard let url = request.url else { return false }
requestCount = requestCount + 1
print("NSURLREQUEST: \(request)")