Skip to content

Instantly share code, notes, and snippets.

View fasiha's full-sized avatar
💭
🧘‍♂️🐻

Ahmed Fasih fasiha

💭
🧘‍♂️🐻
View GitHub Profile
@fasiha
fasiha / workQueue.ts
Last active June 13, 2024 05:02
Node.js, very simple work queue
export type Task = () => Promise<void>;
export function addTask(doTask: Task) {
TASKS.push(doTask);
kickOffWorkers(MAX_WORKERS);
}
const TASKS: Task[] = [];
const workerPool: number[] = []; // "number" but really doesn't matter, this is just to keep track of how many parallel workers we already have
const MAX_WORKERS = 3;
@fasiha
fasiha / so.py
Last active January 19, 2024 23:30
Fitting my Stack Overflow points history to specific sections of time. Growth from early 2020 to mid-2021 was solid, slowed by 30-ish percent by mid-2022, then dropped 50% since mid-2022 till now (early 2024). See https://octodon.social/@22/111682452808811056
import numpy as np
from datetime import datetime, timedelta
import pylab as plt
from numpy.polynomial import Polynomial
plt.style.use("ggplot")
plt.ion()
# this is the min/max points in my line chart on my profile page
rawMin = 4.9e3
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
plt.ion()
# URL for the data
url = "https://data.bls.gov/timeseries/JTS510000000000000LDL"
# Creating a date range from 2001 to 2023
@fasiha
fasiha / reddit.md
Last active January 5, 2024 20:19
"[OC] 2020 electoral map if only ____ voted. Breakdown by each major demographics." mirror
@fasiha
fasiha / fftUpsample.py
Created September 7, 2023 05:56
Demo code on how to use FFT to sinc-interpolate (upsample). (You probably should just use scipy.signal.resample which will filter and window the signal to avoid the ringing that this FFT-only method invariably yields, unless you know what you're doing.)
import numpy as np
from numpy.fft import fft, ifft
def fftUpsample(a, factor):
a_f = fft(a)
n = len(a)
assert n % 2 == 0, "odd case is harder"
padded = np.zeros(int(len(a) * factor), dtype=a_f.dtype)
padded[:n // 2 + 1] = a_f[:n // 2 + 1]
@fasiha
fasiha / exif.md
Created August 12, 2023 12:37
Exif and Artwork Content Description example
@fasiha
fasiha / horimiya.csv
Last active August 23, 2023 04:46
Onomatopoeia in Horimiya (Yen Press, Taylor Engel (translator) and Alexis Eckerman (letterer)). See https://octodon.social/@22/110658625756122629
Volume Page Kana Transcript Translation Note See also JMDict
1 7 ハンッ Han clap hands
7 カリ kari scrit pencil on paper
8 ほすん posun paff placing eraser in someone’s hand
8 とぼ tobo plod walking steps とぼとぼ
9 パァァ paaaa beam smile
10 バンッ ban wham door closing ? バンバン
10 きゅ kyu clip hair clip closing きゅっと
10 ザッ za shhk vacuum attachment attaching? ザーザー
10 ズゴゴゴオオオ zupogogoooo vreeeen vacuuming
Single Women Single Men Men/Women (%)
Average annual expenditures $36,061 $38,748 107.5%
Food 4,299 4,871 113.3%
Food at home 2,557 2,447 95.7%
Cereals and bakery products 322 288 89.4%
Cereals and cereal products 89 86 96.6%
Bakery products 233 202 86.7%
Meats, poultry, fish, and eggs 468 528 112.8%
Beef 110 135 122.7%

Circular reasoning

An excerpt from Duncan Watts, Everything Is Obvious: when you know the answer* (2012, chapter 3)

Although it is rarely presented as such, this kind of circular reasoning—X succeeded because X had the attributes of X—pervades commonsense explanations for why some things succeed and others fail. For example, an article on the success of the Harry Potter books explained it this way:

“A Cinderella plot set in a novel type of boarding school peopled by jolly pupils already has a lot going for it. Add in some easy stereotypes illustrating meanness, gluttony, envy, or black-hearted evil to raise the tension, round off with a sound, unchallenging moral statement about the value of courage, friendship, and the power of love, and there already are some of the important ingredients necessary for a match-winning formula.”

In other words, Harry Potter was successful because it had exactly the attributes of Harry Potter, and not something else.

Likewise, when Facebook first became pop

@fasiha
fasiha / binomialExpansion.py
Last active May 24, 2023 05:25
If you ever need to expand a product of binomials like `prod(1 - x for x in lst)`, or its log equivalent, into a sum of monomials, here's a little well-tested Python module for you! This is handier than you'd think when the product of binomials is inside an integral for example.
from itertools import combinations
from typing import Any
from math import prod
def expand(lst: list[Any]):
"""
Expands `prod(1 - x for x in lst)` into a sum of monomials
Returns a list which summed will yield the product of binomials above.