Skip to content

Instantly share code, notes, and snippets.

View eruffaldi's full-sized avatar

Emanuele Ruffaldi eruffaldi

View GitHub Profile
@eruffaldi
eruffaldi / main.cpp
Created October 12, 2020 04:19
Named Operators in C++ and Unicode
// Testedt with GCC and CLang
// Not working with ICC due to the UTF-8
// MSVC requires /utf-8 option
#include <iostream>
// from https://riptutorial.com/cplusplus/example/23817/named-operators
// modified to use < > instead of *
// modified for adding unary version
namespace named_operator {
template<class D>struct make_operator{constexpr make_operator(){}};
@eruffaldi
eruffaldi / CMakeLists.txt
Last active October 19, 2019 16:21
PortAudio to MP3
// https://github.com/eruffaldi/cmakego
find_package(cmakego COMPONENTS portaudio lame)
add_executable(testpa testpa.cpp)
target_link_libraries(testpa p::portaudio p::lame)
@eruffaldi
eruffaldi / gist:eb8953dd6aeefa35ac28
Last active September 3, 2019 07:57
Example of CMake easy libraries
# REPLACED BY: https://github.com/eruffaldi/cmakego
# assuming to ave the correct find_package above ...
# requires CMakew 3.0 for supporting INTERFACE library type
if(ZeroMQ_FOUND)
add_library(p::zeromq INTERFACE IMPORTED)
set_property(TARGET p::zeromq PROPERTY INTERFACE_LINK_LIBRARIES ${ZeroMQ_LIBRARY})
set_property(TARGET p::zeromq PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ZeroMQ_INCLUDE_DIR}")
endif()
@eruffaldi
eruffaldi / editheader.py
Last active March 7, 2019 12:50
A simple tool for managing the license header of C/C++ files. Allows for removal, regeneration.
# Edit Header for C/C++
# Scan Files and Verify license for C/C++
#
# Emanuele Ruffaldi 2015-2016
#
# Usage:
# - select files using a combination of find/grep e.g.
# find . | grep -v buildosx | grep -v buildwin | grep -E ".*\.(cpp|hpp|h)$"
# - verify used headers or per-file
# python editheader.py --filelist FILELIST --all --listlicenses
@eruffaldi
eruffaldi / midi2notes.py
Created February 7, 2019 14:50
MIDI to notes
from mido import MidiFile
import mido
import sys
def ntof(n):
return 440*(2**((n-69)/12))
def main():
mid = MidiFile(sys.argv[1])
@eruffaldi
eruffaldi / posit_one.h
Last active January 24, 2019 09:58
posit_one.h
// cppPosit 7b7b5ecde436a65923d679d91ddb1b29b711af27
/**
* Emanuele Ruffaldi (C) 2017-2018
*
* My personal bit hip pop using BMI extensions and a bit of constexpr!
*/
#if defined(__SDSVHLS__) && !defined(FPGAHLS)
#define FPGAHLS
@eruffaldi
eruffaldi / cf32.jl
Last active December 30, 2018 11:07
Julia cf32
function s64toc64(a::Int64)::Int64
return a < 0 ? -(a & 9223372036854775807) : a;
end
function c64tos64(a::Int64)::Int64
return a < 0 ? ((-a) | -9223372036854775808) : a;
end
import os,sys
people = [x.split(" ") for x in """1 10 name""".split("\n")]
print (people)
for f,n,name in people:
f = int(f)
n = int(n)
print (f,f+n-1,name)
os.system("gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=%d -dLastPage=%d -sOutputFile=%s.pdf \"%s\"" % (f,f+n-1,name,sys.argv[1]))
@eruffaldi
eruffaldi / timeline-kml-work.py
Created July 13, 2018 08:15
Google Timeline KML to working enter-exit
# parses KML from Google Timeline to obtain places
# Emanuele Ruffaldi 2018
import os,sys
import csv
import datetime
import xml.etree.ElementTree as ET
from collections import defaultdict
import time
from dateutil import tz
from_zone = tz.tzutc()
@eruffaldi
eruffaldi / gist:cd82d29292291a85daa9d8d41f094a65
Created June 8, 2018 08:31
Bash find changed files of Today
find / -mtime -1 -not \( -path "/proc/*" -o -path "/sys/*" -o -path "/dev/*" \) -print