Skip to content

Instantly share code, notes, and snippets.

@silgon
silgon / incentive.py
Created September 15, 2016 12:58
Stackoverflow question #39349894
import numpy as np # import library for linear algebra and more utilities
from numpy.random import randint # import random int
# initialize random seed
np.random.seed(4)
houses = ["Gryffindor","Slytherin", "Hufflepuff", "Ravenclaw"]
houses_points = []
for _ in houses:
# houses_points.append(randint(0, 100, randint(60,100)))
@silgon
silgon / .block
Last active April 10, 2017 13:10
Randomly Generated Fill Graph
license: gpl-3.0
@silgon
silgon / carousel.html
Created April 10, 2017 13:54
Example Carousel
@silgon
silgon / .block
Last active April 10, 2017 15:09
Randomly Generated Gradient Fill Graph
license: gpl-3.0
@silgon
silgon / raspberry_pi requisites
Last active July 5, 2017 18:42
HiLink Send Message
sudo usb_modeswitch -v 12d1 -p 1f01 -J
@silgon
silgon / gist:194cfaefe6716b0cea6212215ac36b0d
Created August 9, 2017 19:36
Needed compilation in machine for grpc in my laptop
# in root of grpc project
GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .
@silgon
silgon / on_change_ip.sh
Created September 27, 2017 15:03
On IP change with bash
#! /bin/bash
# path to save your ip (it shall always contain only one line, if not it can cause problems)
FILE_PATH=/tmp/myip.txt
# get your IP from an external server (with a regex to verify that it is an ip)
EXT_IP=$(curl http://ipecho.net/plain | grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")
# if the file doesn't exist, create it
[ ! -f $FILE_PATH ] && touch $FILE_PATH
# if your ip changed, do something
if [ -n "$EXT_IP" ] && [ "$EXT_IP" != "$(cat $FILE_PATH)" ]; then
echo $EXT_IP > $FILE_PATH
@silgon
silgon / wifi_reconnect.sh
Created November 12, 2017 09:59
Reconnect Raspberry Pi wifi when no connection appears
#! /bin/bash
# This code verify that the computer has an ip. When this is not true
# Cron command
# */5 * * * * /my/path/wifi_reconnect
# ip addr show wlan0 |awk -F ":" '/inet addr/{split($2,a," ");print a[1]}'
IP=$(ifconfig wlan0 | awk '$1 == "inet" {print $2}')
if [ -z $IP ]; then
# wait for 10 seconds and ask again for your ip
@silgon
silgon / pinger.sh
Created November 15, 2017 16:17
this script is a workaround for cronjob (because my router sometimes fails to interconnect my computers)
#! /bin/bash
# this script is a workaround for cronjob (because my router sometimes fails to interconnect my computers)
ips=( "192.168.0.1" "192.168.0.2" "192.168.0.3" )
for i in "${ips[@]}"; do
:
ping -c1 -W5 $i >/dev/null && echo $i' up' || echo $i' down'
done
@silgon
silgon / frequency_prediction.py
Last active February 16, 2018 22:56
Frequency Prediction
# code to solve https://stackoverflow.com/q/47932589/2237916
import numpy as np
import tflearn
from random import shuffle
# parameters
n_input=100
n_train=2000
n_test = 500
# generate data