Skip to content

Instantly share code, notes, and snippets.

View rlogiacco's full-sized avatar
💭
I may be slow to respond, be patient...

Roberto Lo Giacco rlogiacco

💭
I may be slow to respond, be patient...
View GitHub Profile
@rlogiacco
rlogiacco / start.sh
Last active January 10, 2017 12:15
Docker 1.12 for Windows start script
#!/bin/bash
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong... Press any key to continue..."' EXIT
VM=default
DOCKER_MACHINE=./docker-machine.exe
export PATH="/c/Program Files/Docker Toolbox:$PATH"
export HTTP_PROXY=10.235.34.235:3129
export HTTPS_PROXY=10.235.34.235:3129
for n in $(docker-machine ls --format {{.Name}}); do
@rlogiacco
rlogiacco / rsync-completed.sh
Last active November 11, 2016 22:24
Keep movies folder synchronized
#!/bin/bash
exec 5>&1
SHARE="/mnt/TORRENT/completed"
LOCAL="/media/STORAGE/@temp"
FILES="/media/STORAGE/@new"
TIMESTAMP="$(date '+%d %h %y %H:%M:%S')"
LOCK="rsync-completed.lock"
# acquire lock
@rlogiacco
rlogiacco / 0_reuse_code.js
Created April 14, 2016 23:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rlogiacco
rlogiacco / pwrbutton.sh
Created January 6, 2016 00:25
PlusberryPi Power
#!/bin/bash
# monitor GPIO pin 21 for shutdown signal
# export GPIO pin 21 and set to input with pull-up
echo "21" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio21/direction
# wait for pin to go low
while [ true ]; do
if [ "$(cat /sys/class/gpio/gpio21/value)" == '0' ]; then
@rlogiacco
rlogiacco / templog.sh
Created January 6, 2016 00:13
RPi temperature monitor
#!/bin/bash
LOG_FILE=$1
while :
do
temp=`/opt/vc/bin/vcgencmd measure_temp`
temp=${temp:5:16}
echo $(date '+%F %H:%M:%S') [$temp] >>LOG_FILE
sleep 10
done
@rlogiacco
rlogiacco / pingpair_ack.ino
Last active September 19, 2022 19:14
nRF24 Arduino test sketch
/*
// March 2014 - TMRh20 - Updated along with High Speed RF24 Library fork
// Parts derived from examples by J. Coliz <maniacbug@ymail.com>
*/
/**
* Example for efficient call-response using ack-payloads
*
* This example continues to make use of all the normal functionality of the radios including
* the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well.
* This allows very fast call-response communication, with the responding radio never having to
@rlogiacco
rlogiacco / Reset.h
Created September 8, 2015 09:31
Arduino reset via software
#include <avr/io.h>
#include <avr/wdt.h>
#define RESET() wdt_enable(WDTO_30MS); while(1) {}
@rlogiacco
rlogiacco / focus.js
Last active August 29, 2015 14:22
AngularJS UI Utils
angular.module("ui-utils.focus", ['ng'])
.directive('focusMe', function($log) {
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.focusMe, function(value) {
if(value === true) {
$log.debug("value=" + element[0].value);
element[0].focus();
scope[attrs.focusMe] = false;
}
@rlogiacco
rlogiacco / ButtonDebounce.ino
Last active October 2, 2019 19:17
Debounce a button
#define DEBOUNCE 15
#define DMASK ((uint16_t)(1<<DEBOUNCE)-1)
#define DF (1<<(uint16_t)(DEBOUNCE-1))
#define DR (DMASK-DF)
// macro for detection of raising edge and debouncing
#define DRE(signal, state) ((state=((state<<1)|(signal&1))&DMASK)==DR)
// macro for detection of falling edge and debouncing
#define DFE(signal, state) ((state=((state<<1)|(signal&1))&DMASK)==DF)
@rlogiacco
rlogiacco / Blinker.ino
Created June 3, 2015 12:05
Pseudo Concurrency
#define LED_PIN 13
#define BTN_PIN 2
int volatile prog = 0;
void btnPress() {
// cycle over the available programs
// it can be done in a much compact and simpler way, but I believe this is the most
// simple and clear way to describe it
// some sort of debouncing would be required, but I don't add it here for sake of simplicity
if (prog == 0) {