Skip to content

Instantly share code, notes, and snippets.

@chuanjin
chuanjin / docker_cmd.sh
Created April 27, 2020 14:02
Docker command
docker exec -it my_instance /bin/bash
docker attach my_instance # Go into docker instance
docker ps # Check runing instances
docker ps -a # Check all instances
docker start instance_name # Start a docker instance
@chuanjin
chuanjin / secureMQTT.md
Last active March 16, 2019 18:42
MQTT TLS/SSL

Let's configure the mosquitto MQTT broker to use TLS security. There are a few steps needed for self-signed CA and certificates:

  • Generate a certificate authority certificate and private key.
  • Generate a server private key and certificate signed by the CA.
  • Distribute the CA certificate to the server and start mosquitto with the CA certificate and server private key and certificate.
  • Distribute the CA certificate to the client for server verification.
  • Start the client with the CA certificate.

If client certificates are required, then:

from nose import with_setup
def setup_module(module):
print ("") # this is to get a newline after the dots
print ("Start testing module: " + str(module))
def teardown_module(module):
print ("") # this is to get a newline after the dots
print ("Done testing module: " + str(module))
  • Check the system 64 or 22 bit:
    getconf LONG_BIT

  • Check space usage:
    df -h

  • Check processes:
    ps ux or ps -ef or lsof -n -i

  • Kill a process:

@chuanjin
chuanjin / sync_upstream.sh
Last active October 24, 2018 14:53
Sync local master with upstream repo
#!/bin/bash
if [ "$1" == "" ]
then
echo "Missing argument: path"
exit 1
else
folder=${1}
fi
@chuanjin
chuanjin / gist:c4ae6ffeb4c92fd7e1e7882c6bf9f7e5
Created May 29, 2018 13:25
bitbake get DISTRO_VERSION and return version number
bitbake -e core-image-x | grep ^DISTRO_VERSION= | awk -F= '{print $2}' | sed 's/\"//g'
@chuanjin
chuanjin / git-workflow.md
Last active March 6, 2019 19:50
my personal Git workflow

Git workflow

This is my personal Git workflow, basically applicable with GitHub, GitLab and Bitbucket, but probably not Gerrit.

Let's assume there is a cool project on GitHub you will work with and collaborate with other contributors, which is called cool with the git URL like: [email protected]:CoolProject/cool.git.

Preparation

@chuanjin
chuanjin / netpack_rewrite.sh
Created November 20, 2017 22:08
Rewrite the network package, which will be used for tcpreplay
#!/bin/bash
usage()
{
printf "\n"
printf "Usage: $0 [-h] [-f]\n";
printf " -h : Display this help.\n";
printf " -f : INPUT FILE name.\n";
printf " -i : Destination IP address.\n";
printf " -m : Destination MAC address.\n";
printf "\n"
import calendar
import datetime
def get_fist_monday(year, month):
month_range = calendar.monthrange(year, month)
first_date = datetime.date(year, month, 1)
delta = 7 - (month_range[0] - calendar.MONDAY )
return first_date + datetime.timedelta(days = delta)
def get_last_sunday(year, month):
import socket
import select
UDP_IP = "127.0.0.1"
IN_PORT = 5005
timeout = 3
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, IN_PORT))