Skip to content

Instantly share code, notes, and snippets.

View guest271314's full-sized avatar
💭
Fix WontFix

guest271314

💭
Fix WontFix
View GitHub Profile
@vitaly-t
vitaly-t / chain-arrays.ts
Last active September 29, 2024 19:47
Logically concatenates arrays
/**
* Iterable arrays chain, extended for "length" and "at" accessor.
*/
export interface IArraysChain<T> extends RelativeIndexable<T>, Iterable<T> {
readonly length: number;
}
export function chainArrays(): IArraysChain<unknown>;
export function chainArrays<A>(a: ArrayLike<A>): IArraysChain<A>;
export function chainArrays<A, B>(a: ArrayLike<A>, b: ArrayLike<B>): IArraysChain<A | B>;
@jimmywarting
jimmywarting / cjs-in-esm.md
Last active January 27, 2024 18:02
using cjs in esm runtime (NodeJS)
@voluntas
voluntas / h2c.go
Created August 22, 2023 00:55
HTTP/2 over TCP
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
@yashraj1120
yashraj1120 / server.c
Created March 26, 2023 19:07
simple response server
// webserver.c
// https://bruinsslot.jp/post/simple-http-webserver-in-c/
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/socket.h>
@Ustice
Ustice / Boolean Algebra for Programmers in a Nutshell.md
Last active January 9, 2024 20:16
Boolean Algebra in a nutshell for JS/TS programmers

Boolean Algebra in a nutshell for JS/TS programmers

There are a lot of strategies that you will hear about in the Javascript community for keeping your conditionals from becoming a tangled mess. This isn't like them. This is someting different. MATH! Boolean Algebra to be exact. I use it all the time to simplify complex conditionals. There are two things that you need to know: de Morgan's Theorem, and Karnaugh (pronounced CAR-no) Maps. (Don't worry, there is no test)

de Morgan's Theorem

De Morgan's Theorem is great distributing nots (!), and for when you want to convert an && to an ||, or back. This is it:

 !(A &amp;&amp; B) = !A || !B
@lukaslihotzki
lukaslihotzki / polyfill_worklet_import.js
Last active October 1, 2022 14:02
Polyfill to support "import" in worklet scripts in Firefox
const wrappedFunc = Worklet.prototype.addModule;
Worklet.prototype.addModule = async function(url) {
try {
return await wrappedFunc.call(this, url);
} catch (e) {
if (e.name != 'AbortError') {
throw e;
}
// assume error is caused by https://bugzilla.mozilla.org/show_bug.cgi?id=1572644
@dfkaye
dfkaye / Hash.js
Created March 6, 2022 02:54
Use crypto subtle digest to create hash hex string
// 5 March 2022
// Using window.crypto.subtle.digest()
// @param "sha-256" or other algorithm
// @param DataView with ArrayBuffer or just ArrayBuffer
// Not my own.
// Copy+paste+modified from
// https://stackoverflow.com/a/68545495

Originally posted at https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/august/javascript-cryptography-considered-harmful/

Javascript Cryptography Considered Harmful

WHAT DO YOU MEAN, "JAVASCRIPT CRYPTOGRAPHY"?

We mean attempts to implement security features in browsers using cryptographic algoritms implemented in whole or in part in Javascript.

You may now be asking yourself, "What about Node.js? What about non-browser Javascript?". Non-browser Javascript cryptography is perilous, but not doomed. For the rest of this document, we're referring to browser Javascript when we discuss Javascript cryptography.

@gildas-lormeau
gildas-lormeau / unzip
Created September 12, 2021 20:24
Basic unzip implementation based on zip.js and Deno
#!/bin/sh
~/.deno/bin/deno run --allow-net --allow-write --allow-read --unstable unzip.js "$@"
@robertrypula
robertrypula / web-socket-server.js
Created February 11, 2021 20:50
WebSocket - binary broadcast example (pure NodeJs implementation without any dependency)
// Copyright (c) 2019-2021 Robert Rypuła - https://github.com/robertrypula
/*
+--------------------------------------------------+
| Binary broadcast WebSocket server in pure NodeJs |
+--------------------------------------------------+
Based on great article created by Srushtika Neelakantam:
https://medium.com/hackernoon/implementing-a-websocket-server-with-node-js-d9b78ec5ffa8