Skip to content

Instantly share code, notes, and snippets.

@Venryx
Venryx / Fractional Indexing (David Greenspan).md
Last active July 23, 2024 04:30
List of various fractional-indexing schemes, along with language-specific implementations
@Venryx
Venryx / func_types.rs
Created December 21, 2022 21:41
Extensions of the `AsyncFn` trait for use with output-types and variable numbers of arguments (see: https://stackoverflow.com/a/72851012)
use futures::Future;
pub trait AsyncFn_Args0<OutputType>: Fn() -> Self::Future {
type Future: Future<Output = OutputType>;
}
impl<OutputType, F, Fut> AsyncFn_Args0<OutputType> for F
where F: Fn() -> Fut, Fut: Future<Output = OutputType> {
type Future = Fut;
}
@Venryx
Venryx / dynamic_typing.rs
Created July 12, 2022 21:40 — forked from Kimundi/dynamic_typing.rs
Dynamic typing in Rust
use std::unstable::intrinsics::{TyDesc, get_tydesc, forget};
use std::util::Void;
use std::cast::transmute;
///////////////////////////////////////////////////////////////////////////////
// TypeId
///////////////////////////////////////////////////////////////////////////////
/// `TypeId` represents a globally unique identifier for a type
pub struct TypeId {
@Venryx
Venryx / rwlock_tracked.rs
Last active April 18, 2022 05:35
Example of wrapper for RwLock that includes tracking of open lock-guards (for easy debugging of deadlocks)
use std::{sync::{Mutex, Arc}, ops::{Deref, DerefMut}};
use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
/// Wrapper around RwLock, which:
/// 1) Requires that anyone who takes a lock-guard must supply their "name".
/// 2) Provides a way for anyone to get a list of "current lock-guard holders". (without having to take a lock-guard themselves)
pub struct RwLock_Tracked<T> {
l: RwLock<T>,
live_guards: Arc<Mutex<Vec<String>>>,
}
@Venryx
Venryx / coreos_prometheus->Tiltfile
Created August 14, 2021 13:27
coreos_prometheus, modified to work on Windows
# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
def ToLPath(path):
return path.replace("\\", "/").replace("C:/", "/mnt/c/")
def ToWPath(path):
return path.replace("/", "\\").replace("\\mnt\\c\\", "C:\\")
def ListDir(path, recursive = False):
result = []
for file in listdir(ToWPath(path), recursive):
@Venryx
Venryx / Netflix.seek.js
Created December 12, 2020 00:56 — forked from dimapaloskin/Netflix.seek.js
Netflix seek
const videoPlayer = netflix
.appContext
.state
.playerApp
.getAPI()
.videoPlayer;
// Getting player id
const videoPlayer = videoPlayer
.getAllPlayerSessionIds()[0]
@Venryx
Venryx / GearVRInput.ts
Created December 10, 2020 11:30
GearVR controller connection code, using NodeJS's "noble" bluetooth-stack
import {Characteristic, Peripheral, Service} from "@abandonware/noble";
export class ControllerData {
accel: number[];
gyro: number[];
magX: number;
magY: number;
magZ: number;
@Venryx
Venryx / Example.kt
Last active February 17, 2020 23:07
Trigger SonicBomb shakes from your app
// Note: I'm not updating this anymore. For the latest version, see here: https://stackoverflow.com/a/60271550/2441655
val patterns = arrayOf(
"!WLALALALALALALALA;", // default
"!WTRG0TRG0TRG0TRG;", // pulse
"!WPJ0FPV7S1J600;" // sos
// you can add your own patterns by mixing and matching the vibration components
);
// strength is between 0 and 100; pattern follows the format seen above
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Test1</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@Venryx
Venryx / Example.tsx
Last active February 9, 2023 22:36
Using "useImperativeHandle" in a React functional component, with automatic TypeScript typing
import {forwardRef, useImperativeHandle, ForwardRefExoticComponent, RefAttributes, Ref} from "react";
export type Handle<T> = T extends ForwardRefExoticComponent<RefAttributes<infer T2>> ? T2 : never;
export const Parent = (props: {})=> {
let childHandle: Handle<typeof Child>;
return (
<div onClick={()=>childHandle.SayHi()}>
<Child name="Bob" ref={c=>childHandle = c}/>
</div>