Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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);
#install nodejs > 5.0
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -qy nodejs
@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
@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

Deployment Note

To deploy code you need SSH access to the server on which code is to be deployed. In particular the server need not have any private or deployment keys which give it access to github. The server merely needs to be configure with public keys.

Directory structure on deployment server:

We assume the deployment server is Debian or a derivative like Ubuntu. By convention web-apps are deployed to /var/www/sitename.com. This will work with both Apache & Nginx.

/var/www/sitename.com:

@Grynn
Grynn / brew_me_up.sh
Created July 12, 2016 18:52
Homebrew + Cask + VSCode
#!/bin/bash
# Install Homebrew, Cask, git and some gnu tools (gsed == Gnu sed, gawk = Gnu awk, gfind = Gnu find)
set -e
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap caskroom/cask
brew install git gawk gsed gfind
brew cask install visual-studio-code
@Grynn
Grynn / queue.sh
Created November 22, 2017 18:54
flock
#!/bin/bash
> log.txt
for i in {1..10}; do
flock /root/lockfile -c "./worker $i >> log.txt" &
done;
@Grynn
Grynn / work-in-progress.js
Created May 15, 2020 15:47
Backup House Creatives
googletag.cmd.push(function() {
googletag.pubads().addEventListener('slotRenderEnded', function(e) {
let node = document.getElementById(e.slot.getSlotElementId());
if (e.isEmpty)
{
node.innerHTML = `
<p>NO CREATIVE</p>
<ul><li>Fade background?</li>
<li>Put a fake creative / hardcoded?</li>
</ul>