Skip to content

Instantly share code, notes, and snippets.

View revskill10's full-sized avatar
🎯
Focusing

Truong Hoang Dung revskill10

🎯
Focusing
  • Freelancer
  • Haiphong, Vietnam
View GitHub Profile
@revskill10
revskill10 / latency.txt
Created February 18, 2024 12:50 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@revskill10
revskill10 / auth.ts
Created February 8, 2024 08:23 — forked from michaelkremenetsky/auth.ts
Supabase Auth Hook
import { Alert } from "react-native";
import * as WebBrowser from "expo-web-browser";
import { useSupabaseClient } from "@supabase/auth-helpers-react";
import { initiateAppleSignIn } from "../utils/auth";
export const useAuth = () => {
const Supabase = useSupabaseClient();
const signInWithPassword = async (

Multiple GitHub accounts (Work vs Personal)

This setup uses some tricks to ensure that the right email/name/ssh-key is used for the right repos without having to think about it ever again.

  • First generate two SSH keys, ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519_work
  • Add one key to your personal account and the other to your work account

.ssh/config

// TODO: make `pages` optional and measure the div when unspecified, this will
// allow more normal document flow and make it easier to do both mobile and
// desktop.
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
@revskill10
revskill10 / fourier.html
Created December 15, 2023 21:04 — forked from kazad/fourier.html
BetterExplained Fourier Example
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script src="//ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<!--
TODO:
@revskill10
revskill10 / EncryptSmallData.md
Created December 11, 2023 07:38 — forked from QingpingMeng/EncryptSmallData.md
Encrypt data using JavaScript in browser with RSA public key generated in C# without library

This is an example to demo how you generate the RSA key pair from server side(.NetCore 3.1) and pass the public key to the client(Browser) for encrypting the data that <= 245 bytes.

RSA-2048 can only support to encrypt up to 245 bytes data.

Generate RSA key pair in C# (.Net Core 3.1):

using var rsaProvider = new RSACng();
// spki is used for browser side encryption
var spki = Convert.ToBase64String(rsaProvider.ExportSubjectPublicKeyInfo());
var encodedPrivateKey = Convert.ToBase64String(rsaProvider.ExportPkcs8PrivateKey());
"use client";
import { cache, unstable_postpone } from "react";
import { preload } from "react-dom";
const loadImage = cache((src: string) => {
return new Promise<void>((resolve, reject) => {
const img = new Image();
img.src = src;
@revskill10
revskill10 / recursive-rsc-stream-inline.ts
Created September 15, 2023 08:24 — forked from jacob-ebey/recursive-rsc-stream-inline.ts
Inline RSC stream with a recursive async component that is streamed as part of the SSR renderToXYZ call.
import * as React from "react";
// @ts-ignore
import * as ReactDOM from "#react-dom-server-implementation";
// @ts-ignore
import * as ReactDOMClient from "#react-server-dom-client-implementation";
export async function fetch(
request: Request,
{
browserEntry,
@revskill10
revskill10 / frontmatter.js
Created September 9, 2023 17:50 — forked from sudkumar/frontmatter.js
MDX Remark plugin to handle frontmatter
// helps us in parsing the frontmatter from text content
const matter = require('gray-matter')
// helps us safely stringigy the frontmatter as a json object
const stringifyObject = require('stringify-object')
// helps us in getting the reading time for a given text
const readingTime = require('reading-time')
// please make sure you have installed these dependencies
// before proceeding further, or remove the require statements
// that you don't use