Skip to content

Instantly share code, notes, and snippets.

@antiboredom
antiboredom / index.html
Created December 15, 2014 16:36
A simple example showing how to save animated gifs from p5.js sketches, using https://github.com/jnordberg/gif.js
<html>
<head>
<script src="gif.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.3.11/p5.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.3.11/addons/p5.dom.js"></script>
<script src="sketch.js"></script>
</head>
<body>
<p>First, allow camera access.<p><p>Then click once to start recording, and another time finish recording and make a gif.</p>
</body>
@antiboredom
antiboredom / silences.py
Created October 5, 2020 19:07
Create a supercut of a video using only the quiet bits
import argparse
import re
import os
import subprocess
from moviepy.editor import VideoFileClip, concatenate_videoclips
def get_silences(filename, db, duration):
args = "ffmpeg -nostats -i {} -af silencedetect=noise={}dB:d={} -f null -".format(
filename, db, duration
@antiboredom
antiboredom / table.py
Created October 28, 2021 21:17
print a text file in columns
#!/usr/local/bin/python3
import sys
from rich.console import Console
from rich.table import Table
import argparse
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
set-option -g default-terminal "screen-256color"
# set-option -g default-terminal "xterm-256color"
# History
set -g history-limit 10000
# Start windows at 1 rather than 0
set -g base-index 1
# bind-key -n M-/ copy-mode
@antiboredom
antiboredom / serve.sh
Last active October 16, 2020 21:51
Create a static http server on an open port between 8000 and 9000. Just add to your bash_profile...
# stick this in your .bash_profile to create
# a static http server on an open port (btw 8000 and 9000)
# should work in mac and linux
function serve() {
# find an open port, from https://unix.stackexchange.com/a/358101
local openport=$(netstat -aln | awk '
$6 == "LISTEN" {
if ($4 ~ "[.:][0-9]+$") {
split($4, a, /[:.]/);
@antiboredom
antiboredom / ve.sh
Created February 27, 2020 16:56
Createa virtual environment or activate an existing one.
alias ve="if [ -d venv ]; then source venv/bin/activate; else virtualenv venv -p python3;source venv/bin/activate; fi"
@antiboredom
antiboredom / transcribe.js
Last active November 22, 2019 01:26
Transcribe video/audio using IBM Watson
var request = require('request');
var fs = require('fs');
var sox = require('sox');
var spawn = require('child_process').spawn;
var WATSON_USER = '';
var WATSON_PASS = '';
var url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize';
// from https://www.nsftools.com/misc/SearchAndHighlight.htm
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) {
// the highlightStartTag and highlightEndTag parameters are optional
if (!highlightStartTag || !highlightEndTag) {
highlightStartTag = "<span style='color:blue; background-color:yellow;'>";
highlightEndTag = "</span>";
}
// find all occurences of the search term in the given text,
@antiboredom
antiboredom / autocomplete.py
Created February 6, 2015 02:38
scrapes google autocomplete suggestions
import sys
import urllib
import time
import xml.etree.ElementTree as ET
chars = 'abcdefghijklmnopqrstuvwxyz'
q = sys.argv[1]
url = 'http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=' + urllib.quote(q.strip() + ' ')
def suggest(url):
@antiboredom
antiboredom / sun.pde
Created September 8, 2013 22:38
Sun sketch for ICM week 1
int rays = 24;
void setup() {
size(640, 460);
colorMode(HSB, 100, 100, 100, 100);
noStroke();
drawSun();
}
void draw() {}