Skip to content

Instantly share code, notes, and snippets.

View User4574's full-sized avatar

Nat Lasseter User4574

View GitHub Profile
@User4574
User4574 / scan.sh
Last active September 7, 2023 19:00
Batch scanning script
#!/bin/bash
function scanpage {
echo -n insert $1 and press return
read
scanimage \
-d 'brother5:bus2;dev2' \
--AutoDocumentSize=yes \
--format=pdf \
--resolution 300 \
@User4574
User4574 / digits.rb
Last active September 2, 2023 12:19
Digit combinations for target sum
#!/usr/bin/env ruby
require 'optimist'
opts = Optimist::options do
version "digits 0.2 (c) 2023 Nat Lasseter"
banner <<-EOS
Digits gives valid combinations of digits 1-9 that sum to the given total
Usage:
@User4574
User4574 / a_cat.erl
Created August 16, 2023 10:42
gen_object: the start of an erlang OO behaviour
% This is a cat. It behaves like a generic object.
-module(a_cat).
-behaviour(gen_object).
-export([initialise/1, handle_message/3]).
initialise([Name]) ->
{Name, "Meow"}.
handle_message(say, [Word], {Name, Word}) ->
@User4574
User4574 / pdfbook4.rb
Last active June 23, 2023 15:09
Page order to make (or pdfjam command to turn a pdf file into) 4-up double-sided brochure ordered pages (to make two A6 folia per A4 page)
#!/usr/bin/env ruby
n = ARGV.shift.to_i
m = n
m = ((m / 8) + 1) * 8 if m % 8 != 0
p = (1..n).map(&:to_s) + ["{}"] * (m - n)
o = []
until p.empty? do
@User4574
User4574 / tabelvortoj.rb
Created May 12, 2023 12:44
Tabelvortoj test
#!/usr/bin/env ruby
#!DESCRIBE: Flash cards for table words
require "io/console"
data = DATA.each_line.map { |l| l.strip.split(?;) }
correct = 0
total = 0
@User4574
User4574 / cpc.rb
Last active April 10, 2023 17:42
Cyclically Permutable Codewords
codewords = []
class Integer
def rotate_left(bits, width = bit_width)
bits %= width
(self << bits | self >> (width - bits)) & ((1 << width) - 1)
end
end
(2**8).times do |candidate|
@User4574
User4574 / .vimrc
Created February 13, 2023 11:31
Simple Vim Todo
"In normal mode, [ positions the cursor in the checkbox and waits for a character with which to replace the checkmark.
au FileType todo nnoremap [ 0t]r
"In insert mode, [ actually inserts a checkbox and a space.
au FileType todo inoremap [ [<Space>]<Space>
"Any file with a name ending in todo is a todo file.
au BufRead,BufNewFile *todo set ft=todo
#!/usr/bin/env ruby
#!DESCRIBE: Describe the purpose of an executable
require 'ptools'
def fatal(filename, msg)
$stderr.puts("[ERR] #{filename}: #{msg}")
exit 1
end
@User4574
User4574 / slide.rb
Created March 21, 2022 18:55
A laser-cuttable circular slide rule generator
#!/usr/bin/env ruby
Maths = Math
Radius = ARGV.shift&.to_f || 50.0
Ring = ARGV.shift&.to_f || 15.0
Decimals = 6
Origin_x = Radius + Ring + 1
Origin_y = Radius + Ring + 1
@User4574
User4574 / logcircle.rb
Created March 20, 2022 14:20
Output cartesian coordinates for the tickmarks along a log scale around a circle
#!/usr/bin/env ruby
Maths = Math
Intervals = ARGV.shift&.to_i || 2
Radius = ARGV.shift&.to_i || 25
Decimals = ARGV.shift&.to_i || 3
Scale = Maths::PI * 2 / Intervals
Width = 1 + Maths.log10(Radius).to_i + 1 + 1 + Decimals