Skip to content

Instantly share code, notes, and snippets.

View stefanofiorentino's full-sized avatar

Stefano Fiorentino stefanofiorentino

View GitHub Profile
@stefanofiorentino
stefanofiorentino / gist:fd2982d2d42df9d55afe
Last active November 21, 2015 09:17 — forked from anonymous/gist:a57883a80e02b4bab701
How to get all iphone, ipad, windows phone and android icons from "App Icon Template 4.1"
#!/bin/bash
# clear terminal window
clear
# variabili per creare sotto cartelle iOS, Android e WP
export RET_PATH=$PWD
###### iOS
mkdir ./iOS
@stefanofiorentino
stefanofiorentino / libmicrohttpd.diff
Created December 11, 2017 14:31
diff to compile json-rpc-cpp on ubuntu 14.04
--- a/src/jsonrpccpp/server/connectors/httpserver.cpp
+++ b/src/jsonrpccpp/server/connectors/httpserver.cpp
@@ -43,22 +43,8 @@ IClientConnectionHandler *HttpServer::GetHandler(const std::string &url) {
bool HttpServer::StartListening() {
if (!this->running) {
- const bool has_epoll =
- (MHD_is_feature_supported(MHD_FEATURE_EPOLL) == MHD_YES);
- const bool has_poll =
- (MHD_is_feature_supported(MHD_FEATURE_POLL) == MHD_YES);
@stefanofiorentino
stefanofiorentino / gist:91ac92bd571d8d380fcd452922480ffd
Last active January 23, 2019 11:26
rename all cpp files to hpp extension
#!/bin/bash
find . -name "*.cpp" | grep "cpp$" | sed 's/cpp$//g' | xargs -r -n1 -I {} echo mv {}cpp {}hpp
find . -name "*.hpp" | xargs -r -n1 -I {} sed -i '1s;^;#pragma once\n;' {}
@stefanofiorentino
stefanofiorentino / git-gone
Last active December 23, 2021 08:43
git script to add to $PATH to be launched by `git gone` or `git gone --force` (it only print commands to issue)
#!/bin/bash
git fetch
REMOTE=origin
if [ $# -ge 1 ]; then
REMOTE=$1
fi
echo "Pruning ${REMOTE}: $#"
@stefanofiorentino
stefanofiorentino / git-repos
Last active May 4, 2020 10:39
git script to add to $PATH to get all sub-directories' repository commit sha
#!/bin/bash
GIT_REPOS_HOME=$PWD \
find . -type d -name '.git*' ! -path "*/poky-tmp/*" 2>/dev/null | \
sed 's/\.git$//g' | \
xargs -I '{}' sh -c 'readlink -e {};' | \
uniq | \
sort | \
xargs -I '{}' sh -c 'cd {}; echo "dir: $(pwd) url: $(git config --get remote.origin.url) branch: $(git rev-parse --abbrev-ref HEAD) hash: $(git rev-parse HEAD)"; cd $GIT_REPOS_HOME;'
@stefanofiorentino
stefanofiorentino / gist:aa0e76dadfd1fdb0cb0267c28363e306
Created November 7, 2019 16:47
c/c++ function to translate RGB bash terminal colot
// based on https://gist.github.com/mhulse/b11e568260fb8c3aa2a8
void UserLedManager::print_terminal_background_color(const int &r, const int &g, const int &b) const
{
auto r_weight = r < 75 ? 0 : (r - 35) / 40;
auto g_weight = g < 75 ? 0 : (g - 35) / 40;
auto b_weight = b < 75 ? 0 : (b - 35) / 40;
int status = (r_weight * 6 * 6 + g_weight * 6 + b_weight + 16);
fprintf(stdout, "\e[48;5;%dm %3d \e[0m", status, status);
fflush(stdout);
}
@stefanofiorentino
stefanofiorentino / demo.sh
Created January 15, 2020 13:34
Laboratorio IoT @ Relewant SA - 15 gennaio 2020
# SHELL 1:
tmux
Ctrl+b \"
Ctrl+b o
# SHELL 1: clean docker env
docker ps -aq | xargs -r -n1 docker rm -f
docker images -aq | xargs -r -n1 docker rmi -f
clear
@stefanofiorentino
stefanofiorentino / git-amend
Created January 20, 2020 10:27
automatic git commit --amend with reset authors (and commit timestamp!!)
#!/bin/bash
git commit --amend --reset-author
# - Find libjsoncpp
# Find the native libjsoncpp includes and libraries
#
# JSONCPP_INCLUDE_DIR - where to find json.h, etc.
# JSONCPP_LIBRARIES - List of libraries when using libjsoncpp.
# JSONCPP_FOUND - True if libjsoncpp found.
if (NOT JSONCPP_INCLUDE_DIR)
find_path(JSONCPP_INCLUDE_DIR json/value.h HINTS /usr/include/jsoncpp)
endif()
# - Find libmosquittopp
# Find the native libmosquittopp includes and libraries
#
# MOSQUITTOPP_INCLUDE_DIR - where to find mosquitto.h, etc.
# MOSQUITTOPP_LIBRARIES - List of libraries when using libmosquittopp.
# MOSQUITTOPP_FOUND - True if libmosquittopp found.
if (NOT MOSQUITTOPP_INCLUDE_DIR)
find_path(MOSQUITTOPP_INCLUDE_DIR mosquitto.h)
endif()