Skip to content

Instantly share code, notes, and snippets.

View hunghg255's full-sized avatar
:octocat:
Make Frontend Better πŸ‘¨β€πŸ’»

Hung Hoang hunghg255

:octocat:
Make Frontend Better πŸ‘¨β€πŸ’»
View GitHub Profile
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
// only works on react 18
import { useSyncExternalStore } from "react";
export const useColorScheme = () => {
const scheme = useSyncExternalStore(
subscribe,
getSnapshot,
getServerSnapshot
);
[
{ "text": "0️⃣", "name": "0", "keyword": ":0:" },
{ "text": "1️⃣", "name": "1", "keyword": ":1:" },
{ "text": "πŸ”Ÿ", "name": "10", "keyword": ":10:" },
{ "text": "πŸ’―", "name": "100", "keyword": ":100:" },
{ "text": "πŸ₯‡", "name": "1st Place Medal", "keyword": ":1st-place-medal:" },
{ "text": "2️⃣", "name": "2", "keyword": ":2:" },
{ "text": "πŸ₯ˆ", "name": "2nd Place Medal", "keyword": "2nd-place-medal:" },
{ "text": "3️⃣", "name": "3", "keyword": ":3:" },
{ "text": "πŸ₯‰", "name": "3rd Place Medal", "keyword": ":3rd-place-medal:" },
@hunghg255
hunghg255 / build.js
Created April 30, 2023 11:21 — forked from fabiospampinato/build.js
Fast building + watching + starting + restarting. AKA how to throw TypeScript in the garbage bin for anything other than type-checking.
/* IMPORT */
const esbuild = require ( 'esbuild' );
const {nodeExternalsPlugin} = require ( 'esbuild-node-externals' );
const monex = require ( 'monex' );
const path = require ( 'path' );
const {color, parseArgv} = require ( 'specialist' );
const Watcher = require ( 'watcher' );
@hunghg255
hunghg255 / fastest_escape_html.js
Created April 30, 2023 11:19 — forked from fabiospampinato/fastest_escape_html.js
The fastest way to escape HTML strings known to me~~n~~, if you need to do so with JS and you are inside a browser.
// Can you make this faster? Ping me.
const escapeHtml = (function () {
const serializer = new XMLSerializer ();
const attr = document.createAttribute ( 'attr' );
const re = /[&<>"]/;
return function escapeHtml ( str ) {
if ( !re.test ( str ) ) return str;
attr.value = str;
return serializer.serializeToString ( attr );
@hunghg255
hunghg255 / cursed_base64.ts
Created April 30, 2023 11:18 — forked from fabiospampinato/cursed_base64.ts
Cursed base64 encoder.
// It's the fastest pure-JS base64 encoder (that doesn't account for padding though) that I've found.
// It's cursed because it takes ~2s to startup and 16MB of memory πŸ˜‚
const encoder = new TextEncoder ();
const lookup = (() => {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split ( '' );
const lookup = new Array ( 2 ** 24 );
const mask1 = 0b11111100_00000000_00000000;
const mask2 = 0b00000011_11110000_00000000;
@hunghg255
hunghg255 / xor.js
Created April 30, 2023 11:17 — forked from fabiospampinato/xor.js
A little NN trained to learn XOR
function XOR(d){const a={0:1,1:1,7:.05,2:2,3:-2.8,4:-.09,5:2,6:-4.8,8:.04,26:5.7,14:.9,9:10,10:4.5,11:3.3,12:6.8,13:-5.6,15:.01,27:-7.9,21:.9,16:3.8,17:6.4,18:-1.1,19:5,20:2.5,22:0,28:4.7,29:.08,23:2.2,24:-2.3,25:.5,30:.08};a[0]=d[0],a[1]=d[1],a[2]=a[3],a[3]=a[4],a[3]+=a[0]*a[5],a[3]+=a[1]*a[6],a[7]=1/(1+Math.exp(-a[3])),a[8]=a[7]*(1-a[7]),a[9]=a[10],a[10]=a[11],a[10]+=a[0]*a[12],a[10]+=a[1]*a[13],a[14]=1/(1+Math.exp(-a[10])),a[15]=a[14]*(1-a[14]),a[16]=a[17],a[17]=a[18],a[17]+=a[0]*a[19],a[17]+=a[1]*a[20],a[21]=1/(1+Math.exp(-a[17])),a[22]=a[21]*(1-a[21]),a[23]=a[24],a[24]=a[25],a[24]+=a[7]*a[26],a[24]+=a[14]*a[27],a[24]+=a[21]*a[28],a[29]=1/(1+Math.exp(-a[24])),a[30]=a[29]*(1-a[29]);var b=[];return b[0]=a[29],b}
console.log ( XOR ([ 0, 0 ]) );
console.log ( XOR ([ 0, 1 ]) );
console.log ( XOR ([ 1, 0 ]) );
console.log ( XOR ([ 1, 1 ]) );
@hunghg255
hunghg255 / xor.js
Created April 30, 2023 11:14 — forked from fabiospampinato/xor.js
A 99% precise neural network that learned the XOR function. There's about a 1kb fixed overhead, the model is ~just those two hex strings.
function xor(t){const _=xor;return _._||(_._=!0,_.p=(e,t)=>{const r=[];for(let n=0,c=e.length;n<c;n++){r[n]=[];for(let c=0,a=t[0].length;c<a;c++){let a=0;for(let r=0,l=e[0].length;r<l;r++)a+=e[n][r]*t[r][c];r[n][c]=a}}return r},_.m=(e,t)=>{const r=new Array(e.length);for(let n=0,c=e.length;n<c;n++){r[n]=new Array(e[n].length);for(let c=0,a=e[n].length;c<a;c++)r[n][c]=t(e[n][c],n,c)}return r},_.d=(e,t)=>{const r="float64"===t?Float64Array:Float32Array;return e.split("|").map((e=>{const t=e.length/2,n=r.BYTES_PER_ELEMENT,c=new ArrayBuffer(t+(t%n?n-t%n:0)),a=new Uint8Array(c),l=new r(c);for(let t=0,r=e.length;t<r;t+=2)a[t/2]=parseInt(e.slice(t,t+2),16);return Array.from(l).slice(0,t)}))},_.a0=(e,t)=>{const r=1/(1+Math.exp(-e));return t?r*(1-r):r},_.a1=(e,t)=>{const r=1/(1+Math.exp(-e));return t?r*(1-r):r},_.w0=_.d("cf70bbc08a93cfc043c6bb40c6ee8240|de3eb8c06b4a4e4080843bc0480001c1"),_.w1=_.d("c98b9fc1|eb82af40|dd0cbac0|e8d02d41")),_.m(_.p(_.m(_.p([t],_.w0),_.a0),_.w1),_.a1)[0][0]}
console.log(xor([0,0]));
consol
@hunghg255
hunghg255 / fast_css_reset.css
Created April 30, 2023 11:13 — forked from fabiospampinato/fast_css_reset.css
The fastest CSS reset possible
:where(abbr), :where(address), :where(area), :where(article), :where(aside), :where(audio), :where(b), :where(base), :where(bdi), :where(bdo), :where(big), :where(blockquote), :where(body), :where(br), :where(caption), :where(cite), :where(code), :where(col), :where(colgroup), :where(data), :where(datalist), :where(dd), :where(del), :where(details), :where(dfn), :where(dialog), :where(dl), :where(dt), :where(em), :where(embed), :where(fieldset), :where(figcaption), :where(figure), :where(footer), :where(form), :where(h1), :where(h2), :where(h3), :where(h4), :where(h5), :where(h6), :where(head), :where(header), :where(hgroup), :where(hr), :where(i), :where(input), :where(ins), :where(kbd), :where(keygen), :where(label), :where(legend), :where(li), :where(link), :where(main), :where(map), :where(mark), :where(menu), :where(menuitem), :where(meta), :where(meter), :where(nav), :where(object), :where(ol), :where(optgroup), :where(option), :where(output), :where(param), :where(picture), :where(pre), :where(progress
/**
* ℹ️ Topic: Use Proxy() to Set validation to javascript Object
* πŸ“¨ Contact for personalized training: [email protected] πŸ‘ˆ
*/
const userValidator = {
set(object, prop, value) {
const validProps = ['name', 'email'];
if (!validProps.includes(prop)) {