Skip to content

Instantly share code, notes, and snippets.

@shoan
shoan / halt_all_vagrant.sh
Last active March 16, 2017 06:40
Halt all virtualbox vagrant machines
#!/bin/bash
for v in `vagrant global-status |grep virtualbox|grep running|awk '{print $1}'`;
do
vagrant halt $v;
done;
@shoan
shoan / vagrant.py
Last active September 30, 2016 03:52 — forked from lorin/vagrant.py
Vagrant dynamic inventory script for Ansible
#!/usr/bin/env python
# Adapted from Mark Mandel's implementation
# https://github.com/ansible/ansible/blob/devel/plugins/inventory/vagrant.py
import argparse
import json
import paramiko
import subprocess
import sys
@shoan
shoan / beautiful_idiomatic_python.md
Created April 27, 2016 01:34 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@shoan
shoan / git-hook_pre-commit_lint.php
Created October 15, 2015 04:05 — forked from nfreear/git-hook_pre-commit_lint.php
Git pre-commit hook to run PHP lint, check for [CR] Mac-only line endings..
#!/C/xampp/php/php
<?php
#!/usr/bin/env php
/**
* Git pre-commit hook to run php lint.
*
* Git hooks on Windows: Ensure that the path to PHP is added to the %PATH% variable, and run `git commit` via the Bash shell.
*
* @copyright 2012-04-30 N.D.Freear.
* @license MIT
SetEnvIf REMOTE_ADDR "(.+)" CLIENTIP=$1
SetEnvIf X-Forwarded-For "^([0-9.]+)" CLIENTIP=$1
LogFormat "%{CLIENTIP}e %D %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" trueip_combined
@shoan
shoan / gist:6681025
Last active December 23, 2015 19:09
Archive only files changed in the last commit
#gnutar
git --no-pager diff --name-only HEAD~1.. |tar jcvf ~/temp/file.tbz2 -T - --null
#bsdtar
git --no-pager diff --name-only HEAD~2.. |tar jcvf ~/temp/file.tbz2 -T -
@shoan
shoan / gist:6412159
Created September 2, 2013 12:05
Get ip addresses that have hit more than 1000 times
time awk '{!a[$2]++}END{for(i in a) if ( a[i] >1000 ) print a[i],i }' access_log
@shoan
shoan / hack.sh
Created April 2, 2012 08:55 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@shoan
shoan / command.sh
Created October 29, 2011 17:35 — forked from felixge/command.sh
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me: