Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / jquery.mobile_detect.js
Created Aug 16, 2012
JS: jQuery Mobile Browser Detection
View jquery.mobile_detect.js
/**
* 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 Sep 1, 2012
JS: Dump Helper (print_r)
View print_r.js
/**
* 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 Nov 10, 2015
Shell: Find & remove files bigger than X
View rm_biggies.sh
# 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 Nov 10, 2015
PHP/Drupal Malware Remover
View malware_cleaner.sh
# 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 Nov 10, 2015
SVN: Update latest commit message
View svn_commit_amend.sh
# 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 Nov 10, 2015
Shell: Analyze huge files for repeating text portions
View duplicate_lines_count.sh
# 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 Nov 10, 2015
Misc: ASCII art in NMAP source
View nmap_dragon.txt
( ) /\ _ (
\ | ( \ ( \.( ) _____
\ \ \ ` ` ) \ ( ___ / _ \
(_` \+ . x ( .\ \/ \____-----------/ (o) \_
- .- \+ ; ( O \____
(__ +- .( -'.- <. \_____________ ` \ /
(_____ ._._: <_ - <- _- _ VVVVVVV VV V\ \/
. /./.+- . .- / +-- - . (--_AAAAAAA__A_/ |
(__ ' /x / x _/ ( \______________//_ \_______
, x / ( ' . / . / \___' \ /
@sepehr
sepehr / find_n_exec.sh
Last active Nov 10, 2015
Shell: Recursively delete particular files/dirs
View find_n_exec.sh
find . -type f -name "__MACOSX" -exec rm -rf {} \;
@sepehr
sepehr / cron_times.sh
Last active Nov 10, 2015
Shell: /etc/cron.daily tasks run time
View cron_times.sh
# When does cron.daily, cron.hourly, etc. run on a system?
grep run-parts /etc/crontab
@sepehr
sepehr / dos2unix.sh
Last active Nov 10, 2015
Shell: Recursively convert line endings to LF
View dos2unix.sh
find . -type f ! -regex ".*\/\.svn\/.*" -exec dos2unix {} \;
You can’t perform that action at this time.