Skip to content

Instantly share code, notes, and snippets.

View craigvantonder's full-sized avatar

Craig van Tonder craigvantonder

  • South Africa
View GitHub Profile
@craigvantonder
craigvantonder / kill-node.sh
Created March 17, 2017 23:57
Killing a node process in Ubuntu
#!/bin/bash
# http://serverfault.com/a/726024/210437
killall -KILL node
@craigvantonder
craigvantonder / flush-dns.sh
Last active February 3, 2021 04:42
Flushing the DNS in Ubuntu 16.04
#!/bin/bash
# NB: First install nscd with sudo apt-get install nscd
# run this command to flush dns cache:
sudo /etc/init.d/dns-clean restart
# or use:
sudo /etc/init.d/networking force-reload
# Flush nscd dns cache:
sudo /etc/init.d/nscd restart
@craigvantonder
craigvantonder / upload.sh
Created March 18, 2017 16:54
To SCP files from local to remote
#!/bin/bash
# Example: /home/username/Downloads/software.tar.gz
echo -n "Full path of the file to upload: ";
read fileLocation;
# Example: /var/www/mydomain/software.tar.gz
echo -n "Full path of where the file is to be saved: ";
read saveLocation;
@craigvantonder
craigvantonder / install-node-latest.sh
Created March 28, 2017 08:04
Install Node.js v7.x on Ubuntu 16.04
#!/bin/bash
# Switch to root
sudo su
# Update the server
apt-get -y update
# Install Node.js v7.x:
# https://github.com/nodesource/distributions#installation-instructions
@craigvantonder
craigvantonder / install-nginx-latest.sh
Last active March 29, 2021 14:14
Install Nginx Mainline / Stable on Ubuntu 16.04
#!/bin/bash
# https://www.nginx.com/resources/wiki/start/topics/tutorials/install/
# Switch to root
sudo su
# Add the mainline release
echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" > /etc/apt/sources.list.d/nginx.list
@craigvantonder
craigvantonder / test.php
Last active March 6, 2018 08:03
Test execution times of for and foreach in PHP
<?php
// Create fake data array of 10000 records
$max = 10000;
$rands = array();
for($i=0; $i<$max;$i++) {
$rands[$i]=mt_rand(0,$max-1);
}
$temp;
// Time foreach itteration
@craigvantonder
craigvantonder / copyByFiletype.bat
Last active March 27, 2022 10:39
Windows batch file to recursively copy all files of a specific type to an output directory
@echo off
setlocal
set DIR=C:\path\from
set OUTPUTDIR=C:\path\to
for /R %DIR% %%G in (*.jpg *.jpeg) do copy "%%G" "%OUTPUTDIR%"
@craigvantonder
craigvantonder / imagemagick-convert-images
Last active November 8, 2018 07:13
Convert images with imagemagick
mogrify -format jpg *.jpeg
@craigvantonder
craigvantonder / git-compare-directories
Last active November 8, 2018 07:13
Using git to compare two directories for differences
// https://stackoverflow.com/a/7945988/2110294
git diff --diff-filter=M --name-status --no-index /compare/from /compare/to >> some_filename
@craigvantonder
craigvantonder / bash-change-extension-recursively
Created November 8, 2018 07:26
Change the extension of files recursively
find /path/to -depth -name "*.jpeg" -exec sh -c 'mv "$1" "${1%.jpeg}.jpg"' _ {} \;