Skip to content

Instantly share code, notes, and snippets.

View alh13's full-sized avatar

Adrian Hosey alh13

View GitHub Profile
@alh13
alh13 / openssl-cheatsheet
Created February 6, 2013 17:28
openssl commands for certificate manipulation
Generate a key:
openssl genrsa 2048 > <hostname>.key
Generate a CSR:
openssl req -new -key <hostname>.key -out <hostname>.csr
Generate a self-signed cert:
openssl req -new -x509 -nodes -days 365 -sha1 -key <hostname>.key > <hostname>.crt
@alh13
alh13 / gist:3888844
Created October 14, 2012 15:01
Enable TC-Optimization in Ruby
# https://speakerdeck.com/u/jeg2/p/10-things-you-didnt-know-ruby-could-do
RubyVM::InstructionSequence.compile_option = { :tailcall_optimization => true,
:trace_instruction => false }
eval <<end
def factorial(n, result = 1)
if n == 1
result
else
@alh13
alh13 / gist:3856276
Created October 9, 2012 02:44
git-merge branch A into branch B so that B becomes EXACT copy of A
git merge --no-commit && git checkout other-branch -- . && git commit
### https://twitter.com/adymitruk/status/69479850846593024
# We needed this once after some intense debugging on the staging branch. We knew
# staging was correct and wanted to merge staging -> production and be sure that
# prod branch never "won" any conflicts
@alh13
alh13 / gist:3829062
Created October 3, 2012 19:04
python smtpd for dev/test
python -m smtpd -n -c DebuggingServer localhost:1026
@alh13
alh13 / perl-safeticks.pl
Created June 22, 2012 02:26
extra-careful subprocesses in Perl
# Here's an idiom to spawn a subprocess and capture its output, without fear of
# being attacked by shell metachars
# (Perl's backtick operator spawns a shell)
sub safeticks {
my $retval = '';
my $line;
my $pid;
die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
if ($pid) { # parent