Skip to content

Instantly share code, notes, and snippets.

View eruffaldi's full-sized avatar

Emanuele Ruffaldi eruffaldi

View GitHub Profile
# WS Server - UDP Server
# Taken online, refactored
#
# Emanuele Ruffaldi 2017
import time, sys, os, pkg_resources
import SocketServer
from twisted.python import log
from twisted.internet import reactor
@eruffaldi
eruffaldi / datawithpayload.cpp
Last active October 4, 2017 13:52
Shared Memory Placed Variable size object
#include <stdint.h>
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>
#include <vector>
#include <iostream>
#include <tuple>
// header
struct ImageHeader
{
@eruffaldi
eruffaldi / videocapture_cvimageio.py
Last active September 27, 2017 12:05
python cross api videoio
import cv2
import sys
try:
import imageio
except:
print "missing imageio"
imageio = None
try:
@eruffaldi
eruffaldi / build
Created September 4, 2017 14:51
PyQt5 Python 2.7 macOS 10.12
#updated from https://gist.github.com/kilfu0701/47b74a17a70b43549985
brew install qt5
brew install pyqt5 # for python 3.6
## download SIP source code
wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.19.3/sip-4.19.3.tar.gz
tar zxf sip-4.19.3.tar.gz
cd sip-4.19.3
python configure.py
make
@eruffaldi
eruffaldi / extract_pdf_annotations_two.py
Last active August 15, 2017 15:20
Extract Annotations from two columns PDF document s
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdftypes import PDFObjectNotFound
import sys
def extract(objid, obj,pages,anno,marked):
if isinstance(obj, dict):
# 'Type' is PDFObjRef type
if obj.has_key('Type') and obj['Type'].name == 'Page':
pages.append(objid)
elif obj.has_key('C'):
@eruffaldi
eruffaldi / pypdf_sidebyside.py
Last active August 1, 2017 14:21
pypdf side by side
from PyPDF2 import PdfFileWriter, PdfFileReader
import sys
in1,in2,out = sys.argv[1:]
output = PdfFileWriter()
input1 = PdfFileReader(file(in1, "rb"))
input2 = PdfFileReader(file(in2, "rb"))
m = min(input1.getNumPages(),input2.getNumPages())
@eruffaldi
eruffaldi / pypdf_addblank.py
Created August 1, 2017 14:15
pdf add 1 blank
from PyPDF2 import PdfFileWriter, PdfFileReader
import sys
in1,out = sys.argv[1:]
output = PdfFileWriter()
input1 = PdfFileReader(file(in1, "rb"))
for i in range(0,input1.getNumPages()):
p1 = input1.getPage(i)
@eruffaldi
eruffaldi / onlyimageslink.py
Last active July 31, 2017 23:39
FUSE Filesystem that picks only JPEG
@eruffaldi
eruffaldi / youtube-dla.sh
Created July 16, 2017 15:11
Youtube Download and Preserve originating URL
#!/bin/bash
# get filename from youtube-dl then replace it with mp4
# then download, convert to mp4 and put metadata
filename=$(youtube-dl --get-filename "$1")
filename=${filename%.*}.mp4
youtube-dl "$1" --recode-video mp4 --add-metadata
exiftool $filename -XMP:source=$1
exiftool $filename
@eruffaldi
eruffaldi / treelisting.py
Created July 1, 2017 23:28
CSV listing of folders and filers, e.g. for offline hard disks, with the option to report the content of encountered ZIP archives. Needs to be coupled with a search tool
import argparse
import csv
import os
import uuid,json,subprocess
import zipfile
import time
# TODO crossplatform
# TODO given path extract volume then label+uuid+diskformat
#
# OSX: add path => volume using mount output