Skip to content

Instantly share code, notes, and snippets.

Ben Kulbertis benkulbertis

Block or report user

Report or block benkulbertis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@benkulbertis
benkulbertis / Image Upload Validation
Created Jan 11, 2011
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) {
@benkulbertis
benkulbertis / duplicate_fixer()
Created Jan 24, 2011
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(file_exists($fname)){
if($count == 0) $old_fname = $fname;
$count++;
$fname = duplicate_fixer($fname, $count, $old_fname);
@benkulbertis
benkulbertis / lampp
Created Apr 16, 2011
Modified Version of the XAMPP launching script to use a system MongoDB install as opposed to MySQL
View lampp
#!/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 <ben@kulbertis.org>
#
# 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 / rbash.sh
Created Oct 9, 2012
Execute a remote script with bash
View rbash.sh
#!/bin/bash
SCRIPT=$1
shift
bash -s < <(curl -sL $SCRIPT) $@
@benkulbertis
benkulbertis / starcraft.sh
Last active Dec 11, 2015
My Starcraft II Wine Launcher
View starcraft.sh
#!/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 / pshutdown.sh
Last active Dec 26, 2015
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…
View pshutdown.sh
#!/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 / vm-backup.bat
Last active Dec 30, 2015
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 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 / netctl-auto-ethernet.sh
Created Apr 14, 2015
Automatically configures netctl to use wired DHCP with a chosen interface.
View netctl-auto-ethernet.sh
#!/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 / cloudflare-update-record.sh
Last active Dec 4, 2019
Cloudflare API v4 Dynamic DNS Update in Bash
View cloudflare-update-record.sh
#!/bin/bash
# CHANGE THESE
auth_email="user@example.com"
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)
You can’t perform that action at this time.