Skip to content

Instantly share code, notes, and snippets.

View phrz's full-sized avatar

Paul Herz phrz

  • Dallas
View GitHub Profile
@phrz
phrz / svg2scad.py
Created May 30, 2018 21:43
Converts SVG path notation to OpenSCAD polygon(): supports M,L,C,Z with Bézier interpolation to points.
import string
from collections import OrderedDict
from itertools import count
# precision of output points
decimals = 2
svg = '''M0,0 L66,0 L66,140 L0,140 L0,0 Z M17.5356193,9.91374504 L7.89629934,9.91374504 L7.89629934,34.6390567 L13.9842872,34.6390567 L13.9842872,27.741635 L17.6136633,27.741635 C21.6461094,27.741635 24.6445573,27.0341777 26.6090071,25.619263 C28.5734569,24.2043483 29.555612,21.9699927 29.5554723,18.9161962 C29.5554723,15.8625389 28.5993435,13.5986987 26.687086,12.1246754 C24.7748285,10.6511862 21.7243396,9.91420937 17.5356193,9.91374504 Z M51.2530562,20.2426569 L40.4040722,20.2426569 L40.4040722,9.91374504 L34.3159446,9.91374504 L34.3159446,34.6392308 L40.4040722,34.6390567 L40.4040722,24.9118057 L51.2530562,24.9118057 L51.2530562,34.6392308 L57.3411838,34.6392308 L57.3411838,9.91374504 L51.2530562,9.91391916 L51.2530562,20.2426569 Z'''
def string_to_point_tuple(s):
[
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" }
]
@phrz
phrz / sublime-keymap.json
Last active May 29, 2018 05:01
screw MRU
[
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" }
]
@phrz
phrz / scrape_country_codes.py
Created May 14, 2018 22:58
Scrape a list of all international telephone country codes (like +1) from the Wikipedia list of country codes
import requests
from bs4 import BeautifulSoup
import re
page = requests.get('https://en.wikipedia.org/wiki/List_of_country_calling_codes')
soup = BeautifulSoup(page.text, 'html.parser')
text = str(soup.find('table', class_='wikitable'))
matches = re.findall(r'\+\d+', text)
matches = set(matches)
% !TEX TS-program = XeLaTeX
% DOCUMENT FORMATTING
\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{fullpage}
\usepackage{fancyhdr} % better looking title
\usepackage[all]{nowidow}
% MATH FORMATTING
@phrz
phrz / coderunner_nasm.sh
Last active May 3, 2018 21:48
support for NASM on macOS in CodeRunner 2
#!/bin/bash
# This is a CodeRunner compile script. Compile scripts are used to compile
# code before being run using the run command specified in CodeRunner
# preferences. This script is invoked with the following properties:
#
# Current directory: The directory of the source file being run
#
# Arguments $1-$n: User-defined compile flags
#
# Environment: $CR_FILENAME Filename of the source file being run
@phrz
phrz / life_golf.cpp
Last active February 7, 2018 19:38
Conway's Game of Life (OpenGL with SFML + GLSL shader) in 818 bytes
// -std=c++1z -lsfml-graphics -lsfml-window -lsfml-system -Ofast -ffast-math
#import<SFML/Graphics.hpp>
#define B b[i++]=x
using namespace sf;Sprite q;RenderTexture r;Texture j;Shader d;Event e;long i,w=1300,z=w*w*4,x;int main(){auto*b=new Uint8[z];RenderWindow y(VideoMode(w,w),"");d.loadFromMemory("#define g(A,B)mod(gl_FragCoord.A+B,r.A)\n#define V(A,B)texture2D(t,vec2(g(x,A),g(y,B))/r).r\n#define f float\n#define F(A)for(f A=-1.;A<2.;A++)\nuniform sampler2D t;uniform vec2 r;void main(){f s;F(i)F(j)s+=V(i,j);s=f(s==3.||(V(0.,0.)==1.&&s==4.));gl_FragColor=vec4(s,s,s,1.);}",Shader::Fragment);d.setUniform("r",Vector2f(w,w)),j.create(w,w),r.create(w,w);for(;i<z;i++)x=rand()%2*255,B,B,B,b[i]=255;j.update(&b[0]),q.setTexture(j),r.draw(q),r.display(),q.setTexture(r.getTexture());for(;;){while(y.pollEvent(e))if(e.type==Event::Closed)exit(0);y.draw(q),y.display(),r.draw(q,&d),r.display();}}
@phrz
phrz / coderunner_haskell_llvm.sh
Last active September 21, 2018 17:31
A CodeRunner run script (that can be inserted in the settings) enabling development of Haskell in CodeRunner 2. This script expects ghc to be installed (brew cask install haskell-platform) as well as the correct version of LLVM (brew install llvm@VERSION). Run CodeRunner with this script without LLVM or with the wrong version and you'll get an e…
#!/bin/bash
# This is a CodeRunner compile script. Compile scripts are used to compile
# code before being run using the run command specified in CodeRunner
# preferences. This script is invoked with the following properties:
#
# Current directory: The directory of the source file being run
#
# Arguments $1-$n: User-defined compile flags
#
# Environment: $CR_FILENAME Filename of the source file being run
@phrz
phrz / peers.sh
Created January 16, 2018 16:07
A quick bash alias for finding peers on a network with nmap.
alias peers="nmap -sn 192.168.1.0/24|python3 -c $'import sys\n[print(\' \'.j oin(s.split(\' \')[4:]),end=\'\') for s in sys.stdin.readlines()[2::2]]'"
@phrz
phrz / reverse_string.c
Created January 16, 2018 15:18
Reverses a string in C while minding buffer sizes.
void reverse(char* string, char* buffer, size_t buffer_limit) {
if(buffer_limit < 1) {
return;
}
size_t len = strnlen(string, buffer_limit);
if(len == 0) {
buffer[0] = '\0';
return;
}
buffer[len] = '\0';