Skip to content

Instantly share code, notes, and snippets.

View fasiha's full-sized avatar
💭
🐦‍🔥

Ahmed Fasih fasiha

💭
🐦‍🔥
View GitHub Profile
@fasiha
fasiha / analyze.py
Created March 12, 2025 06:33
Comparing US stonks ($VTI) and World ex-US ($ACWX) for a couple of months before and after the start of 2025 like the FT article. Code assumes Yahoo! Finance CSV files are available.
import pandas as pd
import numpy as np
import pylab as plt
from pandas.tseries.offsets import MonthEnd
plt.style.use('ggplot')
plt.ion()
# Load the datasets
us_data = pd.read_csv('vti.txt.csv', parse_dates=['Date'], index_col='Date')
@fasiha
fasiha / combinatorics.ts
Last active January 19, 2025 19:06
JavaScript/TypeScript basic combinatorics generators/iterators—because I always forget how these work. UNLICENSE, in the public domain.
/**
* Simple Cartesian product generator.
*
* Given an N-long array of numbers `lenarr`, where each element representing how many choices are available for that
* position, generate all N-long arrays where the `idx`th element runs from 0 to `lenarr[index]`.
*
* ```ts
* for (const x of numericCartesianProduct([2, 3])) { console.log(x); }
* ```
* generates:
@fasiha
fasiha / demo.ts
Last active January 3, 2025 15:33
How to efficiently and compactly limit concurrency in JavaScript's Promise.all. A simplified and convincing demo for https://stackoverflow.com/a/51020535/ that you can run on TypeScript Playground
const sleep = (t: number) => new Promise((rs) => setTimeout(rs, t));
/**
* This function will return an array of the same length as the input,
* but not in the same order. It's straightforward to extend it to
* preserve order, but I left it like this because this way the timing
* is clearly visible. This helped me confirm that it works.
*/
async function processArray(input: number[], numWorkers: number) {
const ret: { date: number; description: string }[] = [];
@fasiha
fasiha / README.md
Last active December 29, 2024 16:11
Set up RTL-SDR, dump1090, and dump978 for ADS-B/TIS-B/FIS-B/UAT on macOS

Introduction

I’m not very familiar with the aviation jargon (see FAA’s ADS-B FAQ), but ADS-B is a next-gen system where aircraft are equipped with transponders that periodically broadcast their own positions and receive the reports from both other aircraft (direct air-to-air) as well as air-traffic control (ATC) ground transmitters.

There are two separate ADS-B radio bands: the commercial aviation (CA) is at 1090 MHz while the general aviation (GA) is at 978 MHz. If I can be permitted a gross generalization—the former corresponds to big commercial jets and the latter to small private aircraft.

Because ADS-B is designed to democratize airspace situational awareness (in contrast to the older setup, like from films, where a central air-traffic controller is coordinating all these aircraft that can’t see each other), we can buy cheap RF receivers to pick up and decode the messages being broadcast by aircraft and ground towers to get our own picture of the

@fasiha
fasiha / DictionaryOfJapaneseGrammar.csv
Created December 15, 2017 04:39
All example sentences from Seiichi Makino and Michio Tsutsui's series of three Japanese grammar dictionaries: "Dictionary of Basic Japanese Grammar", "Intermediate" and "Advanced
We can't make this file beautiful and searchable because it's too large.
Number,Expression,Translation,Reading,Grammar Japanese,Grammar English,Grammar Explanation,Notes,Picture,Page,Level,Scrambled
1,私は良子に花をあげた・あげました。,I gave Yoshiko flowers.,私[わたし]は 良子[りょうこ]に 花[はな]をあげた・あげました。,あげる,,give | Someone gives something to a person who is not a member of the giver’s in group but whose status is about equal to that of the giver.,,,63,Basic,
2,大野さんは山本さんに本をあげた。,Ms. Ono gave Mr. Yamamoto a book.,大野[おおの]さんは 山本[やまもと]さんに 本[ほん]をあげた。,あげる,,give | Someone gives something to a person who is not a member of the giver’s in group but whose status is about equal to that of the giver.,,,63,Basic,scrambled
3,君はアンに何をあげましたか。,What did you give to Ann?,君[きみ]はアンに 何[なに]をあげましたか。,あげる,,give | Someone gives something to a person who is not a member of the giver’s in group but whose status is about equal to that of the giver.,,,63,Basic,scrambled
4,私は信男さんにネクタイを買ってあげた・あげました。,I bought a tie for Nobuo.,私[わたし]は 信男[のぶお]さんにネクタイを 買[か]ってあげた・あげました。,あげる,,do s.t. for s.o.; do s.o. a favor by doing s.t. |&nbs
@fasiha
fasiha / howPolyphaseDecimationWorks.py
Created February 17, 2017 07:30
How polyphase decimation works—a nitty-gritty didactic Python implementation that is within machine-precision of naive decimation
"""
Brief script to show how to correctly implement indexing for polyphase decimation.
Run as:
$ python <thisfile.py>
It was helpful to read [1], especially slide 5.
[1] http://www.ws.binghamton.edu/fowler/fowler%20personal%20page/EE521_files/IV-05%20Polyphase%20FIlters_2007.pdf
@fasiha
fasiha / learn_datalog_today.clj
Created May 10, 2016 03:32
Learn Datalog Today ported to DataScript & Clojure (JVM)
; Learn Datalog Today (http://www.learndatalogtoday.org) is a great resource for
; reading but its interactive query interface is broken. Below is how we can
; load the same data into a Clojure REPL and play with it using DataScript.
; After running the code below, many/most/all? of the queries on Learn Datalog
; Today should be functional.
;
; Create a new lein project, add `[datascript "0.15.0"]` to `project.clj`'s
; `dependencies`, run `lein deps && lein repl` and copy-paste the following in
; chunks, inspecting the outputs as needed.
@fasiha
fasiha / README.md
Last active October 23, 2024 02:50
Pitch (fundamental frequency) detection using (1) harmonic product spectrum, (2) Blackman-Tukey spectral estimator, and (3) Welch spectral estimator.

Experimenting with pitch detection and spectral estimators

See the question and discussion on StackOverflow: How to get the fundamental frequency using Harmonic Product Spectrum?.

We’re trying to estimate the fundamental frequency of a voiced A4 note (440 Hz). (See the question for link to audio clip.)

Harmonic product spectrum

Result: full data, 0 to 2 KHz

@fasiha
fasiha / youtube-dl-crunchyroll.md
Last active October 12, 2024 00:16
Youtube-dl with Crunchyroll

Get the following:

  • a Crunchyroll account (though they let you watch/download some videos without an account, at 480p),
  • the latest youtube-dl (brew upgrade youtube-dl),
  • your browser’s user agent,
  • your Crunchyroll cookies (cookie.txt export for Chrome is handy) into a cookies.txt file.

Then,

@fasiha
fasiha / README.md
Last active July 30, 2024 13:20
How to visualize 2D arrays in Matplotlib/Python (like imagesc in Matlab)

Visualizing rectangular 2D arrays in Python and Matplotlib the way you do with Matlab’s imagesc

Say you have a very rectangular 2D array arr, whose columns and rows correspond to very specific sampling locations x and y. That is, the arr[i, j] entry corresponds to some measurement taken at x[j] and y[i].

Matlab’s imagesc shows you this quite meaningfully:

x = linspace(-100, -10, 10);
y = [-8 -3];
data = randn(numel(y), numel(x));