Skip to content

Instantly share code, notes, and snippets.

View diogopms's full-sized avatar
🏠
Working from home (🇵🇹)

Diogo Serrano diogopms

🏠
Working from home (🇵🇹)
View GitHub Profile
@diogopms
diogopms / pi_motd.sh
Created April 11, 2020 17:56
Raspberry Pi motd custom welcome message
# cp <CONTENT> /etc/profile.d/motd.sh
# echo "" > /etc/motd
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
@diogopms
diogopms / MQTT Bridge - Examples.md
Created February 29, 2020 14:20
MQTT Bridge - Examples

MQTT - Bridge with examples

# All topics in will be forward to your local instance. If the topic contains *remote_cloudmqtt*, it will be trigger to the cloud.

connection cloudmqtt
  address <HOSTNAME>:18967
  remote_username <USERNAME>
  remote_password <PASSWORD>
 clientid repeater-cloudmqtt
@diogopms
diogopms / Multiple Deploy Keys in GitHub.md
Created February 16, 2020 17:04 — forked from mcnamee/Multiple Deploy Keys in GitHub.md
Using multiple GitHub deploy keys on a single server with a single user

Using multiple GitHub deploy keys on a single server with a single user

Within GitHub it is possible to set up two types of SSH key - account level SSH keys and and repository level SSH keys. These repository level SSH keys are known in GitHub as deploy keys.

Deploy keys are useful for deploying code because they do not rely on an individual user account, which is susceptible to change, to “store” the server keys.

There is, however, an ‘issue’ with using deploy keys; each key across all repositories on GitHub must be unique. No one key can be used more than once. This becomes a problem when deploying to repositories to the same server with the same user. If you create two keys, the SSH client will not know which key to use when connecting to GitHub.

One solution is to use an SSH config file to define which key to use in which situation. This isn’t as easy as it seems.. you might try something like this:

@diogopms
diogopms / docker-compose.yaml
Created February 16, 2020 14:38
docker-compose-irc-thelounge
version: '3.7'
services:
thelounge:
image: thelounge/thelounge:latest
container_name: thelounge
expose:
- "9000"
restart: always
volumes:
- ~/.thelounge:/var/opt/thelounge #
@diogopms
diogopms / clear old docker images
Created February 16, 2020 14:23
clear old docker images
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e DRY_RUN=1 spotify/docker-gc
@diogopms
diogopms / create docker image gcp
Created February 16, 2020 14:08
Create docker image in gcr.io (google cloud)
DOCKER_REGISTRY=eu.gcr.io
DOCKER_IMAGE_NAME=<IMAGE_NAME>
echo "Docker login..."
docker login -u _json_key -p "$(cat credentials.json)" https://gcr.io
docker build -t $DOCKER_IMAGE_NAME .
DOCKER_TAG_NAME=$(docker images | grep $DOCKER_IMAGE_NAME | grep latest | awk '{print $3}')
docker tag $DOCKER_TAG_NAME $DOCKER_REGISTRY/<SERVICE>/$DOCKER_IMAGE_NAME
docker push $DOCKER_REGISTRY/<SERVICE>/$DOCKER_IMAGE_NAME
@diogopms
diogopms / docker watch
Created February 16, 2020 14:06
My docker watchtower
docker run -d \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup \
homeassistant unifi-controller thelounge miflora-mqtt-daemon node-red
@diogopms
diogopms / withings.md
Created October 20, 2019 20:30
Get temperature sensors from withings scale and CO2
curl --cookie-jar cookies.txt 'https://account.withings.com/connectionwou/account_login' --data 'email=<USERNAME>&password=<PASSWORD>' --compressed

curl  -b cookies.txt  'https://scalews.withings.com/cgi-bin/v2/measure' --data-binary 'action=getmeashf&meastype=35%2C12&deviceid=<DEVICE_ID>' --compressed
@diogopms
diogopms / reboot_huawei_b593.md
Last active August 28, 2022 14:09
Reboot - Router huawei b593

Reboot - Router huawei b593

Login and save cookie

curl --cookie-jar cookies.txt 'http://192.168.1.1/index/login.cgi' -H 'Cookie: Language=en_us' --data 'Username=admin&Password=CHANGEME' --compressed

Read cookie and reboot request

Here are several different ways to test a TCP port without telnet.

$ cat < /dev/tcp/127.0.0.1/22
SSH-2.0-OpenSSH_5.3
^C

$ cat &lt; /dev/tcp/127.0.0.1/23