Skip to content

Instantly share code, notes, and snippets.

@benkulbertis
benkulbertis / cloudflare-update-record.sh
Last active October 22, 2024 19:31
Cloudflare API v4 Dynamic DNS Update in Bash
#!/bin/bash
# CHANGE THESE
auth_email="[email protected]"
auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare account settings
zone_name="example.com"
record_name="www.example.com"
# MAYBE CHANGE THESE
ip=$(curl -s http://ipv4.icanhazip.com)
@benkulbertis
benkulbertis / netctl-auto-ethernet.sh
Created April 14, 2015 03:50
Automatically configures netctl to use wired DHCP with a chosen interface.
#!/bin/bash
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
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.
@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 http://stackoverflow.com/a/203116
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
benkulbertis / pshutdown.sh
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…
#!/bin/bash
# Usage: ./pshutdown.sh 1234
# Or: ./pshutdown.sh $(pidof -s someprocess)
pid=$1
if [ -z "$pid" ]
then
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
benkulbertis / starcraft.sh
Last active December 11, 2015 19:59
My Starcraft II Wine Launcher
#!/bin/bash
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
done
xrandr --output DVI-I-3 --auto --right-of DVI-I-2
wineserver -k
@benkulbertis
benkulbertis / rbash.sh
Created October 9, 2012 09:06
Execute a remote script with bash
#!/bin/bash
SCRIPT=$1
shift
bash -s < <(curl -sL $SCRIPT) $@
@benkulbertis
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
#!/bin/bash
#
# 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 <[email protected]>
#
# 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
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.
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(file_exists($fname)){
if($count == 0) $old_fname = $fname;
$count++;
$fname = duplicate_fixer($fname, $count, $old_fname);
@benkulbertis
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.
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) {