Skip to content

Instantly share code, notes, and snippets.

View johnl's full-sized avatar

John Leach johnl

View GitHub Profile

Keybase proof

I hereby claim:

  • I am johnl on github.
  • I am johnl (https://keybase.io/johnl) on keybase.
  • I have a public key whose fingerprint is 4B19 9EC6 F538 7248 5B97 3C7A CCFF 06B7 5C06 D153

To claim this, I am signing this object:

@johnl
johnl / config.ru
Last active June 17, 2016 10:20 — forked from damien/config.ru
A simple rack middleware to debug the request pipeline
# Usage example
require "inspect_env"
use InspectEnv
run GenericSinatraApp
@johnl
johnl / send_twilio_sms.sh
Created May 12, 2016 21:38
bash script to send twilio sms
#!/bin/bash
# Script to send an SMS alert via Twilio.
# handy for nagios.
# supports proper Twilio API keys, so you don't have to share your user token
# https://www.twilio.com/docs/api/rest/request
function printHelpAndExit {
echo "usage: ./`basename $0` -a \"twilio account sid\" -u \"twilio api key sid\" -p \"twilio api key secret\" -s \"sender number\" -d \"destination number\" -m \"message\"]"
echo "optionally add -l to enable logging to syslog using the logger command"
echo "example: ./`basename $0` -a \"ACxxxxxxxxxxxxxxxxxxxx\" -u \"SKxxxxxxxxxxxxxxxx\" -p \"xxxxxxxxxxxxxxxx\" -s \"+4401274000000\" -d \"+4401130000000\" -m \"HTTP Timed out after 10 seconds\""
@johnl
johnl / gist:4c7e51b8bc20ee4bf07e
Created June 2, 2015 12:17
Hacky patch to unicorn to log process ram use after each request
class Unicorn::HttpServer
alias process_client_orig process_client
undef_method :process_client
def process_client(client)
process_client_orig(client)
rss = `ps -o rss= -p #{Process.pid}`.chomp.to_i / 1024
puts "Unicorn #{Process.pid}, #{request.env['REQUEST_METHOD']} #{request.env['REQUEST_PATH']} using #{rss}M"
end
end
@johnl
johnl / scsi-log-parser.rb
Created May 13, 2015 15:30
script to parse Linux scsi command logs
#!/usr/bin/ruby
# Parses linux scsi command logs
# http://www.seagate.com/staticfiles/support/disc/manuals/scsi/100293068a.pdf
# give this program itself as input to test
# DE AD BE EF == 3735928559
# CA FE == 51966
# CDB: Write(10): 2a 08 DE AD BE EF 00 CA FE 00
@johnl
johnl / screenshot.sh
Last active August 29, 2015 14:14
Screenshot taker/uploader
#!/bin/bash
# Takes a screenshot, uploads via scp, puts url on the clipboard
# Edit the code to set the scp destination and url format
#
# Bind it to a gnome keyboard shortcut for speedy screen sharing
#
# Ridiculously this needs bash, gnome-screenshot, xclip, scp, notify-send, sha256sum AND Ruby
set -e
@johnl
johnl / cloud-init-growpart-config
Created March 24, 2014 15:46
Cloud-init conifg to disable partition growing
#cloud-config
growpart:
mode: off
@johnl
johnl / basic.json
Last active January 3, 2016 08:49
elastic search analyzer examples for email addresses
# curl -XGET 'localhost:9200/test/_analyze?pretty=true&analyzer=standard' -d 'john.smith@example-one.com'
{
"tokens" : [ {
"token" : "john.smith",
"start_offset" : 0,
"end_offset" : 10,
"type" : "<ALPHANUM>",
"position" : 1
}, {
"token" : "example",
@johnl
johnl / srv-5ai7t.log
Last active December 25, 2015 17:59
coreos etcd cluster bootstrap failure
-- Logs begin at Wed 2013-10-16 23:08:37 UTC, end at Wed 2013-10-16 23:12:45 UTC. --
Oct 16 23:09:05 srv-5ai7t systemd[1]: Starting etcd...
Oct 16 23:09:05 srv-5ai7t systemd[1]: Started etcd.
Oct 16 23:09:05 srv-5ai7t etcd-bootstrap[649]: trying 10.242.48.122:7001
Oct 16 23:09:05 srv-5ai7t etcd-bootstrap[649]: + exec /usr/bin/etcd -d /var/lib/etcd -f -cl 0.0.0.0 -n 10.241.16.190 -c 10.241.16.190:4001 -s 10.241.16.190:7001 -sl 0.0.0.0 -C 10.242.48.122:7001
Oct 16 23:09:05 srv-5ai7t etcd-bootstrap[649]: [etcd] Oct 16 23:09:05.307 INFO | Wrote node configuration to '/var/lib/etcd/info'
Oct 16 23:09:05 srv-5ai7t etcd[649]: Wrote node configuration to '/var/lib/etcd/info'
Oct 16 23:09:05 srv-5ai7t etcd-bootstrap[649]: [etcd] Oct 16 23:09:05.312 INFO | etcd server [name 10.241.16.190, listen on 0.0.0.0:4001, advertised url http://10.241.16.190:4001]
Oct 16 23:09:05 srv-5ai7t etcd[649]: etcd server [name 10.241.16.190, listen on 0.0.0.0:4001, advertised url http://10.241.16.190:4001]
Oct 16 23:09:05 srv-5a
@johnl
johnl / gist:6592391
Created September 17, 2013 10:06
ruby shellwords library examples
irb(main):001:0> require 'shellwords'
=> true
irb(main):002:0> 'once upon "a time" there was\ a\ giant'.shellsplit
=> ["once", "upon", "a time", "there", "was a giant"]
irb(main):003:0> puts "one upon a time there was a giant & 'her dog' `hack`".shellescape
one\ upon\ a\ time\ there\ was\ a\ giant\ \&\ \'her\ dog\'\ \`hack\`
irb(main):004:0> ["ls", "/home/john/secret stuff/"].shelljoin