Skip to content

Instantly share code, notes, and snippets.

@johnholdun
johnholdun / benchmark.js
Created September 27, 2023 00:38
Benchmarking idempotent `CREATE IF NOT EXISTS` sqlite statements
import fs from 'fs'
import sqlite3 from 'sqlite3'
import { open } from 'sqlite'
const filename = './database.db'
if (fs.existsSync(filename)) {
fs.unlinkSync(filename)
}
@johnholdun
johnholdun / scrape-instagram-feed.js
Created December 15, 2021 20:50
log in to instagram in your browser, then run this in the console. use at your own risk! works as of 2021-12-15 but is likely to break!
;(async () => {
const PATH = 'https://www.instagram.com/graphql/query/'
const QUERY_HASHES = {
list: '8c2a529969ee035a5063f2fc8602a0fd',
post: '7d4d42b121a214d23bd43206e5142c8c'
}
const get = (query, args) => {
const queryParams = { query_hash: QUERY_HASHES[query], variables: JSON.stringify(args) }
@johnholdun
johnholdun / literal-club-feed.rb
Created August 20, 2021 17:31
Get a list of your updates to literal.club. There's no guarantee this will continue to work over time!
require 'date'
require 'json'
require 'net/http'
require 'uri'
# This should be your username
USERNAME = 'johnholdun'.freeze
QUERY = <<-QUERY.freeze
query getBooks($username: String) {
@johnholdun
johnholdun / scarcity.rb
Created March 10, 2021 23:32
Track Zach Gage's Scarcity. Run this every day or you risk losing it forever.
require 'date'
require 'digest'
require 'net/http'
ledger = (DATA || '').each_line.map { |l| l.strip.split(' ') }.to_h
def url_for(token)
"http://stfj.net/scarcity/#{token}"
end
@johnholdun
johnholdun / h.js
Created January 13, 2021 16:31
who needs jsx?
function h(tag, props = {}, children = null) {
if (arguments.length === 2 && props && (typeof props !== 'object' || Array.isArray(props))) {
children = props
props = {}
}
const inner = children ? [].concat(children).join('') : ''
if (!tag) {
return inner
@johnholdun
johnholdun / create_campaign.rb
Created May 11, 2019 03:20
Creates a Mailchimp campaign based on a URL. Useful if you tend to deliver your most recent blog post or whatever but aren't satisfied with the RSS campaign feature.
require 'rest-client'
require 'json'
require 'yaml'
require 'opengraph_parser'
require 'open-uri'
# Generate a new Mailchimp campaign from a page one your website. I used to use
# this with a purpose-built template in my static site generator that
# automatiacally set up my most recent post as an email, just the way I liked
# it. You'll probably need to make some changes to suit your needs but you're
@johnholdun
johnholdun / upload.rb
Created May 11, 2019 03:13
Sync your locally-generated, git-tracked static website to S3
require 'rubygems'
require 'active_support/all'
require 'date'
require 'aws-sdk'
require 'pry'
# If you have a static website that you generate locally, track with git, and
# push to S3, you can use this script to incrementally push new files to your
# bucket. It worked for me when johnholdun.com was hosted with Amazon but use it
# at your own risk!
@johnholdun
johnholdun / mastodon-parser.rb
Created April 19, 2017 16:20
Turn a Mastodon permalink URL into a one-line plain text status
require 'nokogiri'
require 'open-uri'
require 'upmark'
require 'cgi'
require 'uri'
class TootReader
ACTIVITY_NAMESPACE = 'http://activitystrea.ms/spec/1.0/'.freeze
COMMENT_TYPE = 'http://activitystrea.ms/schema/1.0/comment'.freeze
@johnholdun
johnholdun / lateset_browser_versions.rb
Created January 20, 2017 16:48
Find the latest browser versions from the caniuse db
require 'json'
require 'net/https'
require 'uri'
def latest_browser_versions
uri = URI.parse('https://cdn.rawgit.com/Fyrd/caniuse/master/data.json')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@johnholdun
johnholdun / fake-jsx.js
Created December 9, 2016 21:58
render html with javascript?
var objectToAttributes = function (object) {
var output = "";
var keyTranslations = {
className: "class",
htmlFor: "for"
};
Object.keys(object).forEach(function (key) {
var value = object[key];