Skip to content

Instantly share code, notes, and snippets.

@Benjins
Benjins / aarch64_cache_flush.rs
Created June 10, 2023 15:08
Rust port off __aarch64_sync_cache_range from GCC. Used to flush the cache for a section of memory to ensure dcache/icache coherence. NOTE: I have tested this for my own usage, but I would not recommend it for production
// Code ported from https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/config/aarch64/sync-cache.c;h=41151e861d7fc32a77772b7f09b5f88779cbfd4c#l32
const CTR_IDC_SHIFT : usize = 28;
const CTR_DIC_SHIFT : usize = 29;
unsafe fn __aarch64_sync_cache_range(base : *mut libc::c_void, end : *mut libc::c_void) {
let mut cache_info : usize = 0;
core::arch::asm!("mrs {}, ctr_el0", out(reg) cache_info);
@Benjins
Benjins / check_source.py
Last active July 1, 2023 14:27
Python script that checks if all the files in a crate on crates.io are actually present in the crate's git repository
from urllib.request import urlopen
import json
import sys
import subprocess
import tarfile, io, gzip
# USAGE:
# python3 check_source.py [options] [list of crate names as separate arguments]
# e.g. `python3 check_source.py --shallow-clone instant`
@Benjins
Benjins / dl_food_network.py
Created December 31, 2022 04:08
A quick python script to download videos from the food network site. Written on Dec. 30, 2022 and may not work on all playlists, or for a long time
import sys
import json
from urllib.request import urlopen
import subprocess
FFMPEG = 'ffmpeg'
def DLPath(path, filename):
@Benjins
Benjins / yt_heatmap.py
Created May 27, 2022 01:42
PoC for extracting Youtube player heatmap data from videos and displaying it in ASCII form
# Usage: yt_heatmap.py {VID_ID}
# Example: yt_heatmap.py jNQXAC9IVRw
from urllib.request import urlopen
import sys
import json
from pprint import pprint
@Benjins
Benjins / smm1_course_dl.py
Created March 27, 2021 00:28
Basic, untested script using https://github.com/kinnay/NintendoClients that lets you download SMM1 courses
from nintendo.nex import backend, ranking, datastore, settings
from nintendo.games import SMM
from nintendo import nnas
from anynet import http
import anyio
import logging
logging.basicConfig(level=logging.INFO)
DEVICE_ID = 12345678 #From MCP_GetDeviceId
@Benjins
Benjins / intel_d3d12_gfx_resource_bug_repro_case.cpp
Created February 3, 2021 23:51
Repro case for potential Intel driver bug
//
// This is a test app for a simple D3D12 app that should work, but gets a DXGI_ERROR_DEVICE_HUNG error on Intel. It works on Microsoft's WARP and my Nvidia device
//
// The timeline of events for the repro as I understand it :
// -Create resources for frame 0
// - Draw frame 0
// - Wait on the CPU for the GPU to finish frame 0, so that no outstanding command lists refer to the resources created
// - Begin creating resources for frame 1
// - Delete one of the resources created for frame 0 (all other resources are will leak since we don't care about them)
// - Draw frame 1
@Benjins
Benjins / warp_multithread_execcmdlist.cpp
Created January 23, 2021 18:42
A test case for crash in WARP when using D3D12 and calling ExecuteCommandLists() concurrently
//
// Repro case for multi-threaded WARP access violation
// Does not repro every time, but I see it more than half the time
// Tested on my machine that is running Windows 10 Version 20H2, OS Build 19042.746
// If multiple threads call ExecuteCommandLists() at the same time, then later on an access violation occurs inside WARP
// This occurs even if the calls are to different command queues
// It can be mitigated by using a mutex to prevent simultaneous calls to ExecuteCommandLists
// It does not occur when running with debug validation, however if validation is turned on it does not throw any errors
// It seems to require some amount of resource churn
// It seems to require some variation in the PSO's, and blending enabled
@Benjins
Benjins / repro_warp_rasterization_bug.cpp
Last active January 17, 2021 18:32
Repro case for a bug in D3D12 WARP rasterization
// Repro case for a bug in D3D12 WARP rasterization
// If consevative rasterization is enabled and 2 vertices are at the same position,
// then an out of bounds access occurs
#include <stdio.h>
#include <stdint.h>
#include <vector>
@Benjins
Benjins / Checking if a Twitch Clip is still up
Created November 8, 2020 16:49
This is a PoC shell script to show how to check if a Twitch clip is up or not. Probably not as efficient as could be, but demonstrates what to do.
# curl -d '[{"operationName":"VideoAccessToken_Clip","variables":{"slug":"<PUT_YOUR_TWITCH_CLIP_SLUG_HERE>"},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"9bfcc0177bffc730bd5a5a89005869d2773480cf1738c592143b5173634b7d15"}}}]' -X POST https://gql.twitch.tv/gql -H "Content-Type: text/plain;charset=UTF-8" -H "Client-Id: kimne78kx3ncx6brgo4mv6wki5h1ko" | jq '.[0].data.clip!=null'
# The Client ID is not secret, it's used by any browser session
# Examples:
# Clip that is up
curl --silent -d '[{"operationName":"VideoAccessToken_Clip","variables":{"slug":"CarefulInnocentPelicanDBstyle"},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"9bfcc0177bffc730bd5a5a89005869d2773480cf1738c592143b5173634b7d15"}}}]' -X POST https://gql.twitch.tv/gql -H "Content-Type: text/plain;charset=UTF-8" -H "Client-Id: kimne78kx3ncx6brgo4mv6wki5h1ko" | jq .[0].data.clip!=null
# Clip that is down
curl --silent -d '[{"operationName":"VideoAccessToken_Clip","variables":{"slug":"PlayfulMiniatureGarageTheThing"},"extensio
import sys
if sys.version_info[0] == 3:
from urllib.request import urlopen, Request
else:
from urllib2 import urlopen, Request
import os