Skip to content

Instantly share code, notes, and snippets.

View peterc's full-sized avatar
🏠
Working from home

Peter Cooper peterc

🏠
Working from home
View GitHub Profile
@peterc
peterc / watch_page
Last active May 1, 2019 16:19
Watch a Web page for changes and show the differences
#!/bin/bash
# usage:
# chmod +x watch_page
# ./watch_page
while [ 1 ]
do
if [ -e /tmp/latest.html ]; then
cp /tmp/latest.html /tmp/previous.html
@peterc
peterc / playmod.rb
Last active April 5, 2019 13:20
CLI-based module music player that uses VLC
#!/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
peterc / itemrss.rb
Created March 29, 2019 23:15
Cooperpress issues to item-based RSS
require 'open-uri'
require 'json'
require 'nokogiri'
require 'rss'
URL = "https://javascriptweekly.com/issues/latest.json"
issue_data = JSON.parse(open(URL).read)
issue = Nokogiri::HTML(issue_data['xml_body'])
@peterc
peterc / subdocuments.md
Last active March 2, 2019 10:56
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
peterc / s4d.rb
Last active February 27, 2019 13:03
Turns a11y-style text back into English. Or tries to, anyway.
# 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')
.map(&:downcase)
.map(&:chomp)
times.times do
@peterc
peterc / get_sizes.sql
Last active February 2, 2021 02:52
Get the size of different tables and other relations in a PostgreSQL database
SELECT
schema_name, rel_name, table_size,
pg_size_pretty(table_size) AS size
FROM (
SELECT
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
peterc / pg_available_extensions.txt
Created February 14, 2019 18:40
Which Postgres extensions are available on DigitalOcean's new managed PostgreSQL service?
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 |
@peterc
peterc / IDEHISTORY.TXT
Last active November 2, 2020 23:33
A list of seminal or otherwise notable IDEs or "development environments" by year.
1963 - JOSS (JOHNNIAC Open Shop System)
1964 - Dartmouth BASIC
1966 - CAL for Project Genie Time Sharing System
1974 - OLIVER by Kenneth Dakin
1975 - Maestro I
1980 - dBase
1980 - Smalltalk
1981 - IBM Advanced BASIC (BASICA)
1983 - IBM Logo
1983 - GW-BASIC
@peterc
peterc / serverless_rss_validity.js
Last active August 28, 2018 20:49
An ES6 variant of a serverless function written in Python..
const fetch = require('node-fetch');
const parseString = require('xml2js').parseString;
const util = require('util');
const hostnames = ["react.statuscode.com", "javascriptweekly.com", "nodeweekly.com"];
function checkValidity(url) {
return fetch(url)
.then(res => res.text())
.then(resultText => promisify(parseString)(resultText))
@peterc
peterc / serverless_rss_validity.py
Created August 28, 2018 13:57
AWS Lambda function to check RSS feed validity using W3C's API
import json
import requests
import os
import sys
from xml.dom.minidom import parse, parseString
hostnames = ["react.statuscode.com", "javascriptweekly.com", "nodeweekly.com"]
def checkValidity(url):
response = requests.get(url)