Skip to content

Instantly share code, notes, and snippets.

Peter Cooper peterc

Block or report user

Report or block peterc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
peterc / hn-title-checker.rb
Created Nov 24, 2019
Monitors Hacker News for changing titles
View hn-title-checker.rb
require 'aws-sdk'
require 'open-uri'
require 'json'
require 'pg'
require 'dotenv'
# .env to contain:
peterc / stallman.txt
Created Sep 19, 2019
Stallman's "info pack"
View stallman.txt
Here's the info packet about my speeches. This information is
essential for planning my visit and speech. Please forward
it to anyone who is interested in organizing a speech for me.
Please discuss with me what the topic of this speech should be.
We need to decide it together.
My talks are not technical. The topics of free software, copyright vs
peterc / block-aws.rb
Created Aug 19, 2019
Create UFW rules to block AWS regions and services
View block-aws.rb
require 'json'
require 'open-uri'
URL = ""
REGION = "us-east"
j = JSON.parse(open(URL).read)
j['prefixes'].select { |k| k['region'].start_with?(REGION) && k['service'] == SERVICE }.each do |l|
peterc / watch_page
Last active May 1, 2019
Watch a Web page for changes and show the differences
View watch_page
# usage:
# chmod +x watch_page
# ./watch_page
while [ 1 ]
if [ -e /tmp/latest.html ]; then
cp /tmp/latest.html /tmp/previous.html
peterc / playmod.rb
Last active Apr 5, 2019
CLI-based module music player that uses VLC
View playmod.rb
#!/usr/bin/env ruby
# playmod: plays module and other audio files in a directory using vlc
# on macOS: brew cask install vlc
require 'open3'
require 'io/console'
# Keep a copy of the child VLC process's PID around to terminate it nicely
peterc / itemrss.rb
Created Mar 29, 2019
Cooperpress issues to item-based RSS
View itemrss.rb
require 'open-uri'
require 'json'
require 'nokogiri'
require 'rss'
URL = ""
issue_data = JSON.parse(open(URL).read)
issue = Nokogiri::HTML(issue_data['xml_body'])
peterc /
Last active Mar 2, 2019
Can HTML work as a format for sub-documents?

Let's say I want to create and share a document, such as a blog post that has various components:

  • meta information (author, categories, tags..)
  • a title
  • body content
  • some custom styling
  • some custom scripting

An HTML document seems like a great way to portably and easily package all of these things into one place:

peterc / s4d.rb
Last active Feb 27, 2019
Turns a11y-style text back into English. Or tries to, anyway.
View s4d.rb
# ruby s4d.rb "h3o w3d" 5
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
peterc / get_sizes.sql
Last active Mar 5, 2019
Get the size of different tables and other relations in a PostgreSQL database
View get_sizes.sql
schema_name, rel_name, table_size,
pg_size_pretty(table_size) AS size
nspname AS schema_name,
relname AS rel_name,
pg_table_size(pg_class.oid) AS table_size
FROM pg_class, pg_namespace
WHERE pg_class.relnamespace = pg_namespace.oid
peterc / pg_available_extensions.txt
Created Feb 14, 2019
Which Postgres extensions are available on DigitalOcean's new managed PostgreSQL service?
View pg_available_extensions.txt
defaultdb=> SELECT * FROM pg_available_extensions;
name | default_version | installed_version | comment
aiven_extras | 1.0.2 | | aiven_extras
plpgsql | 1.0 | 1.0 | PL/pgSQL procedural language
btree_gist | 1.5 | | support for indexing common datatypes in GiST
tcn | 1.0 | | Triggered change notifications
seg | 1.3 | | data type for representing line segments or floating-point intervals
pgrowlocks | 1.2 |
You can’t perform that action at this time.