Skip to content

Instantly share code, notes, and snippets.

Avatar

Árpád Goretity  H2CO3

View GitHub Profile
View docker_x11_macOS.md

Preamble

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.
View nqueens.py
#!/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)
View primes.py
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
H2CO3 / gol.py
Created Mar 13, 2021
Conway's Game of Llife in NumPy
View gol.py
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
View sudoku.py
#!/usr/bin/env python3
from functools import reduce
import numpy as np
def box(n):
return np.repeat(
np.repeat(
np.arange(1, n**2+1).reshape(n, n),
n, 1
View ToManyProjection.md

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
https://www.dropbox.com/s/fm1eduzdrblgvyu/Arpad_Goretity_Budapest_Rag.pdf?dl=0
View jupyter_typecheck.py
'''
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:
/Users/yourusername/.ipython/profile_default/startup/typecheck.py
View ffff001.js
function getLargestArray(a, b) {
let as = a.map(_ => 'x').join('');
let bs = b.map(_ => '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
H2CO3 / queens.rs
Created Dec 26, 2017
n-queens problem in Rust, with (some) reference counting
View queens.rs
use std::rc::Rc;
#[derive(Copy, Clone)]
struct IntInt {
x: i32,
y: i32,
}
struct Cons<T: Copy> {
elt: T,