Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / accesslog2csv.pl
Created September 22, 2014 08:04
Perl: Convert Apache access log to CSV
#!/usr/bin/perl
#
# @file
# Converter tool, from Apache Common Log file to CSV.
#
# All code is released under the GNU General Public License.
# See COPYRIGHT.txt and LICENSE.txt.
#
@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 / tsv2csv.py
Last active February 4, 2016 16:48
Python: Bulk convert .tsv to .csv
#!/usr/bin/python
import glob
import csv
import sys
import os
# Check args
if len(sys.argv) < 2:
sys.exit('Usage: tsv2csv.py /path/to/dir')
@sepehr
sepehr / desc
Last active September 7, 2017 11:59
Shell: Man a single option
#!/bin/bash
# Print information about a single option or command
# http://svn.mikelward.com/svn/scripts/desc
# Example Usage:
# opt bash continue
# opt rsync -v
scriptname=desc
@sepehr
sepehr / mongodb_subdoc_query.js
Last active November 18, 2015 15:35
MongoDB: Remove an array from an embedded document
//
// Find documents with sub-document query:
//
db.collection_name.find({
relays: {
$elemMatch: {
timestamp: {$gte: 1447628400},
status: "RELAY_STATUS_ERROR_SUBMIT",
app_id: ObjectId("537cb1b5fc20a0eb47000000")
}
@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 / 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 / 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 / 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 / osx-kong.sh
Last active June 12, 2018 01:54
OSX: Kong Installation
#!/bin/bash
#
# The homebrew formula of kong has a lot of version incompatibilities. So
# we install kong directly from Luarocks.
#
# Kong only works with Cassandra 2.1.x/2.2.x, the latest brew formula for
# cassandra is 3.x. We need to tap homebrew/versions and install cassandra22
# instead.
#