Skip to content

Instantly share code, notes, and snippets.

View benjaminoakes's full-sized avatar

Ben Oakes benjaminoakes

View GitHub Profile
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="git@gist.github.com:$gist_id.git"
git clone $clone_url
done
@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.
// ==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.');
<!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>
@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>"))
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..."
# 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
@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;
@benjaminoakes
benjaminoakes / problem_3.js
Last active March 22, 2017 14:31
Project Euler
function find(start, finish, qualifier) {
var index;
for (index = start; start <= finish; index++) {
if (qualifier(index)) {
return index;
}
}
}
@benjaminoakes
benjaminoakes / Dockerfile
Created January 10, 2017 21:04
Docker: use readline vi mode
# Set up dotfiles. (It would be amazing if there were an environment variable for this instead!)
RUN printf "set editing-mode vi\nset keymap vi" > ~/.inputrc
RUN printf "bind -v" > ~/.editrc