Skip to content

Instantly share code, notes, and snippets.

View backup.sh
#!/bin/bash
#
# Backs up my entire website, in case Tumblr or CloudApp goes down someday.
# Last time I ran this, it took 18 minutes.
#
wget \
--mirror `# turns on recursion and timestamping, basically says we want to "mirror" the whole site` \
--convert-links `# after download, convert all links to point to localhost` \
@peterc
peterc / movies.txt
Last active Jul 23, 2021
Movies Watched in 2021 So Far
View movies.txt
I'm trying to migrate from my own spreadsheet to Letterboxd without
much success so far.. so this is just a total mess of a list,
but broadly in order watched this year.
Favourites have been all the Gasper Noe ones (Enter The Void,
Irreversible, etc.)
Only Tenet, The Father and A Quiet Place 2 were at the cinema 🙁
Some are rewatches (e.g. 2001, 1408, Alien) due to getting them
@peterc
peterc / s4d.rb
Created Jul 13, 2021
Convert abbreviated text like i18n and l11n to full text
View s4d.rb
text = ARGV.first || "y1u a5t p1l? j2t w4d to s1y hi"
times = (ARGV[1] || 1).to_i
words = File.readlines('/usr/share/dict/words')
.map(&:downcase)
.map(&:chomp)
times.times do
puts text.gsub(/\w+/) { |word|
words.select { |realword|
View ten-seconds.md

Ten seconds to ponder if a thread is worth it

recording

A userstyle that makes you wait ten seconds before entering a Hacker News thread. I use stylus to manage mine.

.subtext {
  display: inline-block;
  background: linear-gradient(to left, transparent 50%, #f60 50%) right;
@peterc
peterc / gist:62af77f2f5459c27a026bae603eece84
Created Feb 3, 2021
Can you jam with the console cowboys in cyberspace?
View gist:62af77f2f5459c27a026bae603eece84
          
.     
@peterc
peterc / aoc13-part1.rb
Last active Feb 3, 2021
Advent of Code 2020 Day 13 in Ruby annotated
View aoc13-part1.rb
$<.to_a.tap {|e,rs|p rs.split(',').map(&:to_i).reject(&:zero?).map{|r|[r,r-(e.to_i%r)]}.min_by(&:last).inject(:*)}
@peterc
peterc / dnsimple_ssl_to_linode_object_storage.rb
Created Dec 12, 2020
Copy a TLS certificate and private key from DNSimple to Linode Object Storage
View dnsimple_ssl_to_linode_object_storage.rb
# dnsimple_ssl_to_linode_object_storage.rb
# Copy a certificate stored on DNSimple to Linode Object Storage
#
# Depends on 'http' gem
#
# Requires environment settings as such:
# LINODE_TOKEN=[API token]
# LINODE_REGION=[region of your object storage bucket]
# DNSIMPLE_TOKEN=[API token]
# DNSIMPLE_DOMAIN=example.com
@peterc
peterc / aoc9.rb
Created Dec 9, 2020
Advent of Code 2020 Day 9 in Ruby
View aoc9.rb
nums = $<.readlines.map(&:to_i)
w = 25
w.upto(nums.length - 1) do |i|
p nums[i] if nums[i-w, w].combination(2)
.map(&:sum)
.all? { |x| x != nums[i] }
end
w.times do |cw|
@peterc
peterc / github_rate.rb
Created Dec 5, 2020
See GitHub API rate limit information in a useful way
View github_rate.rb
# Return GitHub API rate information in JSON format
# GitHub Personal Access Token expected in ~/.githubtoken
# I'd pipe this into jq for nicer viewing
require 'http'
require 'json'
TOKEN = File.read(ENV['HOME'] + "/.githubtoken").strip
res = HTTP["Authorization" => "token #{TOKEN}"].get("https://api.github.com/rate_limit")
@peterc
peterc / pg.txt
Created Nov 19, 2020
Ruby pg (Postgres) library notes
View pg.txt
# gem 'pg'
# https://github.com/ged/ruby-pg
# http://deveiate.org/code/pg
#
# I always find it a nightmare to look up how it works because
# it's not intuitive at all. So here are some notes.
# CONNECTION
# ==========
# No connection URL support, so..