Skip to content

Instantly share code, notes, and snippets.

View benkant's full-sized avatar

Ben Giles benkant

View GitHub Profile
@benkant
benkant / grub
Last active February 11, 2018 23:49
/etc/default/grub for maverick
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_TIMEOUT=5
GRUB_TIMEOUT_STYLE=menu
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
@benkant
benkant / gscinit.sh
Created December 21, 2017 08:49
Google Cloud Shell init
#!/usr/bin/env bash
shopt -s expand_aliases
export EDITOR=vim
export VISUAL=vim
mkdir -p $HOME/log # TODO: GCP logging shit
STARTTIME=`date --iso-8601=minutes --utc`
@benkant
benkant / spacewindows.sh
Last active February 11, 2018 06:10
spacewindows.sh
#!/usr/bin/env bash
# TODO check we are on macOS
# TODO https://google.github.io/styleguide/shell.xml
INSTANCE_NAME=$INSTANCE_NAME
gcloud compute instances start $INSTANCE_NAME
IPADDRESS=`gcloud compute instances describe $INSTANCE_NAME | grep natIP | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])'`
printf "%s is at %s\n" $INSTANCE_NAME $IPADDRESS
# TODO check Microsoft RDP is installed
@benkant
benkant / mt940toOFX.py
Created March 1, 2018 04:39
Convert SWIFT MT940 data to OFX.
#!/usr/bin/env python
# encoding: utf-8
"""
mt940toOFX.py - Dieses Progrtamm liesst MT940 SWIFT Kontostände und konvertiert sie in OFX.
OFX wurde mit xero.com getestet.
Created by Maximillian Dornseif on 2010-06-05.
Copyright (c) 2010, 2013, 2014 HUDORA. All rights reserved.
"""
@benkant
benkant / cuda-setup.sh
Last active July 8, 2018 09:04 — forked from abdel/cuda-setup.sh
Install CUDA Toolkit v9.0 and cuDNN v7.0.5 on Ubuntu 16.04
#!/bin/bash
# Install CUDA Toolkit v9.0
# Instructions from https://developer.nvidia.com/cuda-downloads (linux -> x86_64 -> Ubuntu -> 16.04 -> deb (network))
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
CUDA_REPO_PKG="cuda-repo-ubuntu1604_9.0.176-1_amd64.deb"
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/${CUDA_REPO_PKG}
sudo dpkg -i ${CUDA_REPO_PKG}
sudo apt-get update
sudo apt-get -y install cuda-9-0
@benkant
benkant / pg-pong.py
Created April 29, 2018 14:38 — forked from etienne87/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
from chainer import cuda
import cupy as cp
import time, threading
#backend
#!/usr/bin/env bash
# slow down crazy fast gaming mouse on X
if [[ `uname` == 'Darwin' ]]; then
echo "Exiting: I don't know what this does on macOS even with XQuartz."
exit 1;
fi
FASTMOUSE=$(xinput --list --short|grep -i sabre|cut -f 2 |sed 's/id=//g')
for id in ${FASTMOUSE[@]}; do
xinput --set-prop $id "Device Accel Constant Deceleration" 10
xinput --set-prop $id "Device Accel Velocity Scaling" 10
@benkant
benkant / tumblr-dl.pl
Created October 1, 2019 09:05
Download comfy gifs from Tumblr
#!/usr/bin/env perl
# known issues:
# plenty, but
# GitHub can't render it properly: see the raw version which is `perltidy`
# hardcodes image size and only looks for gifs
# has an iterator that goes over 9000 regardless of whether it's still
# getting images or not
# it was written for a particular Tumblr, so may need tweaking for others
#
# try:
@benkant
benkant / gibson_garbage.md
Created April 28, 2020 03:23
Hacking is a art

Hacking is really just the act of finding a clever and counterintuitive solution to a problem.

The hacks found in program exploits usually use the rules of the computer to bypass security in ways never intended. Programming hacks are similar in that they also use the rules of the computer in new and inventive ways, but the final goal is efficiency or smaller source code, not necessarily a security compromise. There are actually an infinite number of programs that can be written to accomplish any given task, but most of these solutions are unnecessarily large, complex, and sloppy. The few solutions that remain are small, efficient, and neat. Programs that have these qualities are said to have elegance, and the clever and inventive solutions that tend to lead to this efficiency are called hacks. Hackers on both sides of programming appreciate both the beauty of elegant code and the ingenuity of clever hacks.

In the business world, more importance is placed on churning out functional code than on

@benkant
benkant / subtitle-clean.py
Created September 26, 2020 15:03
Extract closed caption text from a YouTube video
#!/usr/bin/env python3
# Don't call directly, called by `subtitles.sh`
"""Given an srt file, clean it up as much as possible to look like prose."""
import re
import sys
bad_words = ['-->', 'WEBVTT', 'Language: en', 'Kind: captions']