Skip to content

Instantly share code, notes, and snippets.

View H2CO3's full-sized avatar
🦀

Árpád Goretity  H2CO3

🦀
View GitHub Profile
@H2CO3
H2CO3 / guardhdr.sh
Created October 12, 2013 06:00
This script appends an automatically generated include guard to a specified header file. Optionally, you can provide a prefix that will be added to the guard macro.
#!/bin/bash
if [ "$#" = "0" ]; then
echo "at least one argument is required"
exit 1
fi
FILE=$1
GUARD="$2$(printf "%s" $FILE | tr '.' '_' | tr '[[:lower:]]' '[[:upper:]]')"
@H2CO3
H2CO3 / option.cc
Created October 10, 2023 15:40
Safe, simple Option<T> for C++
#include <iostream>
#include <iomanip>
template<typename T>
union OptionInner {
T full;
char empty;
OptionInner(): empty(0) {}
@H2CO3
H2CO3 / gram_schmidt.py
Created September 6, 2023 08:04
Gram-Schmidt orthogonalization using NumPy einsum
import numpy as np
def gram_schmidt(X):
'''
Perform Gram-Schmidt orthogonalization on the rows of X.
Return a new array Y with the same shape as Y of which
the rows form an orthonormal basis.
The input vectors must be linearly independent.
The number of input vectors (rows) must not exceed the
@H2CO3
H2CO3 / docker_x11_macOS.md
Created August 26, 2021 20:03 — forked from paul-krohn/docker_x11_macOS.md
Docker X11 macOS

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.
#!/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
H2CO3 / gol.py
Created March 13, 2021 07:20
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.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,
https://www.dropbox.com/s/fm1eduzdrblgvyu/Arpad_Goretity_Budapest_Rag.pdf?dl=0