Skip to content

Instantly share code, notes, and snippets.

@peterc
peterc / subreply.css
Created Jul 13, 2020
Format subreply more nicely - use with an extension like Stylish
View subreply.css
body {
font-family: "Menlo", Monaco, Consolas, monospace;
font-size: 16px;
line-height: 24px;
}
.container {
grid-template-columns: 2fr minmax(200px, 1fr) minmax(600px, 3fr) 3fr;
}
@peterc
peterc / form-to-fetch.js
Created Jun 29, 2020
Basic implementation of turning a form into an Ajax form using Fetch API
View form-to-fetch.js
// this is very much for my specific use case
// but the general principles work anywhere
let forms = document.querySelectorAll('FORM.subscribe');
forms.forEach(form => {
form.onsubmit = function(e) {
e.preventDefault();
let formData = new FormData(e.target);
let output = e.target.querySelector('button');
@peterc
peterc / Gemfile
Created Jun 25, 2020 — forked from dhh/Gemfile
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@peterc
peterc / hn_new.py
Created Jun 15, 2020
Get a heads up when a new item hits the Hacker News front page
View hn_new.py
# Get a heads up when a new item hits the Hacker News front page
import requests
import sys
from time import sleep
from random import randint
def fetchItems():
res = requests.get("https://hacker-news.firebaseio.com/v0/topstories.json")
assert(res.status_code == 200)
@peterc
peterc / rss-to-s3.rb
Created May 23, 2020
RSS to S3 Ruby Lambda Function
View rss-to-s3.rb
require 'json'
require 'aws-sdk-s3'
require 'open-uri'
# Ideally put these in environment variables
# but since this is just for us, who cares.
BUCKET = "RETRACTED"
REGION = "RETRACTED"
def do_newsletters
@peterc
peterc / pick_a_winner.rb
Created May 2, 2020
Given a list of names, pick a winner at the terminal in a visually appealing way
View pick_a_winner.rb
require 'curses'
include Curses
init_screen
curs_set(0)
users = %w{
put twitter handles of people who enter here
}
@peterc
peterc / cdown.rb
Last active Apr 29, 2020
Basic Countdown numbers solver in Ruby
View cdown.rb
# Basic Countdown numbers solver
# Principally ported from Jake Archibald's JS solution
# at https://jsbin.com/yimejin/4/edit?js,console
def solve(nums, target)
bs = nil
nums.sort.reverse.combination(2).each do |i, j|
%I{+ - * /}.each do |op|
next if op == :* && (i == 1 || j == 1)
next if op == :/ && (j == 1 || i % j != 0)
@peterc
peterc / zapier-gmail.js
Created Apr 10, 2020
Using Zapier to check emails on Gmail and then notify us on Slack
View zapier-gmail.js
// Using Zapier to check emails on Gmail and then notify us on Slack
const slackURL = "https://hooks.slack.com/services/XXXXXXXXXXXXX";
let mb = inputData.b;
let folder = "Unknown";
if (mb.includes('CATEGORY_FORUMS')) {
folder = "Inbox (Forums)";
}
if (mb.includes('CATEGORY_PERSONAL')) {
@peterc
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'
Dotenv.load
# .env to contain:
# POSTGRES_URL
@peterc
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
You can’t perform that action at this time.