Skip to content

Instantly share code, notes, and snippets.


Árpád Goretity  H2CO3

View GitHub Profile


There is a longstanding issue/missing feature/bug with sockets on Docker on macOS; it may never work; you'll need to use a network connection between Docker containers and X11 on macOS for the foreseeable future.

I started from this gist and made some adjustments:

  • the volume mappings aren't relevant/used, due to the socket issue above.
  • this method only allows X11 connections from your Mac, not the entire local network, which would include everyone on the café/airport WiFi.
  • updated to include using the host.docker.internal name for the the container host, instead.
  • you have to restart XQuartz after the config change.
#!/usr/bin/env python3
import numpy as np
def atk(board, x, y):
h, w = board.shape
rest = w - x
atk = np.vstack([np.zeros((y, rest), dtype=int), np.ones(rest, dtype=int), np.zeros((h - 1 - y, rest), dtype=int)])
atk |= np.eye(N=h, M=rest, k=-y, dtype=int)
atk |= np.flip(np.eye(N=h, M=rest, k=y-h+1, dtype=int), axis=0)
from math import floor
import numpy as np
def primes_upto(n):
maxdiv = floor(n ** 0.5) + 1
divs = np.arange(2, maxdiv)
nums = np.arange(2, n + 1)
rem = np.mod.outer(nums, divs)
mask = np.less.outer(nums, divs ** 2)
isprime = np.all(mask | rem, axis=1)
H2CO3 /
Created Mar 13, 2021
Conway's Game of Llife in NumPy
import time
import numpy as np
def next_gen(world):
idxs = np.array(np.meshgrid(*[[-1, 0, 1]]*2)).T.reshape(-1, 2)
rots = [np.roll(world, idx, axis=(0, 1)) for idx in idxs]
neigh = np.sum(rots, axis=0) # toroidal boundary conditions
maybe = np.equal.outer([3, 4], neigh)
masks = [np.ones(world.shape, dtype=bool), world]
alive = masks & maybe
#!/usr/bin/env python3
from functools import reduce
import numpy as np
def box(n):
return np.repeat(
np.arange(1, n**2+1).reshape(n, n),
n, 1

Here's my ER schema:

          owns                       is in
user   1 <----> N   real_estate   N <-----> 1   region

What I want:

  • for each user,
View gist:485eb9e0166863af928e790befb5a978
Add mypy type-checking cell magic to jupyter/ipython.
Save this script to your ipython profile's startup directory.
IPython's directories can be found via `ipython locate [profile]` to find the current ipython directory and ipython profile directory, respectively.
For example, this file could exist on a path like this on mac:
View ffff001.js
function getLargestArray(a, b) {
let as = => 'x').join('');
let bs = => 'x').join('');
let arx = new RegExp(as);
let brx = new RegExp(bs);
let aNotShorter = as.match(brx) !== null;
let bNotShorter = bs.match(arx) !== null;
let compare = aNotShorter - bNotShorter;
switch (compare) {
case -1: return b;
H2CO3 /
Created Dec 26, 2017
n-queens problem in Rust, with (some) reference counting
use std::rc::Rc;
#[derive(Copy, Clone)]
struct IntInt {
x: i32,
y: i32,
struct Cons<T: Copy> {
elt: T,