Skip to content

Instantly share code, notes, and snippets.

@wrunk
Last active February 10, 2018 02:38
Show Gist options
  • Save wrunk/4243499 to your computer and use it in GitHub Desktop.
Save wrunk/4243499 to your computer and use it in GitHub Desktop.
Shellpers
# Prepend something to the beginning of each line
cat .gitignore| while read line; do echo "[ERROR] $line"; done > somefile.txt
# Delete all the GD pyc files starting in this dir
find . -name '*.pyc' -exec rm -f {} \;
#
# ** Below are some SHELLpers to deal with removing crap from a go vendor dir
# NOTE cgo stuff might not like this process ^_^
# Find all files EXCEPT go and just print them
find . -type f -not -name '*go'
# Find and delete all EXCEPT go files (good for cleaning up vendor folder)
find . -type f -not -name '*go' |xargs rm
# Remove test files
find . -name '*_test.go'
# Finally remove left over empty dirs
find . -type d -empty -delete
# In the case of annoying appengine incompatible files, remove:
find . | xargs grep -l unsafe | awk '{print "rm "$1}' > doit.sh
find . | xargs grep -l syscall | awk '{print "rm "$1}' > doit.sh
#
# ** END vendor cleanup
#
# Using the stupid zip command
zip -r nudge.zip nudge/
# Zip single file
zip archive_name.zip file_to_be_zipped.csv
# Some log file cut magic
# Note since using the tail -f, you need the while or nothing will happen.
# Thanks stack overflow!
tail -f /var/log/logfiles.log* | while read line ; do echo "$line"| grep entity_id | cut -c15-25 ; done
# Also see kenji's log tailing py script
# http://code.activestate.com/lists/python-list/577483/
# Create a new tarball (tar.gz)
tar pvczf my_files.tar.gz files/
# Untar it (this will add the files dir into the current dir)
tar pvxzf my_files.tar.gz
# Curl helps
# Verbose mode
curl -vv http://www.google.com
# Adding an HTTP header to the request (note the multiple -H params for several headers)
curl -H "User-Agent:Some fake user agent..." -H "Referer:http://www.evite.com/" http://www.google.com
# Using json like object params AND using tcp trace
# This also shows how to use stripe add card with full source params via curl
curl -vv https://api.stripe.com/v1/customers/cus_6tnWZ...8b/sources \
-u sk_test_M...: \
-d source[object]=card -d source[number]=4111111111111111 \
-d source[exp_month]=02 -d source[exp_year]=2019 \
-d source[cvc]=123 --trace-ascii /dev/stdout
# Standard application/x-www-form-urlencoded POSTing using curl: (recaptcha example)
curl -vv https://www.google.com/recaptcha/api/siteverify \
-d "secret=1234-This-Is-Your-Site-Secret--" \
-d "response=06GHJ...."
# Notes for beginners
# When scping something large, make sure it completes on one leg before starting the next ;)
# Trade Secret: display something like [ 317/s] - great for counting reqs/sec based on log lines
tail -f boom-core.log | grep 'GIN' |pv -lr -i 5 > /dev/null
# Symbolic links
# Create a link using absolute paths
# Remember the final arg is the directory in which to place the link
ln -s /Users/warren/directory_to_be_linked /Users/warren/link-will-go-in-this-dir
# directory_to_be_linked will now exist inside /Users/warren/link-will-go-in-this-dir as a symlink
# Symlink in the current directory
ln -s /Users/warren/directory_to_be_linked
# directory_to_be_linked will now exist inside the current directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment