Skip to content

Instantly share code, notes, and snippets.

@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 / mongodb_subdoc_query.js
Last active Nov 18, 2015
MongoDB: Remove an array from an embedded document
View mongodb_subdoc_query.js
//
// 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 / desc
Last active Sep 7, 2017
Shell: Man a single option
View desc
#!/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 / tsv2csv.py
Last active Feb 4, 2016
Python: Bulk convert .tsv to .csv
View tsv2csv.py
#!/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 / 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 / accesslog2csv.pl
Created Sep 22, 2014
Perl: Convert Apache access log to CSV
View accesslog2csv.pl
#!/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 / 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 {} \;
@sepehr
sepehr / gitignore2svnignore.sh
Created Jun 24, 2014 — forked from iegik/gitignore2svnignore.sh
Shell: Convert .svnignore to .gitignore & viceversa
View gitignore2svnignore.sh
#!/bin/bash
cat .gitignore | sed 's/^/\.\//g;s/\(.*\)\/\([0-9a-zA-Z\*\?\.]*\)$/svn propedit svn:ignore "\2" \1 /mg' | bash