Skip to content

Instantly share code, notes, and snippets.

View noamraph's full-sized avatar

Noam Yorav-Raphael noamraph

View GitHub Profile
use std::collections::HashMap;
use std::fmt;
use std::io;
use std::num::ParseFloatError;
use std::rc::Rc;
/*
Types
*/
@noamraph
noamraph / flake.lock
Created August 24, 2023 12:15
Nix: Cross-compile Hello World for mips64r6el
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1692698134,
"narHash": "sha256-YtMmZWR/dlTypOcwiZfZTMPr3tj9fwr05QTStfSyDSg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a16f7eb56e88c8985fcc6eb81dabd6cade4e425a",
"type": "github"
@noamraph
noamraph / sentinel.py
Created March 5, 2023 06:21
Trying to make sentinels which seem like the type of themselves
from __future__ import annotations
from typing import Any
from abc import ABCMeta
# Quit is an example of a sentinel.
# I want "class Quit(Sentinel): pass" to produce the same thing.
@noamraph
noamraph / pymonad.py
Last active December 14, 2022 13:46
Understanding the Haskell IO monad by implementing it in Python
# Based on https://youtu.be/fCoQb-zqYDI
# This passes `mypy --strict`, which is cool.
from __future__ import annotations
from typing import NamedTuple, Tuple, Callable, TypeVar
A = TypeVar('A')
B = TypeVar('B')
@noamraph
noamraph / dobble.py
Created April 19, 2020 21:45
Code for producing a figure showing dobble matrix
from itertools import combinations
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.text import Text
def dobble(p):
cards = [[] for i in range(p**2 + p + 1)]
cards[0].append(0)
for i in range(p+1):
for j in range(p):
#!/usr/bin/env python
from __future__ import division, print_function
import sys
import os
from os.path import join, abspath, exists, expanduser
from contextlib import contextmanager
import hashlib
import cStringIO
import json
@noamraph
noamraph / byzanz_window.py
Created January 10, 2014 08:24
byzanz_window: Use byzanz to create a GIF screencast of a specific window
#!/usr/bin/env python
"""
Use byzanz to create a GIF screencast of a specific window.
Required tools:
sudo apt-get install byzanz x11-utils xdotool
A tip: use an extra-long duration (-d 100), record your shot, and use
gimp to shorten the duration of the last frame. You need to rename the layer
from "Frame 123 (100000 ms) (combine)" to "Frame 123 (1000 ms) (combine)".
@noamraph
noamraph / activate_app_if_running.py
Created January 9, 2014 12:00
A module which lets you create a pygtk application which will start the running instance if being executed again. Based on http://askubuntu.com/a/171996/98448
"""
Allow an application to activate a running instance of itself instead of
starting another instance.
"""
import sys
import gtk
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
@noamraph
noamraph / critnuc.py
Created June 4, 2013 12:46
An arbitrary function approaches the critical nucleus in the Ginzburg-Landau time dependent equation
from __future__ import division
import numpy as np
from scipy.optimize import brentq
from fipy import Grid1D, CellVariable, Viewer, TransientTerm, DiffusionTerm
import matplotlib.pyplot as plt
D=1.
dx = 0.1
nx = 1000