Skip to content

Instantly share code, notes, and snippets.

View shoaibi's full-sized avatar

Shoaibi shoaibi

View GitHub Profile
@shoaibi
shoaibi / block-steam-internet-access.sh
Created June 25, 2015 14:49
Block Steam's internet access using iptables
#!/bin/sh
# Block Steam's internet access using iptables
# Script must be run as a user with root (or one that has
# permissions to play with iptables)
#
#
# Why did i need it? Even when running in offline mode
# steam would keep trying to login and then once every
# while it'd end my dota bota match saying "Connection
# Lost".
@shoaibi
shoaibi / carry-out-job-until-complete.sh
Created June 25, 2015 14:56
Keep retrying some job till it executes successfully
#!/bin/bash
# Keep retrying some job till it executes successfully
#
# I primarily use this script to download files from servers
# that break the connection after certain minutes. Combining
# this with aria2c makes a really awesome sure-fire way to
# download your files.
#
carryOutJob()
@shoaibi
shoaibi / .bash_aliases.sh
Last active August 29, 2015 14:23
My bash aliases
~/.bash/aliases/apt
##################
# APT
##################
#alias apt-fast='~/scripts/apt-fast.sh'
#alias sagif='sudo apt-fast install -f'
#alias sagi='sudo apt-fast install'
#alias sagur='sudo apt-fast upgrade'
#alias sacs='sudo apt-cache search'
@shoaibi
shoaibi / .bash_custom.sh
Created June 25, 2015 15:12
My bash configuration containing overrides/additions
# find partition name for a given filename
findpart() { [ -e "$1" ] && df -P "$1" | awk '/^\/dev/ {print $1}' || echo "$1 not found"; }
# Verbose version of sleep
countdown()
{
secs=$1
while [ $secs -gt 0 ]; do
echo -ne "$secs\033[0K\r"
sleep 1
@shoaibi
shoaibi / is-port-accessible.sh
Created June 25, 2015 15:14
Test if a remote port is responding or not. Good to be used as part of cron/script that'd send notifications if a port becomes unresponsive
#!/bin/sh
# Usage: $0 {hostname} {port} {pathToScriptToExecuteIfPortIsNotAccessibleSayRestartApacheScript}
echo "" | nc $1 $2 && echo $? &>> /dev/null || $3
@shoaibi
shoaibi / generate_password.php
Created June 25, 2015 15:16
My stupid password generator
<?php
echo substr(str_replace('+', '.', base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 22) . PHP_EOL;
@shoaibi
shoaibi / convert-videos-for-phone.sh
Created June 25, 2015 15:18
Convert video files in the specified path for my phone(SG4)
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: $0 sourceExtension /path/to/source/files /path/to/save/converted/files"
exit 65
fi
cd "$2"
@shoaibi
shoaibi / adblock.sh
Last active August 29, 2015 14:23
Poor man's adblock using hosts file
#!/bin/sh
# Most of the code below has been adapted from several different scripts
mkdir -p /tmp/adblock &> /dev/null
temphosts1=`mktemp`
temphosts2=`mktemp`
# I prefer to separate adblock entries from my vanilla hosts file.
# I also use dnsmasq, which allows me to chain-load an additional
# hosts file, which is what i have done here.
target_file=/etc/hosts.dnsmasq
@shoaibi
shoaibi / start-workspace.sh
Created June 25, 2015 15:31
Start a workspace (preset programs)
#!/bin/bash
#
# I am mostly working in either of 2 modes:
# 1- work [ pass 'work' as first argument ]
# 2- not-work [ default]
#
# And over the years I have found it to be a pain to have to
# manually start the same 5-6 prorgams everytime my laptop
# got rebooted so I created a script with those presets
# and then set openbox to start the relevant workspace
@shoaibi
shoaibi / pnkill.sh
Created June 25, 2015 15:33
Kill a process by its (partial) name
#!/bin/bash
E_BADARGS=65
if [ $# -ne 2 -a $# -ne 1 ]
then
echo "Usage: $0 {processNameWithoutSpaces} [{signal}]"
exit $E_BADARGS
fi
process_name="$1"