Skip to content

Instantly share code, notes, and snippets.

View eruffaldi's full-sized avatar

Emanuele Ruffaldi eruffaldi

View GitHub Profile
#!/bin/bash
IFS=$'\n'
a=''
for i in $( IFS=$'\n' lsusb | grep 045e: ); do
IFS=' :' read -r -a array <<< "$i"
a="${a} --device /dev/bus/usb/${array[1]}/${array[3]}"
done
echo $a
@eruffaldi
eruffaldi / bitreverse.cpp
Last active October 3, 2016 04:49
Bit reverse
// g++ --std=c++11 -O3 -march=native bitreverse.cpp
#include <chrono>
#include <iostream>
char buf[256];
int zz3(int x)
{
return buf[x];
};
// 11001100
#define CONCATENATE_IMPL(s1, s2) s1##s2
#define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2)
#ifdef __COUNTER__
#define ANONYMOUS_VARIABLE(str) \
CONCATENATE(str, __COUNTER__)
#else
#define ANONYMOUS_VARIABLE(str) \
CONCATENATE(str, __LINE__)
#endif
@eruffaldi
eruffaldi / wp_timeline_express.php
Created October 20, 2016 09:35
Fix for multiple timlines
// announcement_user_tag
function add_custom_timeline_express_field( $custom_fields ) {
$custom_fields = array(
array(
'name' => __( 'Tag', 'timeline-express' ),
'desc' => __( 'this is an example user defined text field.', 'timeline-express' ),
'id' => 'announcement_user_tag',
'type' => 'text_medium',
)
);
@eruffaldi
eruffaldi / igrpstats.m
Last active October 24, 2016 08:12
Matlab grpstats variant for exporting all the groups and the associations. This just pulls out the internal mgrp2idx
% Generalzied: [row2group,grouplabels,group2row]= igrpstats(x,group)
%
% Extraction of Mathworks code from 2016A
%
% All copyrights to Mathworks
function [row2group,grouplabels,group2row,groupnames]= igrpstats(x,group)
[rows,cols] = size(x);
if (nargin<1)
@eruffaldi
eruffaldi / setup.bash
Last active October 25, 2016 22:02
gazebo_ros for OSX
# Alternatively use:
# wstool set PACKAGE --git SOURCE
# wstool updaye
DISTRO=indigo-devel
git clone https://github.com/ros-simulation/gazebo_ros_pkgs.git -b ${DISTRO} src/gazebo_ros_pkgs
git clone https://github.com/ros-controls/control_toolbox.git -b ${DISTRO} src/control_toolbox
git clone https://github.com/ros-controls/realtime_tools.git -b ${DISTRO} src/realtime_tools
git clone https://github.com/ros-controls/ros_control.git -b ${DISTRO} src/ros_control
import numpy as np
import cv2
def interp_rgb(a,b,n):
a = np.uint8([[a]])
b = np.uint8([[b]])
a1 = cv2.cvtColor(a,cv2.COLOR_BGR2HSV)
b1 = cv2.cvtColor(b,cv2.COLOR_BGR2HSV)
# 1 1 3
ll = np.linspace(0,1,n)
@eruffaldi
eruffaldi / altany.hpp
Created November 21, 2016 01:47
Alternative Thread Local Storage C++11
//
// Implementation of N4562 std::experimental::any (merged into C++17) for C++11 compilers.
//
// See also:
// + http://en.cppreference.com/w/cpp/any
// + http://en.cppreference.com/w/cpp/experimental/any
// + http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4562.html#any
// + https://cplusplus.github.io/LWG/lwg-active.html#2509
//
//
@eruffaldi
eruffaldi / form.py
Created November 27, 2016 21:37
Industria 4.0 converter
# Industria 4.0 Converter
from collections import OrderedDict,defaultdict
import csv
x = open("form.tsv","rb")
dr = csv.reader(x,delimiter="\t",quotechar="\"")
person = dict()
# load headers
h = [y.strip().strip("\"") for y in dr.next()]
{
"folders":
[
{
"path": "."
}
],
"build_systems":
[
{