Skip to content

Instantly share code, notes, and snippets.

@jsvennevid
jsvennevid / brackets.js
Last active November 21, 2018 15:11
Algorithm to sort teams into matches appropriate for a bracketed tournament
class TournamentBracketGenerator {
static generate(teams) {
teams = teams.map((t,i) => [i,t]);
let curr = 2;
let matches = [[teams[0],teams[1]]];
do {
curr += curr;
matches = matches
.reduce((acc, curr) => acc.concat(curr))
.map(team => [team, teams[(curr-1)-team[0]]]);
@jsvennevid
jsvennevid / S50reroutedns
Last active August 29, 2015 14:21
Small script that I use to remap DNS queries on certain portions of my internal network on my ASUSWRT-based router
APPS_MOUNTED_PATH=`nvram get apps_mounted_path`
APPS_INSTALL_FOLDER=`nvram get apps_install_folder`
APPS_INSTALL_PATH=$APPS_MOUNTED_PATH/$APPS_INSTALL_FOLDER
case "$1" in
start|force-reload|restart)
killall -SIGTERM reroutedns
cd /opt/bin
./reroutedns &
;;
@jsvennevid
jsvennevid / firewall
Created February 9, 2014 11:28
Simple script to turn on/off firewall on Chromebooks
#!/bin/sh
case "$1" in
on) /sbin/iptables -P INPUT DROP
echo "Firewall has been turned on, incoming connections are no longer accepted."
shift;;
off) /sbin/iptables -P INPUT ACCEPT
echo "Firewall has been turned off, incoming connections are now accepted."
shift;;
esac
@jsvennevid
jsvennevid / volume
Last active July 6, 2018 07:13
Volume control for crouton-based linux installations on chromebooks using PulseAudio
#!/usr/bin/env bash
##
## Volume control script for PulseAudio and crouton chromebooks
##
## https://github.com/dnschneid/crouton/wiki/Keyboard
##
## v1.0: Initial release
## v1.1: Simplified mute toggle
## v1.2: Fixed (harmless) error that occured when capping max volume