Skip to content

Instantly share code, notes, and snippets.

@hgascon
hgascon / script.sh
Last active May 10, 2023 16:26
Batch resize images in OSX
sips -Z 1024 *.jpg
@hgascon
hgascon / script.sh
Created June 11, 2015 13:55
Generate N random files with given size in a dir
#option 1:
for i in $(seq 1 N); do dd if=/dev/urandom of=$i bs=1M count=2; done
#option 2:
dd if=/dev/urandom of=masterfile bs=1 count=20000
split -b 1000 -a 10 masterfilex
@hgascon
hgascon / script.sh
Created June 11, 2015 13:58
Fast remote directory rsync over ssh
rsync -aHAXxv --numeric-ids --delete --progress -e "ssh -T -c arcfour -o Compression=no -x" user@<source>:<source_dir> <dest_dir>
@hgascon
hgascon / script.sh
Created June 11, 2015 14:02
Move a very long list of files to a directory
# Useful when $(ls) gives the error that the file list too long is
find . -name "*.bin" -exec mv {} /path/to/dest/ \;
@hgascon
hgascon / script.sh
Created June 11, 2015 14:20
Rename files using substring of another file name
for FILE in $(ls | grep -v \\.); do
BIN_FILE=$(echo ${file:0:60}.bin)
NEW_BIN_FILE=$FILE.bin
mv $BIN_FILE $NEW_BIN_FILE
done
@hgascon
hgascon / script.sh
Created June 11, 2015 14:25
Move files and files with new extension to a new dir
for FILE in $(ls *.foo); do
NAME=$(echo $FILE | cut -d '_' -f 1)
NAMEBAR=$NAME.bar
mv $FILE DONE/
mv $NAMEBAR DONE/
done
@hgascon
hgascon / script.sh
Created June 11, 2015 14:27
Unzip all files in dir and zip in a new file
#!/bin/bash
for item in *
do
unzip $item
name=$(echo $item | cut -f1 -d ' ' )
echo "all_files.zip" $name".foo"
done
@hgascon
hgascon / script.sh
Created June 11, 2015 14:29
Decompress a gzip file without gz extension
gzip -d "" -f gzippe_file
#For several files under several directories
for item in $(ls -d -1 $PWD/**/*); do
echo $item; zcat $item > temp;
sed -i 's/, / /g' temp;
gzip temp;
mv temp.gz $item;
done;
@hgascon
hgascon / script.sh
Created June 29, 2015 22:31
Download files from a AWS instance
s3cmd --access_key=12345 --secret_key="ABCDE" get s3://bucket/* --skip-existing
@hgascon
hgascon / json2libsvm.py
Created May 18, 2016 16:17
Read json files extracted from pcaps, embed the features and output a libsvm file
#!/usr/bin/python
""" Read json files extracted from pcaps,
embed the features and output a libsvm file.
"""
import json
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.datasets import dump_svmlight_file