Skip to content

Instantly share code, notes, and snippets.

import numpy as np, pandas as pd
import freetype
from shapely.geometry import *
from shapely import affinity as aff
from cartoframes.viz import Layer
face = freetype.Face("Vera.ttf") # path to your font
face.set_char_size(3000, hres = 100)
# These parameters are ok for Vera, but should be adjusted for each font.
char_width = 1500
@justvanrossum
justvanrossum / PaulBrownPattern.py
Last active March 11, 2020 21:19
DrawBot script to recreate 'Untitled Computer Assisted Drawing' by Paul Brown from 1975
# Original:
# Paul Brown, 'Untitled Computer Assisted Drawing' (1975)
# The program was written in Fortran and drawn with Calcomp's drum pen plotter.
# https://twitter.com/satoshi_aizawa/status/1218786881631965186
def drawArc(center, radius, startAngle, endAngle):
bez = BezierPath()
bez.arc(center, radius, startAngle, endAngle, False)
drawPath(bez)
@anku255
anku255 / DCEL.py
Created September 5, 2019 21:24
Double Connected Edge List (DCEL) implmented in python
import math as m
# Utils
def findHAngle(dx, dy):
"""Determines the angle with respect to the x axis of a segment
of coordinates dx and dy
"""
l = m.sqrt(dx*dx + dy*dy)
if dy > 0:
return m.acos(dx/l)
@ttsiodras
ttsiodras / RustyThoughts.md
Last active September 8, 2020 08:17
Rusty thoughts on affine types

Below is my understanding of affine types and how they help us in Rust (unsure if I got this right - please correct if I am talking nonsense).

The issue is... How can we use the power of a type system so a compiler will block us from doing this wrong sequence of calls?

FILE *fp = NULL;
fclose(fp);
fp = fopen("...");

An idea is to "mirror" the states that the file variable goes through (unused/closed, opened) in the type system:

@mortehu
mortehu / zip-test.cc
Last active May 23, 2022 12:00
C++ zip
#include <cstdio>
#include <list>
#include <vector>
#include "zip.h"
int main() {
std::vector<int> one{{1, 11}};
auto two = [] { return std::vector<short>{{2, 22}}; };
const std::list<float> three{{3, 33}};
@urraka
urraka / stb.c
Last active January 21, 2024 00:20
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STBI_ONLY_PNG
#define STBI_ONLY_JPEG
#define STBI_ONLY_BMP
#define STBI_ONLY_GIF
#include "stb_image.h"
#include "stb_image_write.h"
@dpwright
dpwright / README.md
Last active June 21, 2018 03:09
Monadic operations in C++

Monadic operations in C++

This began as a further attempt to implement the Maybe monad in C++, but quickly spiralled out of control and now includes an implementation of the List monad as well (using std::list!). This is really for my own amusement rather than to try and do anything useful with them. It also gave me an excuse to try out C++ 11 lambda functions for the first time.

My original implementation defined a macro called MBind which caused a number of problems -- thankfully [PJayB][pjayb] managed to find a way around that so

@num3ric
num3ric / interleave.cpp
Last active December 2, 2020 21:58
In-place array interleaving
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <assert.h>
typedef std::chrono::high_resolution_clock Clock;
template<typename T>