Skip to content

Instantly share code, notes, and snippets.

View benjamingorman's full-sized avatar

Benjamin Gorman benjamingorman

View GitHub Profile
@benjamingorman
benjamingorman / index.html
Created May 6, 2024 00:13
Downscale oversized pixel art
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixel Art Resizer</title>
<style>
#input-image {
max-width: 100%;
UklGRrBJBgBXQVZFZm10IBAAAAABAAIARKwAABCxAgAEABAAZGF0YXBJBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
import math
import numpy as np
import sys
lattice_width = 100
lattice_height = 100
initial_learning_rate = 0.01
input_dimensions = 3
weights = np.random.rand(lattice_height, lattice_width, input_dimensions)
initial_neighbourhood_radius = 15.0
@benjamingorman
benjamingorman / pysplit.py
Created July 21, 2016 13:55
Command line string splitting tool
#!/usr/bin/env python
"""Splits every line in STDIN using str.split. Prints
each field on STDOUT using the indices given as arguments
to the script.
Usage:
echo 'foo bar baz' | pysplit 2 1 0
echo 'foo,bar,baz' | pysplit , 2 1 0
"""
import sys
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Set directory of current project
export CURRENTPROJ=~/Projects
cd $CURRENTPROJ
@benjamingorman
benjamingorman / .vimrc
Created July 21, 2015 21:50
Laptop vimrc
execute pathogen#infect()
"Temporary bindings:
nmap <F5> :!love .<CR><CR>
""""""""""""
"PLUGINS
""""""""""""
"NERDTree
nmap \e :NERDTreeToggle<CR>
@benjamingorman
benjamingorman / gist:840f42cca525ab2cd6bf
Last active March 8, 2023 07:32
Shader - Circle and Rectangle functions
// returns 1.0 if inside circle
float disk(vec2 r, vec2 center, float radius) {
return 1.0 - smoothstep( radius-0.005, radius+0.005, length(r-center));
}
// returns 1.0 if inside the disk
float rectangle(vec2 r, vec2 bottomLeft, vec2 topRight) {
float ret;
float d = 0.005;
ret = smoothstep(bottomLeft.x-d, bottomLeft.x+d, r.x);
ret *= smoothstep(bottomLeft.y-d, bottomLeft.y+d, r.y);
@benjamingorman
benjamingorman / parallel_waves.glsl
Last active August 29, 2015 14:19
Shader - Parallel waves
// credit: https://www.shadertoy.com/view/4dsGzH
vec2 uv = fragCoord.xy / iResolution.xy;
vec3 final_color = vec3(1.0); //white
vec3 bg_color = vec3(0.0); //black
vec3 wave_color = vec3(0.0); //black
float wave_width = 0.1;
uv = vec2(-1.0, -1.0) + 2.0 * uv; // convert to -1.0 < y < 1.0
uv.y += 0.1;
import cProfile
import collections
def pascal(first, length):
row = []
a = first
for x in range(1, length):
# x and y form the ratio between consecutive elements
b = length - x
a = a * b // x # // is the integer division function
@benjamingorman
benjamingorman / python_run_log.txt
Created December 30, 2014 17:42
Python connect to RoboMinions log
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/google/protobuf/internal/python_message.py", line 839, in MergeFromString
if self._InternalParse(serialized, 0, length) != length:
File "/usr/lib/python3.4/site-packages/google/protobuf/internal/python_message.py", line 860, in InternalParse
(tag_bytes, new_pos) = local_ReadTag(buffer, pos)
File "/usr/lib/python3.4/site-packages/google/protobuf/internal/decoder.py", line 189, in ReadTag
while (ord(buffer[pos]) if py2 else buffer[pos]) & 0x80:
TypeError: unsupported operand type(s) for &: 'str' and 'int'
During handling of the above exception, another exception occurred: