Skip to content

Instantly share code, notes, and snippets.

View omranjamal's full-sized avatar
🎯
Focusing

Omran Jamal omranjamal

🎯
Focusing
View GitHub Profile
@omranjamal
omranjamal / sync-atom.mts
Last active October 18, 2024 18:23
Locks, Semaphonres, Events & Barriers using a powerful primitive to build synchronization primitives
function atom<T>(initialState: T) {
let state = initialState;
const pendingUpdates = new Map<Function, Function>();
const blocked = new Map<Function, Function>();
function update(predicate: (state: T) => boolean, nextState: T | ((state: T) => T)): Promise<T> {
function attemptToApplyPendingUpdates() {
for (const [predicate, update] of pendingUpdates) {
if (predicate(state)) {
@omranjamal
omranjamal / jsonx.tsx
Created June 8, 2024 08:28
Building JSON structures with JSX
/** @jsx jsonx */
/** @jsxFrag null */
const property = (key: string | number, ...children: any) =>
jsonxobject({
[key]: jsonx(null, undefined, ...children),
});
class JSONXObject extends Object {}
const jsonxobject = (obj: any) => Object.assign(new JSONXObject(), obj);
export function unicodeCodePointsToString(codePoints) {
return codePoints
.replace(/[^0-9A-F]/gi, ' ')
.replace(/\s+/g, ' ')
.trim()
.split(' ')
.map((code) => parseInt(code, 16))
.filter((code) => !isNaN(code))
.map((code) => {
try {
#!/usr/bin/env bash
while :
do
echo "Attempting to connect to $1:$2 ..."
if exec 7<> /dev/tcp/$1/$2 ; then
echo "Connection Established to $1:$2"
while :
function toDecimal(mantissa_str, exponent_str) {
const [sign_str, sig_str] = mantissa_str.split('.')
const sign = sign_str === "1" ? -1 : 0
const [ex_sign_str, ...ex_sig_arr] = exponent_str.split("")
const ex_sign = ex_sign_str === '1' ? -1 * Math.pow(2, exponent_str.length - 1) : 0
const ex_summed = ex_sign + ex_sig_arr.reverse().map(
(bit, i) => bit === '1' ? Math.pow(2, i) : 0
).reduce((a, b) => a + b, 0)
@omranjamal
omranjamal / fuck-shiritori.js
Created July 20, 2018 14:39
Destroys any and every oponent in Shiritori.
const data = {
"i": [
"immunoelectrophoresis",
"indistinguishability",
"internationalisation",
"internationalization",
"incomprehensibility",
"incontrovertibility",
"interdenominational",