Skip to content

Instantly share code, notes, and snippets.

@gray
gray / gist:305973
Created February 16, 2010 21:47
ensure single running instance of a shell script
if command -v flock > /dev/null 2>&1; then
flock -nx "$LOCK" || exit
else
trap 'rm -f "$LOCK"; exit' INT QUIT TERM
shlock -f "$LOCK" -p $$ || exit
trap 'rm -f "$LOCK"; exit' EXIT
fi
@gray
gray / gist:306053
Created February 16, 2010 23:02
run a command with a timeout
# Prefer the timeout program from GNU coreutils.
if command -v timeout > /dev/null 2>&1; then
:
elif command -v gtimeout > /dev/null 2>&1; then
timeout () {
gtimeout $@
}
else
# From "Beginning Portable Shell Scripting", 2008.
timeout () {
@gray
gray / List all youtube videos for a user
Created March 29, 2010 16:47
List all youtube videos for a user
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXML;
my $user = shift || die "No user specified\n";
my $feed_url = (
"http://gdata.youtube.com/feeds/api/users/$user/uploads?" .
'max-results=50'
@gray
gray / benchmark-process-size.pl
Created July 7, 2010 19:45
Benchmark process size
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use GTop;
use Proc::ProcessTable;
my $gtop = GTop->new;
my $ptable = Proc::ProcessTable->new(cache_ttys => 1);
@gray
gray / gist:523860
Created August 14, 2010 02:10
Flush logs from Ambit cable modem
# Clear the cable modem logfile from memory to prevent slowdowns.
14 */2 * * * curl -sS -u admin:cableroot --basic -d SnmpClearEventLog=2 http://192.168.100.1/goform/CmEventLog
@gray
gray / gist:526263
Created August 16, 2010 02:11
Switch Tor circuits (generate new identity)
# Switch Tor circuits (generate new identity).
printf "AUTHENTICATE %s\nSIGNAL NEWNYM\nQUIT\n" \
$(xxd -c32 -ps ~/.tor/control_auth_cookie) | nc localhost 9051
@gray
gray / find-imdb-classics.pl
Last active February 9, 2017 18:58
scrape imdb to get list of best classics
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Carp::Always;
use List::Util qw(any none);
use URI;
use URI::QueryParam;
use Web::Scraper::LibXML;
@gray
gray / gist:895678
Created March 31, 2011 01:46
Find specific XS distribution examples
#!/usr/bin/env perl
use 5.012;
use warnings;
use CPAN::DistnameInfo;
use CPAN::Mini::Visit;
use File::Find::Rule;
use File::pushd;
CPAN::Mini::Visit->new(
@gray
gray / http-proxy.pl
Created November 5, 2012 18:26
Filtering HTTP Proxy
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent::HTTP;
use AnyEvent::HTTP::Socks;
use AnyEvent::HTTPD;
use URI;
# Default is 4 connections per host.
$AnyEvent::HTTP::MAX_PER_HOST = 8;
@gray
gray / autocomplete-on.user.js
Last active February 9, 2021 10:46
Autcomplete On - Greasemonkey extension
// ==UserScript==
// @name Autocomplete On
// @namespace http://gist.github.com/gray
// @description Undo the disabling of autocomplete on forms and inputs.
// @include *
// ==/UserScript==
// Note: other solutions on userscripts.org don't properly handle dynamically
// inserted widgets. This solution uses the new MutationObserver DOM API.