Skip to content

Instantly share code, notes, and snippets.

View ljcooke's full-sized avatar

Liam Cooke ljcooke

View GitHub Profile
#!/usr/bin/env ruby
# frozen_string_literal: true
i = 0
poem = DATA.read.split("\n").select { |s| s.start_with?('>') }
poem.each_with_index do |line, num|
direction = rand(2) * (num > poem.size / 2 ? -1 : 1)
options = line[1..].split('.')
i = [[0, i + direction].max, options.size - 1].min
puts options[i].strip
@ljcooke
ljcooke / deploy.sh
Last active January 3, 2022 03:44
A script to revolutionise web3* using blockchain** (*update my website) (**bash)
#!/usr/bin/env bash
set -euo pipefail
deploy() {
rsync -Pachvz --exclude '.DS_Store' \
"${BUILD_DIR}/" "${REMOTE_HOST}:${REMOTE_PATH}/" "$@"
}
printf "\n== DRY RUN ==\n"
%!PS-Adobe-3.0 EPSF-3.0
%%Pages: 1
%%BoundingBox: 0 0 720 720
%%EndComments
/inch { 72 mul } def
/invertgray { 1 currentgray sub setgray } def
/makepoints { % nsides
4 dict begin
%!PS-Adobe-3.0 EPSF-3.0
%%Pages: 1
%%BoundingBox: 0 0 720 720
%%EndComments
/inch { 72 mul } def
/windistance 1 def
/project3d {
@ljcooke
ljcooke / Makefile
Last active August 9, 2020 06:45
Drawing an icon with PostScript.
avatar-500.png: avatar.png
convert avatar.png -unsharp 0x5 -resize 500 avatar-500.png
avatar.png: avatar.pdf
inkscape -b white -d 100 -o avatar.png avatar.pdf
mogrify -flatten -background white avatar.png
avatar.pdf: avatar.ps
ps2pdf -dEPSCrop avatar.ps
#!/bin/sh
set -o errexit
set -o nounset
tile() {
printf "%s\033[1B\033[3D%s\033[1B\033[3D%s\033[2A" '╲┴╱' '┤╳├' '╱┬╲'
}
printf "\033[2J\033[H"
@ljcooke
ljcooke / nodaire-invalid-source.rb
Last active August 18, 2019 11:02
Example of parsing invalid Indental source with Nodaire::Indental.
> require 'nodaire/indental'
# true
> source = <<~NDTL
NAME
KEY : VALUE
key : duplicate
wrong indent level
NDTL
@ljcooke
ljcooke / pre-push
Created December 17, 2018 22:22
.git/hooks/pre-push
#!/bin/sh
bundle exec rubocop
@ljcooke
ljcooke / .bashrc
Last active August 17, 2017 07:54
Bash function to read a man page in your web browser.
function hman()
{
if [ $# -gt 0 ]; then
man $@ | man2html | bcat
else
man
return 1
fi
}
#!/usr/bin/env python3
"""
Make an image with some text. Example:
./textimg.py -f fonts/SourceCodePro-Regular.otf 'Hello, world.'
"""
import argparse
import subprocess
import sys