Skip to content

Instantly share code, notes, and snippets.

@sven-bock
sven-bock / bash
Created February 7, 2019 08:35
Check battery capacity
upower -i /org/freedesktop/UPower/devices/battery_BAT0
@sven-bock
sven-bock / gist:9f161759a8c91e068c1eb831fc82f5b5
Created December 14, 2018 10:25
C++ Using base and derived constructor
struct Base {
Base(int a) : i(a) {}
int i;
};
struct Derived : Base {
Derived(int a, std::string s) : Base(a), m(s) {}
using Base::Base; // Inherit Base's constructors.
// Equivalent to:
@sven-bock
sven-bock / gist:9069164551fbc63d3ca286650ad8bf67
Created December 7, 2018 11:15
Rename a network device (Ubuntu 16.04)
#Create a file called
/etc/udev/rules.d/70-persistent-net.rules
#Add this and replace address and name:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="02:01:02:03:04:05", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth0"
#Modify the grub configuration
/etc/default/grub
# Replace this line
GRUB_CMDLINE_LINUX=""
# with
@sven-bock
sven-bock / gist:d0fbecd8fd08c8287909aad8dd64a76a
Created September 21, 2018 10:49
Linux command line text replacement or renaming
#Rename multiple files:
rename 's/old-name/new-name/' files
#In file replacements:
sed -i 's/old-name/new-name/g' config.h.in
@sven-bock
sven-bock / wemos_led_dht_captouch.ino
Created September 18, 2018 18:53
Code for a Wemos D1 mini to offer a capacitive touch, show the status on the LED and also read the temperature. Can also be used with a ENC28J60 module as all required pins are still free.
/*
* Code for a Wemos D1 mini to offer a capacitive touch, show the status on the LED and also read the temperature. Can also be used with a ENC28J60 module as all required pins are still free.
*/
////Temperature sensor
#include "DHT.h"
#define DHTPIN D3 //GPIO 0
#define DHTTYPE DHT11
#define INTERVAL_PUBLISHING 5000
DHT dht(DHTPIN, DHTTYPE, 15);
@sven-bock
sven-bock / threadpool.cpp
Last active December 18, 2023 14:02
Sample how to create a boost threadpool in a class
#include <boost/asio/io_service.hpp>
#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
#include <boost/make_shared.hpp>
#include <iostream>
class Bla{
public:
void callback(std::string msg){
pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
@sven-bock
sven-bock / gist:b3df7bd8183d62e05a4bdf23248cbd97
Created June 6, 2018 17:55
Add ssh key to authorized keys to connect by ssh by key
cat ~/.ssh/id_rsa.pub | (ssh user@host "cat >> ~/.ssh/authorized_keys")
@sven-bock
sven-bock / gist:8d00721feef030860f1cbe4be77d322f
Created May 2, 2018 08:51
openssh does not accept dss key type
#Error from /var/log/auth.log upon ssh login when ssh key is not accepted:
userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes [preauth]
sudo nano /etc/ssh/sshd_config
#add this line
PubkeyAcceptedKeyTypes=+ssh-dss
#save and close
#reload service
sudo service sshd reload
@sven-bock
sven-bock / gist:7f1f8336409b2b098ce54a71d2e59947
Created April 30, 2018 13:00
Enable and setup swap on your Raspberry Pi
# install
sudo apt-get update
sudo apt-get install dphys-swapfile
# config
sudo nano /etc/dphys-swapfile
# verify with
free