Skip to content

Instantly share code, notes, and snippets.

@isaaclw
isaaclw / git_clean_merge.sh
Last active November 22, 2019 16:06
Makes sure your branch is as up to date as possible before you merge/push. #git
#!/bin/bash
branch=$1
commitfile=$2
ticketno=$(echo $branch | sed -r 's/[^0-9]+([0-9]+)[^0-9].*/\1/')
if [ -z "$branch" ]; then
echo
echo "Usage: $(basename $0) branch [ commitfile ]"
echo
@isaaclw
isaaclw / vimdiff_show.sh
Last active November 22, 2019 16:06
Use vimdiff to show the differences before and after a git hash #vim #git
HASH=
FILE=
vimdiff <(git show $HASH~:$FILE) <(git show $HASH:$FILE)
@isaaclw
isaaclw / git_old_branches.sh
Last active November 22, 2019 21:08
Clear out old branches #git #bash
git remote prune origin
# or delete branches:
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
@isaaclw
isaaclw / curl_cookies.sh
Last active November 22, 2019 16:06
Run Curl with cookies
#!/bin/bash
COOKIE_JAR=cookies.txt
URL="http://www.google.com/foobar/"
get_session() {
read -p "username: " username
# The -s option is only present in bash
read -sp "password: " password
@isaaclw
isaaclw / parse_download.pl
Last active September 7, 2020 03:12
Parse page (with perl) and then download everything matching a regex. #perl #download
#!/usr/bin/perl
# download a page, and then download all the files on the page according to the regular expression, and store them in the folder
use strict;
use URI::URL;
my $urlchars = "[^\'\"]";
parse("http://www.test.com/", "data-bt=\"($urlchars*?\.torrent)\"", "humble");
sub parse() {
@isaaclw
isaaclw / sudo_envcat
Last active May 28, 2020 15:47
Checks a Pid for a variable in the environment #bash #env
#!/bin/bash
# isaac ALL = NOPASSWD: /home/isaac/.bin/sudo_envcat
pid="$1"
if [ "$pid" == 't' ] && [ $(whoami) == 'root' ]; then
exit 0
fi
var="$2"
output=$(cat /proc/$pid/environ | tr '\0' '\n' | grep "$var" | cut -d '=' -f2-)
if [ -n "$DEBUG" ] && [ -n "$output" ]; then
@isaaclw
isaaclw / forcefsck
Created November 22, 2019 15:41
Force fsck #ubuntu #bash
sudo touch /forcefsck
sudo shutdown -r 1 "shutting down to do disk check"
@isaaclw
isaaclw / dehardlink.sh
Created November 22, 2019 15:45
Copy and unlink files #bash #fs
@isaaclw
isaaclw / wordpress_upload_daemon.sh
Last active November 22, 2019 20:51
Wordpress Upload Daemon #bash #wordpress #ftp
#!/bin/bash
SHARE='/opt/shuttle'
FROM_FOLDER="$SHARE/Ready to Transfer"
TRANS_FOLDER="$SHARE/Transferred"
ERROR_FOLDER="$SHARE/Didnt Upload"
mkdir -p "$FROM_FOLDER" "$TRANS_FOLDER" "$ERROR_FOLDER"
# The idea is that files show up in $FROM_FOLDER, and are uploaded via ftp to the wordpress folder.
# If they transfer successfully, they're moved to $TRANS_FOLDER
# If they fail, they're tranferred to $ERROR_FOLDER
@isaaclw
isaaclw / replace_text
Created November 22, 2019 16:37
Replaces a string within multiple files specified on the command line #perl
#!/usr/bin/perl
#
# Replaces a string within multiple files
# specified on the command line
$mv = '/bin/mv';
$tmp = '/tmp';
$op = shift || die("Usage: $0 perlexpr [filenames]\n");