Skip to content

Instantly share code, notes, and snippets.

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

Ahmed Fasih fasiha

💭
🧘‍♂️🐻
View GitHub Profile
@fasiha
fasiha / posdef.py
Last active April 17, 2024 04:28
Python/Numpy port of John D’Errico’s implementation (https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd) of Higham’s 1988 paper (https://doi.org/10.1016/0024-3795(88)90223-6), including a built-in unit test. License: whatever D’Errico’s license, since this is a port of that.
from numpy import linalg as la
import numpy as np
def nearestPD(A):
"""Find the nearest positive-definite matrix to input
A Python/Numpy port of John D'Errico's `nearestSPD` MATLAB code [1], which
credits [2].
@fasiha
fasiha / youtube-dl-crunchyroll.md
Last active April 15, 2024 14:51
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 March 31, 2024 17:49
Hiragana frequency in readings of sentences in Tono, et al., *A Frequency Dictionary of Japanese* (2013; Core5000 Anki deck)

Overview Nayr's Japanese Core5000 Anki deck (discussion) contains pronunciations of all five thousand or so sentences in A Frequency Dictionary of Japanese by Yukio Tono, Makoto Yamazaki, and Kikuo Maekawa (2013), which contains the top five thousand words in Japanese according to the latest corpus research. I analyzed these sentences to make a histogram table of hiragana occurrences, including dipthongs like きゃ, ちょ, etc. The attached two tables show the results in modern hiragana order, and sorted order.

Technical notes I parsed a file containing those sentences (with annotated readings in hiragana, in core5k-sentences.md) using the following script and helper file (in kana.txt):

cp core5k-sentences.md sacrifice.md; 
sed '/^$/d' kana.txt | while read i; do 
  echo -n $i " : " ;
  sed -n "s/$i/$i\n/gp" 
@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 / README.md
Last active December 23, 2023 05:42
J.DepP usage and output example

Example output

➜ echo あの壁にかかっている絵はきれいですね | mecab -d /usr/local/lib/mecab/dic/unidic | jdepp 2> /dev/null | to_tree.py
# S-ID: 1; J.DepP
  0:         あの━━┓
  1:   壁に━━┓     ┃
  2:  かかっている━━┓  ┃
  3:         絵は━━┫
  4:        きれいですねEOS
➜ echo あの壁にかかっている絵はきれいですね | mecab -d /usr/local/lib/mecab/dic/unidic | jdepp 2> /dev/null | to_chunk.py
@fasiha
fasiha / demo.ts
Last active November 14, 2023 15:54
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 November 3, 2023 20:40
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 / 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]