Skip to content

Instantly share code, notes, and snippets.

View fingerd.rb
#!/usr/bin/env ruby
require 'eventmachine'
class FingerServer < EM::Connection
def receive_data(data)
if data =~ /\A\w+\z/ && data.length <= 100
puts "Got a request for user #{data}"
peterc / mlr.txt
Created Jun 7, 2022
Using mlr to filter and sort a CSV of GitHub projects
View mlr.txt
mlr --csv filter 'strptime($pushed_at,"%Y-%m-%d %H:%M:%S %Z") > strptime("2021-09-01", "%Y-%m-%d") && $stargazers >= 2' then sort -nr stargazers list.csv > goodlist.csv
peterc / 3b.rb
Last active Dec 7, 2021
advent of code day 3 part 2
View 3b.rb
lines = File.readlines("3.txt")
def dl(lines, m)
12.times do |pos|
rs = { |s| s[pos] }.tally
.sort_by { |k, v| [v * m, k.ord * m] }! { |l| l[pos] == rs[1][0] }
break lines.first.to_i(2) if lines.size == 1
# 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 / 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 / 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')
times.times do
puts text.gsub(/\w+/) { |word| { |realword|

Ten seconds to ponder if a thread is worth it


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 / 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 / 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_REGION=[region of your object storage bucket]
peterc / aoc9.rb
Created Dec 9, 2020
Advent of Code 2020 Day 9 in Ruby
View aoc9.rb
nums = $<
w = 25
w.upto(nums.length - 1) do |i|
p nums[i] if nums[i-w, w].combination(2)
.all? { |x| x != nums[i] }
w.times do |cw|