Skip to content

Instantly share code, notes, and snippets.

View tuzz's full-sized avatar

Chris Patuzzo tuzz

View GitHub Profile
@tuzz
tuzz / github.css
Last active May 8, 2024 00:48
Github Markdown Stylesheet
/*
Copyright (c) 2017 Chris Patuzzo
https://twitter.com/chrispatuzzo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@tuzz
tuzz / twos_complement.rb
Last active September 11, 2022 21:31
Encode and Decode integers to and from twos complement in Ruby
module TwosComplement
def self.encode(n)
if n < 0
binary = (n + 1).abs.to_s(2).chars.map { |c| c == "0" }
binary.unshift(true) unless binary.first == true
else
binary = n.to_s(2).chars.map { |c| c == "1" }
binary.unshift(false) unless binary.first == false
end
@tuzz
tuzz / Cargo.toml
Last active March 17, 2021 16:05
A proof of concept that uses the Sliding Puzzle crate to search for words.
[package]
name = "sliding_puzzle_message"
version = "0.1.0"
authors = ["Chris Patuzzo <chris@patuzzo.co.uk>"]
edition = "2018"
[dependencies]
sliding_puzzle = "*"
pathfinding = "*"
@tuzz
tuzz / invisible_text.pdf
Created December 6, 2020 14:02
A PDF that contains an invisible '24. a.' list item.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tuzz
tuzz / miracle-sudoku-tweet-solver.snt
Created August 13, 2020 22:36
A quick Sentient program to solve a sudoku posted in a tweet
# A quick Sentient program to solve the sudoku posted in this tweet:
# https://twitter.com/crypticcracking/status/1293897459912056833
function main () {
array9<array9<int5>> sudoku;
sudoku.each(function (row) {
invariant row.uniq?;
invariant row.all?(function (n) {
[package]
name = "foo"
version = "0.1.0"
edition = "2018"
[dependencies]
legion = "0.2.4"
@tuzz
tuzz / gaussian
Last active May 3, 2020 11:36
Generate the weights/offsets for an efficient two-pass Gaussian blur filter of different sizes.
#!/usr/bin/env ruby
# Generate the weights/ offsets for an efficient two-pass Gaussian blur filter of different sizes.
# Based on: http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
#
# Usage: ./gaussian [epsilon]
require "bigdecimal/util"
EPSILON = Float(ARGV[0] || 0.05)
@tuzz
tuzz / web_sys_event_handler.rs
Created April 19, 2020 10:04
A convenience wrapper for handling events in Rust using web_sys
// The EventHandler::new method takes three arguments:
//
// 1) The Rust function to call to handle the event
// 2) The registration function
// 3) The deregistration function
//
// The deregistration function is called when the EventHandler is dropped.
// This is similar to React's useEffect cleanup pattern.
pub struct EventHandler {
@tuzz
tuzz / commit.rb
Created July 24, 2012 14:30
Generate a pie chart showing commits by author in a git repository
#!/usr/bin/ruby
# Run in the root directory of a git repository with ruby commits.rb
# Depends upon the 'rmagic' and 'gruff' gems.
require 'rubygems'
require 'gruff'
commits = `git shortlog -ns`.split("\n").map { |e| e.strip.split("\t") }.map { |n, a| [a, n.to_i] }
int8 m, n, p, q;
m2 = m.square;
n2 = n.square;
p2 = p.square;
q2 = q.square;
# ceil(log2(sqrt((2 ** (bits - 1)) ** 2 ** 2 * 3)) + 1)
int16 inner, outer1, outer2;
int2 i;