Skip to content

Instantly share code, notes, and snippets.

View chamalis's full-sized avatar

Stelios chamalis

  • Wandering around Earth
View GitHub Profile
@chamalis
chamalis / clean_pdf.sh
Created January 25, 2022 23:50
Remove metadata from PDF files, using pdftk, exiftool and qpdf
# Ensure that required tools are installed and available in $PATH
command -v pdftk >/dev/null 2>&1 || { echo >&2 "pdftk is required but was not found. Aborting."; exit 1; }
command -v exiftool >/dev/null 2>&1 || { echo >&2 "exiftool is required but was not found. Aborting."; exit 1; }
command -v qpdf >/dev/null 2>&1 || { echo >&2 "qpdf is required but was not found. Aborting."; exit 1; }
# Ensure that 1 cmdline argument was passed
if [ "$#" -ne 1 ]
then
echo "Usage: cleanpdf.sh path-to-pdf-file.pdf"
echo ""
@chamalis
chamalis / sam2bam
Created August 21, 2019 20:36
Bash script to convert all SAM files found in a directory to BAM. Directory is passed as positional command line argument.
#!/usr/bin/env bash
for i in $(ls $1); do
filename_prefix="${i%.*}"
filename_extension="${i##*.}"
if [ "$filename_extension" == "sam" ]; then
samtools view -bs $i > $filename_prefix.bam
samtools sort $filename_prefix.bam -o $2
samtools index $2 $2.index
rm $filename_prefix.bam
@chamalis
chamalis / compress-mp4.sh
Last active April 24, 2024 08:28
Compress video files recursively, using x264, placing the output files into the same folder with an appropriate filename (filename_scaled.mp4). First argument is the top-level directory to scan. It avoid overriding already compressed files. Change the filetype (e.g mp4) at the beginning of the script.
#!/bin/bash
FILETYPE=mp4
if [ "$#" -ne 1 ]; then
echo "Usage: <path-to-compress.mp4> target-top-level-directory"
exit
fi
# for all the mp4 except the already scaled ones
@chamalis
chamalis / https_mitm.sh
Last active October 8, 2018 16:09
Bash script to set up MiTM attack using arpspoof
#!/bin/bash
# This script only sets up the interception mechanism, placing your machine
# in the middle of target and gateway.
# In order to actually capture and view/edit the traffic either run
# sslstrip to bypass SSL and tcpdump to capture packets, or
# Burp Suite (auto-generates certificates), or any other similar tool(s)
if [ "$#" -ne 1 ]; then
echo "Usage: bash mitm_https.sh targetIP"
@chamalis
chamalis / es_fetch_all.py
Last active November 8, 2018 12:58
Get all Elasticsearch records
#!/usr/bin/env python
# using the low-level elasticsearch-py client. Works for 6.3
from elasticsearch.helpers import scan # abstraction for scroll()
# assuming `es_obj` is an `Elasticsearch` instance
doc_generator = scan(
es_obj,
query={"query": {"match_all": {}}},
index="my-index",
@chamalis
chamalis / hash.c
Created November 28, 2017 13:15 — forked from tonious/hash.c
A quick hashtable implementation in c.
#define _XOPEN_SOURCE 500 /* Enable certain library functions (strdup) on linux. See feature_test_macros(7) */
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
struct entry_s {
char *key;
char *value;