Skip to content

Instantly share code, notes, and snippets.

View apchamberlain's full-sized avatar

Alex Chamberlain apchamberlain

  • Between jobs... hire me!
  • Columbia County, OR
View GitHub Profile
@apchamberlain
apchamberlain / instantwebservers.md
Last active July 16, 2018 20:47
One-line web servers

Instant Webservers! Just add electrons!

All these run on localhost:8000 unless otherwise noted and serve the index.html file in the current directory in an insecure session, i.e, open http://127.0.0.1:8000 in any browser. All except Python's SimpleHTTPServer allow multiple simultaneous client connections. The Node http-server module is the most robust although none of these is suitable for production. The true one-liners (all but Node) should all run without any dependencies on a standard OS X or Linux install.

Python 2

    python -m SimpleHTTPServer

or

    python2 -m SimpleHTTPServer
@apchamberlain
apchamberlain / viagra.pl
Created June 9, 2015 07:01
a horrible horrible hack
#!/usr/bin/env perl
# usage: script 'command' 'time'
# time format must be: 14/01/09 21:21
my $printprefix = 'VIAGRA: ';
my $silent = (@ARGV[2] eq '--silent' || @ARGV[2] eq '-s')? 1 : 0;
use Time::Piece;
my $start = Time::Piece->new;
@apchamberlain
apchamberlain / csv2json.rb
Created April 29, 2015 22:35
Simple CSV-to-JSON with no external dependencies other than the default OS X Ruby install. Because I keep forgetting how to do this. Pipe through `jq` for prettier output.
#!/usr/bin/env ruby
require 'json'
# Beware, this doesn't support embedded escaped commas, but it does
# handle quotes around field values with spaces in them correctly.
class Array
def to_h()
@apchamberlain
apchamberlain / dotsshslashconfig
Created April 23, 2015 21:10
SSH config for optimum TRAMP
Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
Compression yes
# Also make sure that .bashrc is empty or minimal on the destination, and sshd is as new as possible
@apchamberlain
apchamberlain / samplePPgen.pl
Last active September 9, 2015 14:19
Produce manifest code for testing Puppet with a catalog of 'n' classes with 'm' resources each.
#!/usr/bin/env perl
# Produce test code for 'n' classes with 'm' resources each for site.pp
#
# Usage: ./samplePPgen CLASSCOUNT RESOURCECOUNT NODENAME
# e.g., ./samplePPgen 1 1000 foo # 1 class with 1000 resources on node foo
# e.g., ./samplePPgen 1000 2 # 1000 classes with 2 resources each on default
#
# If parameters are omitted, the default output is 10 classes with 10
# file resources each, on the default node (meaning all nodes if you
@apchamberlain
apchamberlain / service-completion.bash
Last active December 24, 2015 15:19
bash completion for 'service' command on Linux
# Add bash completion for services: it tries to complete the service you want
# based on the output of "service --status-all"
# Source this as a separate file from your .bash_profile or just copy and paste into it
# Inspired by http://en.newinstance.it/2011/06/30/ssh-bash-completion/
__service_known_services() {
service --status-all |awk '{print $1}'
}