Skip to content

Instantly share code, notes, and snippets.

@bbengfort
bbengfort / locks.go
Created March 3, 2017 17:40
Synchronized, thread safe buffer using mutex embedding
package main
import (
"flag"
"fmt"
"log"
"sync"
"time"
)
@ExperimentalPagerApi
@Composable
fun WormHorizontalPagerIndicator(
pagerState: PagerState,
modifier: Modifier = Modifier,
activeColor: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current),
inactiveColor: Color = activeColor.copy(ContentAlpha.disabled),
indicatorWidth: Dp = 8.dp,
activeIndicatorWidth: Dp = 25.dp,
indicatorHeight: Dp = indicatorWidth,
@Daninet
Daninet / wav.js
Created July 2, 2022 13:57
Convert AudioBuffer's Float32Array to Wav file format
/** @param sampleRate {number} */
/** @param channelBuffers {Float32Array[]} */
function audioBufferToWav(sampleRate, channelBuffers) {
const totalSamples = channelBuffers[0].length * channelBuffers.length;
const buffer = new ArrayBuffer(44 + totalSamples * 2);
const view = new DataView(buffer);
const writeString = (view, offset, string) => {
for (let i = 0; i < string.length; i++) {
@ar1a
ar1a / comp.cfg
Created October 1, 2023 07:22
Dathost cs2 configs
// >>> DatHost Competitive Config 0.1 <<< //
// Reset from Practice to Competitive
sv_cheats "false" // Disable cheats
mp_ct_default_grenades "" // Spawn CTs without grenades
mp_t_default_grenades "" // Spawn Ts without grenades
sv_showimpacts "0" // Don't show bullet impacts
sv_falldamage_scale "1" // Enable fall damage
sv_full_alltalk "0" // Disable voice chat with anyone
@MattPD
MattPD / analysis.draft.md
Last active May 4, 2024 14:56
Program Analysis Resources (WIP draft)
@matteobertozzi
matteobertozzi / 1_otp.ts
Last active May 4, 2024 14:56
Generate Time Based OTP in Javascript/Typescript, Python, Java
async function generateOneTimePassword(rawKey: Uint8Array, counter: number): Promise<number> {
const data = new DataView(new ArrayBuffer(8));
data.setBigUint64(0, BigInt(Math.floor(counter)), false);
const algo = { name: 'HMAC', hash: 'SHA-1' };
const key = await crypto.subtle.importKey('raw', rawKey, algo, false, ['sign']);
const hmacHash = new Uint8Array(await crypto.subtle.sign(algo, key, data.buffer));
const offset = hmacHash[hmacHash.byteLength - 1] & 0x0f;
const hotp = (hmacHash[offset] & 0x7f) << 24
{ stdenv, autoPatchelfHook }:
stdenv.mkDerivation rec {
pname = "wasmcloud-binaries";
version = "1.0";
src = ./.; # Assuming the binaries are in the current directory
nativeBuildInputs = [ autoPatchelfHook ];
@shalyf
shalyf / vpn_route.md
Last active May 4, 2024 14:54
利用路由表给VPN分流

2020年初因为新冠肺炎爆发,所以在家办公,公司给配置了L2TP的VPN,但是我不想所有流量都走VPN(VPN比较慢而且也节省流量),于是想到用路由表给VPN分流。
具体的方案就是公司内网的流量走VPN,外网流量走默认网关。

我是在macOS上操作的,其他平台应该也差不多。

假设:
公司内网 192.168.10.0/24
家里网络 192.168.1.0/24 你已经配置好VPN并且可以使用了。

@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@mattiaz9
mattiaz9 / blurhashDataURL.ts
Last active May 4, 2024 14:51
Convert blurhash to a base64 DataURL string (no canvas or node-canvas)
import { decode } from "blurhash"
export function blurHashToDataURL(hash: string | undefined): string | undefined {
if (!hash) return undefined
const pixels = decode(hash, 32, 32)
const dataURL = parsePixels(pixels, 32, 32)
return dataURL
}