Skip to content

Instantly share code, notes, and snippets.

View davibe's full-sized avatar

Davide Bertola davibe

  • Vercelli/Torino, Piedmont, Italy
View GitHub Profile
@davibe
davibe / OptionalUseExample1.kt
Last active November 10, 2017 09:16
Struggling with kotlin optionals a bit
class OptionalUseExample1 {
val opt1: String?
val opt2: String?
val opt3: String?
// ...
// it's kind of repetitive to check/unwrap properties every time i use them
fun work(): String {
@davibe
davibe / kotlinStructuredConcurrency.kt
Created November 13, 2017 06:55
Example of structured concurrency in Kotlin
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel
import java.util.*
/*
* Structured concurrency means that child co-routines should die when their father dies
* http://libdill.org//structured-concurrency.html
*
* In kotlin in order to have parent->child relationship you need to explicitly pass
* the coroutineContext to the child coroutine.
@davibe
davibe / rpi_zero_w_wifiapclientbridge_configure.sh
Last active September 29, 2018 09:59 — forked from lukicdarkoo/configure.sh
Raspberry Pi: AP + client mode
#!/bin/sh
# The script configures simultaneous AP and Managed Mode Wifi on Raspberry Pi Zero W (should also work on Raspberry Pi 3)
# Usage: curl https://gist.githubusercontent.com/lukicdarkoo/6b92d182d37d0a10400060d8344f86e4/raw | sh -s WifiSSID WifiPass APSSID APPass
# Licence: GPLv3
# Author: Darko Lukic <lukicdarkoo@gmail.com>
# Special thanks to: https://albeec13.github.io/2017/09/26/raspberry-pi-zero-w-simultaneous-ap-and-managed-mode-wifi/
MAC_ADDRESS="$(cat /sys/class/net/wlan0/address)"
CLIENT_SSID="${1}"
CLIENT_PASSPHRASE="${2}"
@davibe
davibe / rpicam-gstreamer.txt
Created October 19, 2018 06:15 — forked from muellermartin/rpicam-gstreamer.txt
Stream video from Raspberry Pi with camera attached to CSI port via RTP (UDP) using GStreamer
Useful Links:
- http://stackoverflow.com/questions/25941171/how-to-get-gstreamer1-0-working-with-v4l2-raspicam-driver
- http://raspberrypi.stackexchange.com/questions/26675/modern-way-to-stream-h-264-from-the-raspberry-cam
- http://stackoverflow.com/questions/13154983/gstreamer-rtp-stream-to-vlc
- http://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/gst/rtp/README
- http://archpi.dabase.com/#sending-and-receiving-pi-camera-video-over-the-network
- http://emmanuelgranatello.blogspot.de/2013/10/raspberry-pi-gstreamer-streaming-h264.html
- http://stackoverflow.com/questions/15712983/why-rtp-streaming-of-a-avi-video-file-fails-to-be-received
sudo apt-get update && sudo apt-get install -y hostapd dnsmasq iptables-persistent
export DEBIAN_FRONTEND=noninteractive
export ID=$(cat /sys/class/net/wlan0/address | sed 's/://g')
export AP_NAME=AP_$(date +%s)
export AP_PASS=raspberry
export WIFI_NAME=wifi_name
export WIFI_PASS=wifi_password
sudo bash -c 'cat > /etc/network/interfaces.d/ap' << EOF
@davibe
davibe / kotlin_channels_combineLatest.kt
Created November 12, 2017 14:44
I tried to implement combineLatest for kotlin channels with corutines
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.experimental.selects.select
import java.util.*
/*
* Combine multiple channels into one `output` channel.
@davibe
davibe / network_security_config.xml
Created August 21, 2019 15:20
app/src/main/res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
@davibe
davibe / monopattini_torino_email_bezzon_municipale.txt
Last active November 9, 2019 19:53
Monopattini torino email bezzon municipale
Davide ----
Salve,
Mi scuso per il disturbo. Ho provato a cercare chiarimenti tramite la email generica della polizia municipale ma ho ricevuto risposte che non mi sono sembrate aderenti alle mie domande. Per questo motivo ho deciso di scrivere direttamente a lei.
In questi giorni molto del rumore causato dalle vicende legate alla mobilità elettrica si basano sul fatto che la polizia equipara i monopattini a motocicli. Il riferimento normativo su cui vi basate non mi sembra sia direttamente il codice della strada, ma piuttosto il "decreto del 31
gennaio 2003". Tale decreto è stato emanato per recepire una direttiva europea del 2002.
Rif: https://www.asaps.it/1705-decreto_31_gennaio_2003__gu_n_123_del_29-5-2003-_suppl_ordinario_n86.html
Nel 2013 però è stato emanato un altro regolamento europeo "168/2013" che è del tutto analogo alla direttiva del 2002 ma rende chiaro che i mezzi che non hanno un posto a sedere sono esclusi esattamente come i mezzi per disabili e i mezzi che costruttivamente vanno a meno di
@davibe
davibe / laptop_thinnest_2019.md
Created November 9, 2019 20:12
Thinnest 15" laptops (macbook pro alternatives) - 2019
[
{
"type": 4,
"data": {
"href": "http://localhost:1234/workflow1.html",
"width": 877,
"height": 927
},
"timestamp": 1570639615140
},