Skip to content

Instantly share code, notes, and snippets.

@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
}
@wojteklu
wojteklu / clean_code.md
Last active May 4, 2024 14:50
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@AndruC
AndruC / Roll20 Macros.md
Last active May 4, 2024 14:50
Macros that I use to improve my D&D games

Macro Must-Haves

These are my must-have macros for running games online. I make full use of the compendium, which gives these macros access to common actions and rolls, saving me time.

Remember to add /w gm or @{selected|wtype} to hide sensitive info from your players. WTYPE is an attribute used in the 5th Edition OGL character sheet, a prerequisite for most of these.

Here's what my bar looks like.

Macro Quickbar

@munrocket
munrocket / wgsl_noise.md
Last active May 4, 2024 14:50
WGSL Noise Algorithms

WGSL Noise Algorithms

Operator % has changed, probably current code with it need a fix

Good and fast integer hash

// https://www.pcg-random.org/
fn pcg(n: u32) -> u32 {
    var h = n * 747796405u + 2891336453u;
    h = ((h >> ((h >> 28u) + 4u)) ^ h) * 277803737u;
@jclosure
jclosure / docker_reverting
Created June 5, 2015 08:07
How to revert a docker container to a previous commit
$ docker history imagename
IMAGE CREATED CREATED BY SIZE
f770fc671f11 12 seconds ago apt-get install -y curl 21.3 MB
28445c70c2b3 39 seconds ago apt-get install ping 11.57 MB
8dbd9e392a96 7 months ago 131.5 MB
$ docker tag 2844 imagename # <-- that's the secret right there
$ docker history imagename
IMAGE CREATED CREATED BY SIZE