Skip to content

Instantly share code, notes, and snippets.

View fzn0x's full-sized avatar
💻
Working from home

Fauzan fzn0x

💻
Working from home
View GitHub Profile
@McSodbrenner
McSodbrenner / README.md
Last active September 29, 2021 18:51
Javascript: Exact Javascript Timeout

This is a more precise version of the native setTimeout(). It uses the same parameters as setTimeout, but adds a third parameter "resolution" which defines how often (in ms) to check for the time that passed.

// alert after 5 seconds with an inaccuracy of 20 milliseconds
var timeout = setExactTimeout(function(){
   alert('done');
}, 5000, 20);

// comment out to show "done"
clearExactTimeout(timeout);
@hibiyasleep
hibiyasleep / GodDrinksJava.java
Last active June 27, 2025 08:19
world.execute(me);
package goddrinksjava;
/**
* The program GodDrinksJava implements an application that
* creates an empty simulated world with no meaning or purpose.
*
* @author momocashew
* @lyrics hibiyasleep
*/
@ljharb
ljharb / array_iteration_thoughts.md
Last active April 15, 2025 03:33
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active July 24, 2025 08:48
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for(...;...;...) or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@mpgn
mpgn / SubtleCrypto.js
Last active May 6, 2024 03:25
SubtleCrypto javascript example
// exemple based on https://github.com/diafygi/webcrypto-examples#rsa-oaep
function importKey() {
return window.crypto.subtle.importKey(
"jwk", //can be "jwk" or "raw"
{ //this is an example jwk key, "raw" would be an ArrayBuffer
kty: "oct",
k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",
alg: "A256GCM",
ext: true,
@Cynosphere
Cynosphere / gameslist.json
Created March 6, 2019 01:48
Discord Verified Games List
This file has been truncated, but you can view the full file.
[
{
"id": "259392830932254721",
"name": "SpeedRunners",
"icon": "cb48279ea90e86fb4f71c709d3236395",
"splash": "94e91cac9509fee1eb80a69b9503878a",
"overlay": false,
"overlayWarn": false,
"overlayCompatibilityHook": false,
@fzn0x
fzn0x / divideAndSort.js
Last active August 16, 2020 04:50
Divide And Sort Javascript
function divideAndSort(value){
const division = value.toString().split("0");
for(let num in division){
if(division[num] == "") {
division.splice(num,1);
}else{
division[num] = division[num].split("").sort().join().replace(/,/g,"");
@nfantone
nfantone / before-shutdown.js
Created September 23, 2020 13:00
Node.js graceful shutdown handler
'use strict';
/**
* @callback BeforeShutdownListener
* @param {string} [signalOrEvent] The exit signal or event name received on the process.
*/
/**
* System signals the app will listen to initiate shutdown.
* @const {string[]}
@broofa
broofa / checkForUndefinedCSSClasses.js
Last active June 22, 2025 08:19
ES module for detecting undefined CSS classes (uses mutation observer to monitor DOM changes). `console.warn()`s undefined classes.
/**
* Sets up a DOM MutationObserver that watches for elements using undefined CSS
* class names. Performance should be pretty good, but it's probably best to
* avoid using this in production.
*
* Usage:
*
* import cssCheck from './checkForUndefinedCSSClasses.js'
*
* // Call before DOM renders (e.g. in <HEAD> or prior to React.render())
@fzn0x
fzn0x / fifo.js
Created May 19, 2021 15:28
FIFO Algorithm in Javascript
// define the queue class
class Queue {
constructor(...elements) {
// set array as value of construct args
this.elements = [...elements];
}
push(...args) {
// push arguments to this.elements
return this.elements.push(...args);