Skip to content

Instantly share code, notes, and snippets.

View rougier's full-sized avatar
:octocat:

Nicolas P. Rougier rougier

:octocat:
View GitHub Profile
@rougier
rougier / fractal-dimension.py
Last active August 13, 2024 10:35
Fractal dimension computing
# -----------------------------------------------------------------------------
# From https://en.wikipedia.org/wiki/Minkowski–Bouligand_dimension:
#
# In fractal geometry, the Minkowski–Bouligand dimension, also known as
# Minkowski dimension or box-counting dimension, is a way of determining the
# fractal dimension of a set S in a Euclidean space Rn, or more generally in a
# metric space (X, d).
# -----------------------------------------------------------------------------
import scipy.misc
import numpy as np
@rougier
rougier / numpy_find_view.py
Created November 3, 2016 18:14
Numpy find view
def find_view(base, view):
"""
Given an array that is a `view` of a `base`, find an index such that
`base[index] is view`
"""
if not isinstance(view, np.ndarray):
return "..."
itemsize = view.itemsize
@rougier
rougier / poisson-disk-sampling.py
Created November 15, 2016 16:42
Poisson disk sampling
def poisson_disk_sample(width=1.0, height=1.0, radius=0.025, k=30):
# References: Fast Poisson Disk Sampling in Arbitrary Dimensions
# Robert Bridson, SIGGRAPH, 2007
def squared_distance(p0, p1):
return (p0[0]-p1[0])**2 + (p0[1]-p1[1])**2
def random_point_around(p, k=1):
# WARNING: This is not uniform around p but we can live with it
R = np.random.uniform(radius, 2*radius, k)
T = np.random.uniform(0, 2*np.pi, k)
@rougier
rougier / marker-rotation.py
Created November 27, 2016 07:32
Matplotlib / individual rotation markers using a single path
# Matplotlib / individual rotation markers using a single path
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.animation import FuncAnimation
from matplotlib.collections import PathCollection
triangle = [[(-0.25, -0.5), (+0.0, +0.5), (+0.25, -0.5), (+0.0, +0.0)],
@jakevdp
jakevdp / convolution_matrix.py
Last active March 12, 2019 09:49
Convolution Matrix
# Author: Jake VanderPlas
# LICENSE: MIT
from __future__ import division
import numpy as np
def convolution_matrix(x, N=None, mode='full'):
"""Compute the Convolution Matrix
@rougier
rougier / cellular-automata-1d.py
Last active February 24, 2017 21:14
Cellular automata 1D
# Copyright (2017) Nicolas P. Rougier - BSD license
# Twitter version (140 characters)
# --------------------------------
_='0'
R,C="{:08b}".format(30),_*9+'1'+_*9
for k in range(9):
print(C)
C = _+''.join([R[7-eval('0b'+C[i:i+3])] for i in range(len(C)-2)])+_
@felipeochoa
felipeochoa / mu4e-thread-folding.el
Created March 16, 2017 18:05
Thread folding in mu4e
;; Refactored from https://github.com/djcb/mu/pull/783
(defun mu4e~headers-msg-unread-p (msg)
"Check if MSG is unread."
(let ((flags (mu4e-message-field msg :flags)))
(and (member 'unread flags) (not (member 'trashed flags)))))
(defvar mu4e-headers-folding-slug-function
(lambda (headers) (format " (%d)" (length headers)))
@max-mapper
max-mapper / bibtex.png
Last active November 6, 2024 09:03
How to make a scientific looking PDF from markdown (with bibliography)
bibtex.png
@victor-shepardson
victor-shepardson / pytorch-glumpy.md
Last active January 22, 2025 20:55
using pycuda and glumpy to draw pytorch GPU tensors to the screen without copying to host memory
@sinclairtarget
sinclairtarget / 1-cat-pdp7.s
Last active July 16, 2025 20:06
cat through the ages
" cat
lac 017777 i " Load accumulator (AC) with argument count
sad d4 " Skip next if we have more than 4 words of args
jmp nofiles " Otherwise, jump to nofiles
lac 017777 " Load AC with address of args
tad d1 " Increment AC by 1, past argument count
tad d4 " Increment AC by 4, now AC points to first real arg
dac name " Save arg pointer from AC into 'name'