Skip to content

Instantly share code, notes, and snippets.

@Grynn
Grynn / fakeip.sh
Created May 6, 2016 14:10
add private ips to a droplet
#!/bin/bash
set -e
modprobe dummy
lsmod | grep dummy
ip link set name eth2 dev dummy0
ip addr add 192.168.100.199/24 brd + dev eth2 label eth2:0
ip addr add 192.168.100.200/24 brd + dev eth2 label eth2:1
ip addr add 192.168.100.201/24 brd + dev eth2 label eth2:2
@Grynn
Grynn / ls-ip
Created April 26, 2016 17:51
List IP addresses
ip addr show | grep "scope global" | egrep -o "inet ([0-9\.]+){4}" | cut -d' ' -f2
#install nodejs > 5.0
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -qy nodejs
@Grynn
Grynn / free_port.php
Last active January 30, 2016 03:24
Show next available port
<?php
/* Create a socket, bind to port 0, kernel assigns a free port. Read port number, close socket
* This works *mostly* because the kernel tries hard to avoid re-using ports. So the port returned
* by this function should remain available for a bit after this process has terminated.
*/
echo "Available local port: " . getFreeLocalTcpPort();
function getFreeLocalTcpPort() {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@Grynn
Grynn / .gitconfig
Created September 16, 2015 21:59
My .gitconfig
[alias]
st = status
co = checkout
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
br = branch -v
dt = difftool --dir-diff
gshow = !f() { git difftool --dir-diff $1^..$1; }; f
llg = !f() { git lg $(git branch --column | tr -d '*' | tr -s ' '); }; f
[user]
@Grynn
Grynn / locale-fix.sh
Last active August 29, 2015 14:27
Fix Ubuntu locale issues
#!/bin/bash
#paranoid (in case the langguage-pack-en is not installed, which is rare)
sudo apt-get -q install language-pack-en.*
#write to /etc/default/locale
#changes only take effect after logout
sudo update-locale --reset LANG=en_US.UTF-8 LC_MESSAGES=POSIX LC_ALL=en_US.UTF-8
#generate locale files if required
#!/bin/bash
while read p; do
(svn list -R "$p" | xargs -I{} echo $p{} | tee -a allfiles.txt) &
done < repos.txt
wait #for above jobs to finish...
cat /etc/apache2/sites-available/* /etc/nginx/sites-available/* | perl -ne 'print if (!m/^\s*#/ && m/ServerName|ServerAlias/i);'
@Grynn
Grynn / lsrecent
Last active November 18, 2015 18:23
List 10 most recently modified files (in a directory tree)
#!/bin/bash
# May not work if filename have spaces
# Inspired by this answer on StackOverflow
# http://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s
find . -type f -printf '%T@ %P\n' | sort -nr | cut -d ' ' -f2- | head
## Windows Version ##
# gfind . -type f -name "clean*.php" -printf "%T@ \"%P\"\n" | gsort -nr | cut -d ' ' -f2-
# Assumes gfind = Gnu find and gsort Gnu sort
<?php
//GetPass for a website
//getpass(sitename.com) returns a XORed version of the sitename + salt
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$homeDir = realpath(getenv("USERPROFILE"));
} else {
$homeDir = realpath("~");
}
$salt = file_get_contents("$homeDir/.salt");