Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / jquery.mobile_detect.js
Created August 16, 2012 15:54
JS: jQuery Mobile Browser Detection
/**
* Mobile Browser Detection for jQuery
*
* jQuery.browser.mobile will be true if the browser is a mobile device.
*/
(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(2
@sepehr
sepehr / print_r.js
Created September 1, 2012 04:14
JS: Dump Helper (print_r)
/**
* Debug helper similar to PHP's print_r().
*
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*
* @param data
* array, object or hash (assoc array)
@sepehr
sepehr / rm_biggies.sh
Last active November 10, 2015 22:38
Shell: Find & remove files bigger than X
# k: Kilobyte, M: Megabyte, G: Gigabyte
# +: Bigger than, -: Lower than
find . -maxdepth 1 -type f -size +500k -exec rm -f {} \;
# Or better:
find . -maxdepth 1 -type f -size +50M -delete
# Let's have a look first:
find . -maxdepth 1 -type f -size +2G -exec ls -lhS {} \; | awk {print $5 "\t" $9}
@sepehr
sepehr / malware_cleaner.sh
Last active November 10, 2015 22:44
PHP/Drupal Malware Remover
# Observe the mess, exclude the unnecessary
#
# -r: Recursive
# -I: Skip binaries
#
grep -rI --color "return base64_decode(\\$.*);" /path/to/www/root
# Clean the mess
#
# -r: Recursice
@sepehr
sepehr / svn_commit_amend.sh
Last active November 10, 2015 22:45
SVN: Update latest commit message
# Try svn info and replace SVN_REPO_REMOTE_ADDRESS
svn propset --revprop -r {REVISION_NUMBER} --force "svn:log" "NEW_COMMIT_MESSAGE_HERE..." SVN_REPO_REMOTE_ADDRESS
@sepehr
sepehr / duplicate_lines_count.sh
Last active November 10, 2015 22:45
Shell: Analyze huge files for repeating text portions
# Sorts the file by duplicate line count
sort /path/to/filename | uniq -c | sort -nr > ./_aggregated.tmp
# Just read the head as it's probably a huge file
head -n 1000 ./_aggregated.tmp | less
@sepehr
sepehr / nmap_dragon.txt
Last active November 10, 2015 22:48
Misc: ASCII art in NMAP source
( ) /\ _ (
\ | ( \ ( \.( ) _____
\ \ \ ` ` ) \ ( ___ / _ \
(_` \+ . x ( .\ \/ \____-----------/ (o) \_
- .- \+ ; ( O \____
(__ +- .( -'.- <. \_____________ ` \ /
(_____ ._._: <_ - <- _- _ VVVVVVV VV V\ \/
. /./.+- . .- / +-- - . (--_AAAAAAA__A_/ |
(__ ' /x / x _/ ( \______________//_ \_______
, x / ( ' . / . / \___' \ /
@sepehr
sepehr / find_n_exec.sh
Last active November 10, 2015 22:49
Shell: Recursively delete particular files/dirs
find . -type f -name "__MACOSX" -exec rm -rf {} \;
@sepehr
sepehr / cron_times.sh
Last active November 10, 2015 22:50
Shell: /etc/cron.daily tasks run time
# When does cron.daily, cron.hourly, etc. run on a system?
grep run-parts /etc/crontab
@sepehr
sepehr / dos2unix.sh
Last active November 10, 2015 22:51
Shell: Recursively convert line endings to LF
find . -type f ! -regex ".*\/\.svn\/.*" -exec dos2unix {} \;