Skip to content

Instantly share code, notes, and snippets.

Emanuele Ruffaldi eruffaldi

Block or report user

Report or block eruffaldi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@eruffaldi
eruffaldi / udp_player.py
Last active Feb 15, 2018
Simple UDP packet recorder and playback
View udp_player.py
# Emanuele Ruffaldi 2018
import argparse,socket,socket,json,time
def str2bool(v):
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
@eruffaldi
eruffaldi / closejson.py
Last active Feb 7, 2018
Incremental JSON
View closejson.py
import json
import sys
def main():
if len(sys.argv) < 2:
print "requires JSON file"
else:
try:
View linuxcpucontrol.bash
# e.g. setgov performance or setgov powersave
function setgov ()
{
for i in {0..7};
do
cpufreq-set -c $i -g $1;
done
}
# setfreq 3.5GHz 3.5GHz
@eruffaldi
eruffaldi / opencv_videoio_check.cpp
Created Jan 13, 2018
opencv videowriter bug check cling
View opencv_videoio_check.cpp
.L ./lib/libopencv_videoio.dylib
.L ./lib/libopencv_highgui.dylib
//.L /usr/local/Cellar/opencv/3.3.0_3/lib/libopencv_highgui.3.3.0.dylib
//.L /usr/local/Cellar/opencv/3.3.0_3/lib/libopencv_videoio.3.3.0.dylib
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <math.h>
@eruffaldi
eruffaldi / gitsquashed.sh
Created Jan 6, 2018
Git Temporary Branch Squashed
View gitsquashed.sh
git push origin --delete $SQUASHEDBRANCH
git branch -d $SQUASHEDBRANCH
git checkout master
git checkout -b $SQUASHEDBRANCH
git merge --squash $BRANCH
git commit -am "squashed patch"
@eruffaldi
eruffaldi / resticmount.bash
Created Jan 4, 2018
mount and open folder restic
View resticmount.bash
#!/bin/bash
read -s -p "Enter Password: " mypassword
set -m
RESTIC_PASSWORD=$mypassword restic -r $REPO_PATH mount $MOUNT_PATH &
lastp=$!
sleep 2
open $MOUNT_PATH/tags/$TAG/latest
fg
@eruffaldi
eruffaldi / transfer.md
Last active Dec 20, 2017
Simple Network Transfer
View transfer.md

Direct

Receiver: nc -q2 -l 12345 > myfile.tar

Sender tar cf - FILES --verbose --checkpoint=64000 | nc IPDEST 12345

This can be reversed in direction

@eruffaldi
eruffaldi / scan2pptx.py
Created Dec 19, 2017
images to pptx using annotation
View scan2pptx.py
import argparse
from pptx import Presentation
from pptx.util import Mm,Pt
import pptx
import os
import csv
import json
from PIL import Image # uses pillow
@eruffaldi
eruffaldi / TypedCsvDict.py
Created Dec 14, 2017
Typed CSV Reader and Writer
View TypedCsvDict.py
from csv import DictReader,DictWriter
# originally from pygramel
class TypedDictReader(DictReader):
"""A class for iterating a CSV file and type cast the values."""
def __init__(self, csvfile, casts, fieldnames=None, restkey=None,
restval=None, dialect='excel', *args, **kwds):
"""Arguments:
- f: An iterable object such as as file. Passed on to
@eruffaldi
eruffaldi / plot2terminal.py
Created Nov 3, 2017
Python plot to terminal
View plot2terminal.py
import sys
import numpy as np
import json
import base64
import StringIO
import matplotlib.pyplot as plt
import sys
#https://www.iterm2.com/utilities/imgls
def encode_iterm2_image(data,height=None):
You can’t perform that action at this time.