Skip to content

Instantly share code, notes, and snippets.

@abiyani
abiyani / dedup_PATH.bash
Last active August 29, 2015 13:58
Removes duplicate paths from the input (which is assumed to be a "PATH-like" string)
# Removes redundant entries from the input (which is assumed to be a "PATH"-like string)
# Input: Exactly one argument ($1): a PATH-like string, which will be de-deuplicated
# Output: Prints the deduplicated string on stdout (can be captured using command substitution by caller)
#
# Notes:
# - Assumes colon (:) as the delimiter character.
# - The only assumption regarding actual pathnames within the input string is that they won't
# contain the delimiter character (':') - this shouldn't be a problem, because bash will
# anyway split on ":" unconditionally (http://stackoverflow.com/a/14661492/1857518). Any other
# valid pathname character (whitespaces, non-printable ascii values, etc) are ok (modulo some other
@abiyani
abiyani / bing_search.bash
Last active August 29, 2015 14:01
Perform multiple bing search from your account (by default assumes that you are logged into bing in Firefox, but you can supply a custom cookie file too)
#!/bin/bash
# Usage:
# ./bing_search.bash [max_random_wait_in_seconds=5] [cookie_file_path]
set -e
function ensureCookieFile() {
local mpath=~/.mozilla/firefox
cf="$(find "$mpath" -name "cookies.sqlite" -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | rev | head -n 1 | cut -f 1 -d ' ' | rev)"
if [[ -z "$cf" ]]; then
echo -e "\nUnable to find file 'cookies.sqlite' inside the source tree '${mpath}' -- will exit\n" >&2
exit 1
@abiyani
abiyani / worldcup-prompt.bash
Last active August 29, 2015 14:02
Display current World Cup 2014 match scores as part of terminal prompt (requires jq, and wget/curl)
# You will need to have jq (http://stedolan.github.io/jq/) and wget/curl installed on your system before being able to use this script.
#
# Usage: Include the following bash snippet in your ~/.bashrc file, or save as a separate file and source it.
#
# Example prompt generated by the script:
# abiyani@vaio:~ [BEL-2-1-ALG, RUS-1-1-KOR, BRA-0-0-MEX]
#
# Note: By default it display score for only active matches, and if there is no active match at the moment, then prompt remains unchanged.
function get_scores() {