Skip to content

Instantly share code, notes, and snippets.

View benjaminoakes's full-sized avatar

Ben Oakes benjaminoakes

View GitHub Profile
# Purpose: Find all the duplicate files recursively and delete them
# Recommended: review what will be deleted before running with `xargs rm`
find . -type f -exec md5sum {} \; > MD5SUMS
# Assumption: no whitespace in filenames
cat MD5SUMS | sort | awk '{ if (prev_md5==$1) { print $2 }; prev_md5=$1 }' | xargs rm
# Remove partially downloaded files that have filenames repeated in two different directories
<!DOCTYPE html>
<html>
<head>
<script>
let style = document.createElement("style")
style.innerHTML = ".noscript { display: none }"
document.head.appendChild(style)
</script>
</head>
@benjaminoakes
benjaminoakes / clock.js
Created April 23, 2021 03:16
Preact and HTM example
import { html, Component, render } from 'https://unpkg.com/htm/preact/standalone.module.js';
class Clock extends Component {
constructor() {
super()
this.tick()
}
componentDidMount() {
#!/bin/bash
# Based on https://gist.githubusercontent.com/chinmaya-n/cff02f1277c811deab2e550f2aad9967/raw/5d5511b6b61cb643f207f302fd370522e06948fd/bitbucket_to_github.sh
# Slightly manual but better than no automation
set -o errexit
# verify for two script params
if [ "$#" -ne 1 ]; then
echo "Need two arguments."
echo "Usage: ./bitbucket_to_github.sh <bitbucket_url>"
# Simulates a race condition for testing. The first try always fails, the second try succeeds.
#
# Abstract example:
#
# RaceConditionCollection.new(active_record_model.associated_collection)
#
# Concrete example:
#
# RaceConditionCollection.new(blog_post.comments)
class RaceConditionCollection
@benjaminoakes
benjaminoakes / oneline.rb
Created August 24, 2019 02:41
Google Tasks to text
require 'json'
json=JSON.parse(File.read('Tasks.json'))
puts json['items'].map { |l| "\n\n**" + l['title'] + "**\n\n" + l['items'].reject { |t| t['deleted'] }.reject { |t| t['status'] == 'completed' }.map{|t| t['notes'] ? (t['notes'].match(/^http/) ? "[#{t['title']}](#{t['notes']}) #{t['due']}" : "#{t['title']} (#{t['notes']}) #{t['due']}") : "#{t['title']} #{t['due']}" }.join("\n")}
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 / convert.sh
Created April 7, 2019 21:41
Convert wav files in current directory to mp3, spx, vorbis, opus
# convert_wavs_to() {
# extension="$1"
#
# if [ ! -d "$extension" ]; then
# mkdir -p "$extension"
#
# for f in *.wav; do
# ffmpeg \
# -i "$f" \
# "$extension/$(basename "$f" .wav).$extension"
// ==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==
<?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>