Skip to content

Instantly share code, notes, and snippets.

View jonhoo's full-sized avatar
🤦‍♂️
Permanent 418 status code.

Jon Gjengset jonhoo

🤦‍♂️
Permanent 418 status code.
View GitHub Profile
@jonhoo
jonhoo / getElementsByClassName.min.js
Created May 11, 2012 13:37
Simple polyfill for fetching all elements on the page with the given class
"getElementsByClassName"in document||(document.getElementsByClassName=document.evaluate?function(a){var a="[contains(concat(' ', @class, ' '), ' "+a+" ')]",d="http://www.w3.org/1999/xhtml"===document.documentElement.namespaceURI?"http://www.w3.org/1999/xhtml":null,b;try{b=document.evaluate(".//*"+a,document,d,0,null)}catch(c){b=document.evaluate(".//*"+a,document,null,0,null)}return b}:function(a){for(var a=RegExp("(^|\\s)"+a+"(\\s|$)"),d=document.all||document.getElementsByTagName("*"),b=[],c=0,e=
d.length;c<e;c+=1)a.test(d[c].className)&&b.push(d[c]);return b});
@jonhoo
jonhoo / imdb-lookup.pl
Created September 18, 2012 11:03
File for looking up movie files in IMDb
#!/usr/bin/perl
use strict;
use warnings;
use IMDB::Film;
my $promptDelete = 0;
if (@ARGV > 0 and $ARGV[0] eq "-d") {
$promptDelete = 1;
shift @ARGV;
}
@jonhoo
jonhoo / cssmin
Created February 6, 2013 12:36
A very minimal CSS minifier
#!/bin/bash
cat $1 \
| tr '\r\n' ' ' \
| perl -pe 's:/\*.*?\*/::g' \
| sed \
-e 's/\s\+/ /g' \
-e 's/\([#\.:]\)\s\?/\1/g' \
-e 's/\s\?\([;{}]\)\s\?/\1/g' \
-e 's/\s\?\([,!+~>]\)\s\?/\1/g' \
-e 's/;}/}/g' \
@jonhoo
jonhoo / mp3Match.pl
Created March 5, 2013 17:40
Compare the mp3 files in multiple folders and choose which ones to keep based on bitrate, length, etc.
#!/usr/bin/perl
# Scans all directories prefixed by "-n" for mp3 files and compares them with
# mp3 files of the same name in all other given directories.
# Allows comparison of bitrate, length and size, and then selecting which to keep
use strict;
use warnings;
use Cwd qw/cwd abs_path/;
use MP3::Tag;
die "Usage: $0 folder folder -n lookupfolder -n lookupfolder\n" if @ARGV < 2;
@jonhoo
jonhoo / showoff
Created July 22, 2013 12:30
Bash function for setting up and tearing down remote tunnels
#!/bin/bash
# Remember to change USER@SERVER below to the server you want to
# show off from
showoff() {
if [[ -z $2 ]]; then
lport=80
rport=8080
else
lport=$1
rport=$2
@jonhoo
jonhoo / slicewin
Last active June 3, 2016 21:58
Script for slicing and aerosnapping X windows in an EWMH compatible WM
#!/bin/bash
if [[ $# -eq 0 ]]; then
echo "Usage: $0 top|right|bottom|left [maximized]"
exit 1
fi
active=`xprop -root _NET_ACTIVE_WINDOW | sed 's/^.*# //'`
if [[ $active == "0x0" ]]; then
echo "No active window found (_NET_ACTIVE_WINDOW == 0x0)"
@jonhoo
jonhoo / dungeon-keeper.desktop
Created February 2, 2014 14:59
Dungeon Keeper Desktop Entry on Linux
[Desktop Entry]
Name=Dungeon Keeper
Comment=Evil is Good
Exec=dosbox -conf ../dosboxDK.conf -conf ../dosboxDK_single.conf -noconsole -c exit
Icon=dungeon-keeper
Path=/home/user/.wine/drive_c/GOG Games/Dungeon Keeper Gold/DOSBOX
Terminal=false
Type=Application
Categories=Game;
@jonhoo
jonhoo / README
Created April 7, 2011 01:42
A busybox bash script for determining the progress of a copy operation
A simple script that estimates the progress, speed and probable completion time of a copy operation.
It was originally written for a QNAP NAS running busybox, but should be compatible with any busybox install.
Should also work for most Linux systems, but the options to du and df will have to be modified since the busybox uses a simplified syntax (The -m for both of them is to get the output in MB).
The script is called with the same arguments given to cp
The script estimates by using:
- Difference in df-used for speed
- Difference in du for percentage
- A combination of the above for ETC (Estimated Time to Completion)