Skip to content

Instantly share code, notes, and snippets.

@benjaminoakes
benjaminoakes / count_all_tables.sql
Created March 30, 2017 18:39
Count all tables (Postgres)
SELECT schemaname, relname, n_live_tup FROM pg_stat_user_tables ORDER BY n_live_tup DESC;
# Debugging helper, useful while fixing N+1 problems
# Based on https://gist.github.com/crazymykl/b526e0ed6b285b3c4e77
def count_queries(log: false, &block)
ActiveRecord::Base.logger = Logger.new(STDOUT) if log
query_count = 0
increment_count = -> (*) { query_count += 1 }
ActiveSupport::Notifications.subscribed(increment_count, 'sql.active_record', &block)
query_count
end
loop do
print 'Listening... '
utterance = gets
command = utterance.strip.sub(/\.$/, '').downcase.split(/\s+/).first
case command
when 'say'
puts utterance.sub(/^say/i, '')
when 'exit', 'quit'
puts "Exiting..."
@benjaminoakes
benjaminoakes / rss_item.js
Last active May 25, 2017 15:39
Simple RSS item bookmarklet
void(prompt('Copy',"<item><title>"+document.title+'</title><guid%20isPermaLink="true">'+document.location+"</guid><link>"+document.location+"</link></item>"))
<!DOCTYPE html>
<html>
<head>
<title>Vue.js Sandbox</title>
</head>
<body>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
<button @click="checkAll">Check all</button>
// ==UserScript==
// @match https://www.google.com/calendar/*
// ==/UserScript==
window.alert = function (s) {
console.log(s);
};
console.log('Disabling Google Calendar javascript alerts. They are instead routed to this console.');
@benjaminoakes
benjaminoakes / errors.txt
Created July 28, 2017 16:31
BeOS (NetPositive) haiku error messages
Not a pretty sight
When the web dies screaming loud
The site is not found.
Morning and sorrow
404 not with us now
Lost to paradise.
gist_urls_file=$(mktemp)
gist -l | sed 's/ .*$//' > $gist_urls_file
cat $gist_urls_file | while read -r line; do
gist_url="$line"
gist_id="$(echo $gist_url | sed 's|https://gist.github.com/||')"
clone_url="[email protected]:$gist_id.git"
git clone $clone_url
done
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Asimov - Foundation Trilogy</title>
<description>Isaac Asimov's Foundation Trilogy in BBC Audio from the Internet Archive</description>
<item>
<title>Part 1 of 8</title>
<enclosure url="http://www.archive.org/download/IsaacAsimov-TheFoundationTrilogy/IsaacAsimov-Foundation1Of8_64kb.mp3" type="audio/mpeg"/>
</item>
// ==UserScript==
// @name Google Push to Talk
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Hold down the spacebar to unmute the mic in Google Meet; tapping the spacebar toggles mute.
// @author Marc Reynolds (github.com/marcreynolds)
// @match https://meet.google.com/*
// @updateUrl https://gist.github.com/marcreynolds/6c629eaf8bfe87986ebe90ebea7daf85/raw/google-meet-spacebar.user.js
// @grant none
// ==/UserScript==