Skip to content

Instantly share code, notes, and snippets.

View eruffaldi's full-sized avatar

Emanuele Ruffaldi eruffaldi

View GitHub Profile
@eruffaldi
eruffaldi / linuxcpucontrol.bash
Last active January 18, 2018 09:06
Multicore pusher
# 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 January 13, 2018 00:24
opencv videowriter bug check cling
.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 January 6, 2018 01:58
Git Temporary Branch Squashed
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 January 4, 2018 23:35
mount and open folder restic
#!/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 December 20, 2017 14:38
Simple Network Transfer

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 December 19, 2017 22:51
images to pptx using annotation
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 December 14, 2017 11:21
Typed CSV Reader and Writer
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 November 3, 2017 13:16
Python plot to terminal
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):
@eruffaldi
eruffaldi / catls.py
Created November 3, 2017 13:07
Python inline image with iterm2
import base64
import sys
#https://www.iterm2.com/utilities/imgls
def encode_iterm2_image(data,height=None):
if height is None:
height = "auto"
else:
height = "%spx" % height
return ("\x1B]1337;File=loss.jpg;width=auto;height=%s;inline=1;size=%dpreserveAspectRatio=1:" % (height,len(data))) + base64.b64encode(data)
@eruffaldi
eruffaldi / udptunnel.sh
Created October 16, 2017 09:52
SSH UDP Tunnelling: remote to local UDP server
# Only for remote UDP https://stackpointer.io/network/ssh-port-forwarding-tcp-udp/365/
# Local UDP server to Remote UDP server
ssh -L 9999:127.0.0.1:9999 percro@alientelecom socat tcp4-listen:9999,reuseaddr,fork udp:target:9999
socat -T15 udp4-recvfrom:9999,reuseaddr,fork tcp:localhost:9999
# Remote UDP server to Local UDP server
ssh -R 9999:127.0.0.1:9999 percro@alientelecom socat udp4-recvfrom:9999,reuseaddr,fork tcp:localhost:9999
socat -T15 tcp4-listen:9999,reuseaddr,fork udp:localhost:9999