Skip to content

Instantly share code, notes, and snippets.

var page = require('webpage').create(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 1280, height: 1024 };
@neilellis
neilellis / SnapitoControlConfig.kt
Last active January 2, 2016 09:19
A little Kotlin
package com.cazcade.snapito.control.impl
import com.cazcade.snapito.control.api.Infrastructure
import com.cazcade.snapito.control.api.MachineState.*
import com.cazcade.snapito.control.api.MachineGroupState.*
import com.cazcade.snapito.control.api.Action.*
import com.cazcade.snapito.control.api.GroupAction.*
import com.cazcade.snapito.control.api.Controller
import com.cazcade.snapito.control.api.MachineGroup
import net.schmizz.sshj.SSHClient
fun String.on(host: String? = "localhost", user: String = "root", retry: Int = 3): String {
val ssh: SSHClient = SSHClient();
ssh.addHostKeyVerifier { a, b, c -> true };
for ( i in 1..retry) {
try {
ssh.connect(host);
return ssh use {
ssh.authPublickey(user);
import net.schmizz.sshj.SSHClient
import java.io.File
fun File.scp(host: String = "localhost", user: String = "root", path: String = "~/", retry: Int = 3) {
val ssh: SSHClient = SSHClient();
ssh.addHostKeyVerifier { a, b, c -> true };
for ( i in 1..retry) {
try {
@neilellis
neilellis / kill_tree.sh
Last active August 29, 2015 14:02
Kill a process tree
#!/bin/bash -eu
#From http://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes?lq=1
#See that URL for alternative methods which don't require pstree
function kill_tree() {
#$1 is the name of the process, i.e. the file that was executed
readonly gpid=$(pgrep -o $1)
#Now $gpid is the group id of all the sub processes
if [[ ! -z $gpid ]]
@neilellis
neilellis / do_to_cf.sh
Last active August 29, 2015 14:05
Use cfcli to sync DigitalOcean host names with Cloudflare
#!/bin/bash -eu
convert() {
while read line
do
mc=$(echo $line | cut -d' ' -f1)
if echo $mc | grep $1
then
ip=$(echo $line | cut -d':' -f2 | cut -d',' -f1)
cfcli addrecord -t A $mc $ip || cfcli editrecord -t A $mc $ip
function errexit() {
local err=$?
set +o xtrace
local code="${1:-1}"
echo "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status $err"
# Print out the stack trace described by $function_stack
if [ ${#FUNCNAME[@]} -gt 2 ]
then
echo "Call tree:"
for ((i=1;i<${#FUNCNAME[@]}-1;i++))

Keybase proof

I hereby claim:

  • I am neilellis on github.
  • I am neilellis (https://keybase.io/neilellis) on keybase.
  • I have a public key whose fingerprint is 0ACC 8350 1CAB 2EC3 A09A 8086 EBDD DCB1 AAAF 22CE

To claim this, I am signing this object:

@neilellis
neilellis / obtain_subnet_address.sh
Last active August 29, 2015 14:06
Create a subnet for this host to use in zettio/weave
#!/bin/bash -eu
#apt-get install -y jq
host_ip=$1
#Check to see if we have a cached session for this machine and if it is still valid
if [ -f ~/.consul_subnet_session ] && [[ -n $(< ~/.consul_subnet_session) ]] && [[ $(curl "http://localhost:8500/v1/session/info/$(< ~/.consul_subnet_session)") != null ]]
then
session=$(< ~/.consul_subnet_session)
else
@neilellis
neilellis / therapist.sh
Last active August 29, 2015 14:06
Gets rid of shellshock on Digital ocean + Ubuntu by running security updates in parallel - requires tugboat to be installed first.
#!/bin/bash -eu
function fixIt() {
ip=$1
if ssh -o "StrictHostKeyChecking no" root@${ip} "env X='() { (a)=>\' bash -c \"echo date\"; cat echo" | grep 2014
then
ssh -o "StrictHostKeyChecking no" root@${ip} "apt-get install -y unattended-upgrades; apt-get update; unattended-upgrades; rm echo"
else
echo $ip passed
fi