Skip to content

Instantly share code, notes, and snippets.

benkulbertis /
Last active April 28, 2023 02:12
Cloudflare API v4 Dynamic DNS Update in Bash
auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare account settings
ip=$(curl -s
benkulbertis /
Created April 14, 2015 03:50
Automatically configures netctl to use wired DHCP with a chosen interface.
interfaces=$(ip link | cut -d ":" -f 1-2 | sed 'n; d')
echo -e "Available Interfaces:\n$interfaces"
read -p "Please choose an interface: " choice
if [ "$choice" -ge 1 -a "$choice" -le $(echo "$interfaces" | wc -l) ]; then
interface=$(echo "$interfaces" | sed "${choice}q;d" | cut -d ":" -f 2 | sed 's/ //g')
sed "s/eth0/$interface/g" /etc/netctl/examples/ethernet-dhcp > /etc/netctl/ethernet-dhcp
echo "Now enabling the $interface interface..."
netctl start ethernet-dhcp
benkulbertis / vm-backup.bat
Last active January 26, 2021 20:30
This backs up my Ubuntu VM on my Windows work machine. It works with any Virtualbox VM by passing the VM name as an argument. I hate batch.
View vm-backup.bat
@echo off
:: This is the name (in Virtualbox) of the VM you want to back up. Pass it as an argument or change the '%1' below to the VM name.
set vmname=%1
set bakroot=D:\VM Backups
:: Get current date - from
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%a-%%b-%%c)
set /p start=The %vmname% VM is about to be backed up. Do you wish to continue (Y/[N])?
benkulbertis /
Last active December 26, 2015 17:29
This is a little bash script that will shut down the system when a process id exits. Just pass the relevant process id as an argument. It requires root/sudo to shutdown the system. The program Cuttlefish used to be able to do this but is now unmaintained. The kde program kshutdown can do this but requires a lot of dependencies on non-kde systems…
# Usage: ./ 1234
# Or: ./ $(pidof -s someprocess)
if [ -z "$pid" ]
echo "This script shuts down the system when a certain process exits. Please pass a process id as an argument to shut the system down when it exits." 1>&2
benkulbertis /
Last active December 11, 2015 19:59
My Starcraft II Wine Launcher
xrandr --output DVI-I-3 --off
env LD_LIBRARY_PATH="/usr/lib32/:/usr/lib/" WINENOPULSE=1 wine ~/.wine/dosdevices/c\:/Program\ Files/StarCraft\ II/Starcraft\ II.exe
while [ "$(pidof SC2.exe)" -o "$(pidof Blizzard\ Launcher.exe)" ]; do
sleep 1
xrandr --output DVI-I-3 --auto --right-of DVI-I-2
wineserver -k
benkulbertis /
Created October 9, 2012 09:06
Execute a remote script with bash
bash -s < <(curl -sL $SCRIPT) $@
benkulbertis / lampp
Created April 16, 2011 22:09
Modified Version of the XAMPP launching script to use a system MongoDB install as opposed to MySQL
View lampp
# Modified Version of the XAMPP launching script to use a system MongoDB install as opposed to MySQL
# Tested on Ubuntu 10.10
# Copyright (c) 2011, Ben Kulbertis
# Author: Ben Kulbertis <>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
benkulbertis / duplicate_fixer()
Created January 24, 2011 02:34
Checks if the file name exists, if it does uses recursion to append the file name with a number that has not yet been used.
View duplicate_fixer()
function duplicate_fixer($fname, $count = 0, $old_fname = null){
if($count != 0){
$boom = explode(".", $old_fname);
$boom[count($boom)-2] = $boom[count($boom)-2].$count.".";
$fname = implode($boom);
if($count == 0) $old_fname = $fname;
$fname = duplicate_fixer($fname, $count, $old_fname);
benkulbertis / Image Upload Validation
Created January 11, 2011 22:13
Simple validation function to confirm that an image is actually an image, not a malicious .gif or .php file.
View Image Upload Validation
function validate($upload){ // Must be a $_FILES array
if($upload['size'] == 0) return "Image not uploaded correctly.";
if($upload['size'] > 2097152){ // Measured in bytes, this is equal to 2MB
$filesize = $upload['size']/1048576; // Converts from bytes to Megabytes
return "The image you uploaded has a filesize that is too large. Please reduce your image to < 2MB. It is currently ".$filesize."MB.";
if(($upload['type'] != "image/gif" || "image/jpeg" || "image/png") || ($this->imageinfo['mime'] != "image/gif" || "image/jpeg" || "image/png"))
return "Uploads of that file type are not allowed. You need a jpg, png, or gif image.";
$blacklist = array(".php", ".phtml", ".php3", ".php4", ".ph3", ".ph4");
foreach ($blacklist as $item) {