Skip to content

Instantly share code, notes, and snippets.

Emanuele Ruffaldi eruffaldi

View GitHub Profile
@eruffaldi
eruffaldi / gettoken.sh
Created Sep 25, 2018
Google OAuth 2.0 full example bash script.
View gettoken.sh
#!/bin/bash
#1) on https://console.developers.google.com/ register project and associate API from library
# OUTPUT: client_id,client_secret
client_id="..."
client_secret="...."
#2) get authorization code at the following link using web browser
# OUTPUT: code
scope="https://www.googleapis.com/auth/drive"
@eruffaldi
eruffaldi / openmpcustom.cpp
Created Aug 11, 2016
OpenMP custom reduction example
View openmpcustom.cpp
// g++-mp-4.9 -fopenmp --std=c++11 x.cpp -lgomp
#include <iostream>
#include <omp.h>
#include <unistd.h>
class Custom
{
public:
Custom(int y = 0) : x(y) {}
@eruffaldi
eruffaldi / CMakeLists.txt
Last active Oct 19, 2019
PortAudio to MP3
View CMakeLists.txt
// 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 Sep 3, 2019
Example of CMake easy libraries
View gist:eb8953dd6aeefa35ac28
# 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 / lambdasignal.cpp
Last active Apr 5, 2019
Signal as Lambda Functions in C++
View lambdasignal.cpp
#include <functional>
#include <fstream>
#include <iostream>
#include <signal.h>
/// one holder per signal type
template <int q>
struct Signal
{
using sfx = void(int );
@eruffaldi
eruffaldi / bandwidth.py
Created Sep 2, 2016
USB Bandwidth logging using usbmon
View bandwidth.py
# See: https://www.kernel.org/doc/Documentation/usb/usbmon.txt
# See: http://people.redhat.com/zaitcev/linux/OLS05_zaitcev.pdf
#
# Emanuele Ruffaldi @ SSSA 2016
import sys,os
def scan(name,device=0):
hdevices = dict()
try:
@eruffaldi
eruffaldi / editheader.py
Last active Mar 7, 2019
A simple tool for managing the license header of C/C++ files. Allows for removal, regeneration.
View editheader.py
# 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
View midi2notes.py
from mido import MidiFile
import mido
import sys
def ntof(n):
return 440*(2**((n-69)/12))
def main():
mid = MidiFile(sys.argv[1])
View 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 Dec 30, 2018
Julia cf32
View cf32.jl
function s64toc64(a::Int64)::Int64
return a < 0 ? -(a & 9223372036854775807) : a;
end
function c64tos64(a::Int64)::Int64
return a < 0 ? ((-a) | -9223372036854775808) : a;
end
You can’t perform that action at this time.