Skip to content

Instantly share code, notes, and snippets.

@arkatsy
arkatsy / zustand-internals.jsx
Last active April 28, 2024 09:47
How zustand works internally
import { useSyncExternalStore } from "react";
// For more on the useSyncExternalStore hook, see https://react.dev/reference/react/useSyncExternalStore
// The code is almost identical to the source code of zustand, without types and some features stripped out.
// Check the links to see the references in the source code.
// The links are referencing the v5 of the library. If you plan on reading the source code yourself v5 is the best way to start.
// The current v4 version contains lot of deprecated code and extra stuff that makes it hard to reason about if you're new to this.
// https://github.com/pmndrs/zustand/blob/fe47d3e6c6671dbfb9856fda52cb5a3a855d97a6/src/vanilla.ts#L57-L94
function createStore(createState) {
@shinchiro
shinchiro / encode.bat
Last active April 28, 2024 09:42
My one-drag encode using CLI
@echo OFF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Copyright (C) 2017-2019 miniencodes.nl :::
:: :::
:: Author: Shinchiro :::
:: :::
:: Purpose: To re-encode anime to small size with little effort, without GUI. :::
:: WARNING: DON'T PUT THIS SCRIPT IN SAME FOLDER AS INPUT FILE, IT WILL OVERWRITE THE INPUT FILE. :::
:: The lock file is needed to force only one encoding at same
@nicknapoli82
nicknapoli82 / cs50_Tideman_cycle-explanation.md
Last active April 28, 2024 09:40
My attempt at clarifying how cycles work for the Tideman algorithm

A Way to Look at Tideman Lock Pairs

I've observed that there is a little bit of a disconnect in understanding what it is that needs to be done to properly implement the lock_pairs function for cs50 Tideman. The goal of this little write-up is simply an attempt at explaining what the problem actually is, and why a cycle imposes a problem.

First:
If you are unfamiliar with the actual problem, or have not read through the entire cs50 Tideman problem description. Then I think you should start there.
cs50 Tideman

Second:
This little write-up is only narrowing in on the idea of cycles, and a way to think about what a cycle is and determine if locking a pair in the pairs array would create that cycle. This does not talk about any other part of the Tideman problem.

@kou-yeung
kou-yeung / FileSystem.cs
Created May 8, 2020 06:36
Unity WebGL FileSystem Sync
using AOT;
using System;
using System.Collections.Generic;
namespace WebGL
{
public static class FileSystem
{
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
@barelyhuman
barelyhuman / extensions.json
Last active April 28, 2024 09:38
Simple but Minimal
[
{
"id": "a-h.templ",
"name": "templ",
"publisher": "a-h",
"version": "0.0.24"
},
{
"id": "adpyke.codesnap",
"name": "codesnap",
@miranda-zhang
miranda-zhang / linux.md
Last active April 28, 2024 09:32
Linux Command Cheat Sheet, Ubuntu, CentOS

Linux Command Cheatsheet

Linux Keyboard shortcuts

open terminal: Ctrl+Alt+T

Ctrl + C is used to kill a process with signal SIGINT , in other words it is a polite kill .

Ctrl + Z is used to suspend a process by sending it the signal SIGTSTP , which is like a sleep signal, that can be undone and the process can be resumed again.

@AlmostEfficient
AlmostEfficient / load.js
Last active April 28, 2024 09:31
Load a Solana keypair from a .env file as a byte array
// "@solana/web3.js": "^1.87.6",
import { Connection, Keypair, clusterApiUrl } from '@solana/web3.js';
import dotenv from 'dotenv';
dotenv.config();
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
const payerSecretKey = JSON.parse(process.env.PAYER);
const payer = Keypair.fromSecretKey(Uint8Array.from(payerSecretKey));
@alksily
alksily / NoiseGenerator.java
Last active April 28, 2024 09:31
Perlin Noise (1D, 2D, 3D noise generator)
package main.ru.aengine.noise;
import java.util.Random;
public class NoiseGenerator {
private double seed;
private long default_size;
private int[] p;
private int[] permutation;
@svet-b
svet-b / bigdashboard_output.pdf
Last active April 28, 2024 09:30
PDF export of Grafana dashboard using puppeteer
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MrWeez
MrWeez / cloudflare-tlsa-auto-updater.sh
Last active April 28, 2024 09:29
This script allows you to automatically update the TLSA record via Cloudflare API. This is useful when using Let's Encrypt certificates to avoid manually updating records after reissuing the certificate.
#!/bin/bash
# Variables
API_KEY="CHANGE_ME" # Cloudflare API key
API_TOKEN="CHANGE_ME" # Cloudflare API token
API_EMAIL="CHANGE_ME" # Cloudflare account email
ZONE_ID="CHANGE_ME" # ID of the domain
DNS_RECORD_NAMES=("_25._tcp.domain.com" "_110._tcp.domain.com" "_143._tcp.domain.com" "_465._tcp.domain.com" "_587._tcp.domain.com" "_993._tcp.domain.com" "_995._tcp.domain.com") # List of TLSA records
DOMAIN="domain.com" # Your domain
SSL_CERTIFICATE="/path/to/cert.pem" # Path to cert file