Docker no space left on device

Docker uses /var/lib/docker to store all container images and volumes sometimes the disk mounted to /var/lib/docker is full and gives error no space left on device

One way to fix this remove all unused containers, for a full clean up you can use this

docker system prune --all --force --volumes

Increase available disk space in docker

One another method if you have space in your home folder move the docker directory to home folder and create system link to it

sudo systemctl stop docker
sudo mv /var/lib/docker /home/
sudo ln -s /home/docker/ /var/lib/
sudo systemctl start docker

Remove images that one month or old

docker system prune --filter "until=240h"

Git quick checklist

Resets all changes done

git reset --hard

Give a git commit without changing the previous commit message

git commit --amend --no-edit

Modify last commit message

git commit --amend -m "An new updated commit message"

Push to master

git push origin HEAD:refs/for/master

Discard all changes made to a file

discard changes in locally modified file

 git restore main.cpp

git delete local branch

git branch --delete old-branch

Modenize you C++ code using clang tools

Consider a simple c++ porgram like this below

#include<iostream>

// Base class
class Vehicle {
  public:
    string brand = "Ford";
    void honk() {
      cout << "Tuut, tuut! \n" ;
    }
};

// Derived class
class Car: public Vehicle {
  public:
    string model = "Mustang";
};

int main() {
  Car myCar;
  myCar.honk();
  cout << myCar.brand + " " + myCar.model;
  return 0;
}

This is plain old method C++14,C++17 uses new syntax methods, t get familiarize with those you can use clang-tidy tool.

Install clang-tidy tool

sudo apt-get install clang-tidy

use the below command to get tips on how to modernize the code

clang-tidy --checks='modernize*, readability*' simple.cpp -- -std=c++17

It will give information like this

7173 warnings and 4 errors generated.
Error while processing /home/gharshan/Desktop/simple.cpp.
/home/gharshan/Desktop/simple.cpp:6:5: error: unknown type name 'string'; did you mean 'std::string'? [clang-diagnostic-error]
    string brand = "Ford";
    ^~~~~~
    std::string
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stringfwd.h:79:33: note: 'std::string' declared here
  typedef basic_string<char>    string;   
                                ^
/home/gharshan/Desktop/simple.cpp:7:10: warning: method 'honk' can be made static [readability-convert-member-functions-to-static]
    void honk() {
         ^
    static 
/home/gharshan/Desktop/simple.cpp:8:7: error: use of undeclared identifier 'cout'; did you mean 'std::cout'? [clang-diagnostic-error]
      cout << "Tuut, tuut! \n" ;
      ^~~~
      std::cout
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/iostream:61:18: note: 'std::cout' declared here
  extern ostream cout;          /// Linked to standard output
                 ^
/home/gharshan/Desktop/simple.cpp:15:5: error: unknown type name 'string'; did you mean 'std::string'? [clang-diagnostic-error]
    string model = "Mustang";
    ^~~~~~
    std::string
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stringfwd.h:79:33: note: 'std::string' declared here
  typedef basic_string<char>    string;   
                                ^
/home/gharshan/Desktop/simple.cpp:18:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
int main() {
~~~ ^
auto       -> int
/home/gharshan/Desktop/simple.cpp:21:3: error: use of undeclared identifier 'cout'; did you mean 'std::cout'? [clang-diagnostic-error]
  cout << myCar.brand + " " + myCar.model;
  ^~~~
  std::cout
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/iostream:61:18: note: 'std::cout' declared here
  extern ostream cout;          /// Linked to standard output
                 ^
Suppressed 7171 warnings (7171 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).

Error launching application on Android SDK built for x86.

I created a simple flutter app which works fine and the second app created is throwing the below error

Error: ADB exited with exit code 1
adb: failed to install 
simpleapp.apk: Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]
Error launching application on Android SDK built for x86.

The default configuration storage is too small and may get this error when the emulator runs out of storage when you install.

To fix this error either modify the emulator configuration or uninstall before you install another app.

Open the Android Virtual Device (AVD) manager in Android Studio, edit the emulator and increase “Internal Storage” and restart the emulator.

Increase the Internal Storage and save it. This will fix the issue.

ASTERISK – netsock2.c:305 ast_sockaddr_resolve: getaddrinfo(“raspbx”, “(null)”, …): Temporary failure in name resolution

Sometime when you start running Asterisk you may get the below error, which causes delay in call connection etc.

      > 0x104be738 -- Strict RTP learning after remote address set to: 192.168.1.103:14446
    -- Executing [1002@PA:1] Dial("SIP/1001-00000000", "SIP/1002,20") in new stack
[Sep  2 10:32:37] WARNING[772][C-00000000]: app_dial.c:2527 dial_exec_full: Unable to create channel of type 'SIP' (cause 20 - Subscriber absent)
  == Everyone is busy/congested at this time (1:0/0/1)
    -- Auto fallthrough, channel 'SIP/1001-00000000' status is 'CHANUNAVAIL'
    -- Executing [h@PA:1] Set("SIP/1001-00000000", "CDR(userfield)= Quality: R/W:alaw/alaw N:(alaw) Priority : 1") in new stack
    -- Registered SIP '1002' at 192.168.1.102:15998
       > Saved useragent "MizuDroid/3.1.0" for peer 1002
[Sep  2 10:32:49] NOTICE[747]: chan_sip.c:24646 handle_response_peerpoke: Peer '1002' is now Reachable. (6ms / 2000ms)
    -- Registered SIP '1001' at 192.168.1.103:14448
[Sep  2 10:32:54] ERROR[747][C-00000001]: netsock2.c:305 ast_sockaddr_resolve: getaddrinfo("raspbx", "(null)", ...): Temporary failure in name resolution
[Sep  2 10:32:54] WARNING[747][C-00000001]: acl.c:835 resolve_first: Unable to lookup 'raspbx'
[Sep  2 10:32:59] ERROR[747][C-00000001]: netsock2.c:305 ast_sockaddr_resolve: getaddrinfo("A.ROOT-SERVERS.NET", "(null)", ...): Temporary failure in name resolution
[Sep  2 10:32:59] WARNING[747][C-00000001]: acl.c:835 resolve_first: Unable to lookup 'A.ROOT-SERVERS.NET'
  == Using SIP RTP CoS mark 5
       > 0x104c2a48 -- Strict RTP learning after remote address set to: 192.168.1.103:14450
    -- Executing [1002@PA:1] Dial("SIP/1001-00000001", "SIP/1002,20") in new stack
[Sep  2 10:33:04] ERROR[774][C-00000001]: netsock2.c:305 ast_sockaddr_resolve: getaddrinfo("raspbx", "(null)", ...): Temporary failure in name resolution
[Sep  2 10:33:04] WARNING[774][C-00000001]: acl.c:835 resolve_first: Unable to lookup 'raspbx'
[Sep  2 10:33:09] ERROR[774][C-00000001]: netsock2.c:305 ast_sockaddr_resolve: getaddrinfo("A.ROOT-SERVERS.NET", "(null)", ...): Temporary failure in name resolution
[Sep  2 10:33:09] WARNING[774][C-00000001]: acl.c:835 resolve_first: Unable to lookup 'A.ROOT-SERVERS.NET'

The issue is because it is unable to resolve the name, the fix is edit /etc/hosts file

vim /etc/hosts

so default /etc/hosts file content may look like this

127.0.0.1       localhost.localdomain           localhost

Add one more line

127.0.0.1       localhost.localdomain           raspbx

The raspbx can be changed with whatever mentioned in the error acl.c:835 resolve_first: Unable to lookup ‘raspbx’

How to configure Asterisk `menuselect` build options through commandline

If we are automating installation of Asterisk through a shell script or cmake and we want to enable and disable features in Asterisk, we can use the below option. Normally we use

make menuconfig

which gives us a console based gui and selects features, this can be done without the menuconfig gui.

This is the command line option for menuconfig

make menuselect.makeopts
menuselect/menuselect --enable chan_sip menuselect.makeopts

Asterisk – Failed to register ‘bucket’ object type in Bucket sorcery

Sometimes when you compile Asterisk manually and when run you many get an error like this

#./asterisk -cvvv
Asterisk 13.3.2, Copyright (C) 1999 - 2014, Digium, Inc. and others.
Created by Mark Spencer 
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
[ Initializing Custom Configuration Options ]
  == Parsing '/etc/asterisk/extconfig.conf': Found
  == Registered 'audio' codec 'g723' at sample rate '8000' with id '1'
  == Created cached format with name 'g723'
  == Registered 'audio' codec 'ulaw' at sample rate '8000' with id '2'
  == Created cached format with name 'ulaw'
  == Registered 'audio' codec 'alaw' at sample rate '8000' with id '3'
  == Created cached format with name 'alaw'
  == Registered 'audio' codec 'gsm' at sample rate '8000' with id '4'
  == Created cached format with name 'gsm'
  == Registered 'audio' codec 'g726' at sample rate '8000' with id '5'
  == Created cached format with name 'g726'
  == Registered 'audio' codec 'g726aal2' at sample rate '8000' with id '6'
  == Created cached format with name 'g726aal2'
  == Registered 'audio' codec 'adpcm' at sample rate '8000' with id '7'
  == Created cached format with name 'adpcm'
  == Registered 'audio' codec 'slin' at sample rate '8000' with id '8'
  == Created cached format with name 'slin'
  == Registered 'audio' codec 'slin' at sample rate '12000' with id '9'
  == Created cached format with name 'slin12'
  == Registered 'audio' codec 'slin' at sample rate '16000' with id '10'
  == Created cached format with name 'slin16'
  == Registered 'audio' codec 'slin' at sample rate '24000' with id '11'
  == Created cached format with name 'slin24'
  == Registered 'audio' codec 'slin' at sample rate '32000' with id '12'
  == Created cached format with name 'slin32'
  == Registered 'audio' codec 'slin' at sample rate '44100' with id '13'
  == Created cached format with name 'slin44'
  == Registered 'audio' codec 'slin' at sample rate '48000' with id '14'
  == Created cached format with name 'slin48'
  == Registered 'audio' codec 'slin' at sample rate '96000' with id '15'
  == Created cached format with name 'slin96'
  == Registered 'audio' codec 'slin' at sample rate '192000' with id '16'
  == Created cached format with name 'slin192'
  == Registered 'audio' codec 'lpc10' at sample rate '8000' with id '17'
  == Created cached format with name 'lpc10'
  == Registered 'audio' codec 'g729' at sample rate '8000' with id '18'
  == Created cached format with name 'g729'
  == Registered 'audio' codec 'speex' at sample rate '8000' with id '19'
  == Created cached format with name 'speex'
  == Registered 'audio' codec 'speex' at sample rate '16000' with id '20'
  == Created cached format with name 'speex16'
  == Registered 'audio' codec 'speex' at sample rate '32000' with id '21'
  == Created cached format with name 'speex32'
  == Registered 'audio' codec 'ilbc' at sample rate '8000' with id '22'
  == Created cached format with name 'ilbc'
  == Registered 'audio' codec 'g722' at sample rate '16000' with id '23'
  == Created cached format with name 'g722'
  == Registered 'audio' codec 'siren7' at sample rate '16000' with id '24'
  == Created cached format with name 'siren7'
  == Registered 'audio' codec 'siren14' at sample rate '32000' with id '25'
  == Created cached format with name 'siren14'
  == Registered 'audio' codec 'testlaw' at sample rate '8000' with id '26'
  == Created cached format with name 'testlaw'
  == Registered 'audio' codec 'g719' at sample rate '48000' with id '27'
  == Created cached format with name 'g719'
  == Registered 'audio' codec 'opus' at sample rate '48000' with id '28'
  == Created cached format with name 'opus'
  == Registered 'image' codec 'jpeg' at sample rate '0' with id '29'
  == Created cached format with name 'jpeg'
  == Registered 'image' codec 'png' at sample rate '0' with id '30'
  == Created cached format with name 'png'
  == Registered 'video' codec 'h261' at sample rate '0' with id '31'
  == Created cached format with name 'h261'
  == Registered 'video' codec 'h263' at sample rate '0' with id '32'
  == Created cached format with name 'h263'
  == Registered 'video' codec 'h263p' at sample rate '0' with id '33'
  == Created cached format with name 'h263p'
  == Registered 'video' codec 'h264' at sample rate '0' with id '34'
  == Created cached format with name 'h264'
  == Registered 'video' codec 'mpeg4' at sample rate '0' with id '35'
  == Created cached format with name 'mpeg4'
  == Registered 'video' codec 'vp8' at sample rate '0' with id '36'
  == Created cached format with name 'vp8'
  == Registered 'text' codec 'red' at sample rate '0' with id '37'
  == Created cached format with name 'red'
  == Registered 'text' codec 't140' at sample rate '0' with id '38'
  == Created cached format with name 't140'
  == Registered 'audio' codec 'none' at sample rate '8000' with id '39'
  == Created cached format with name 'none'
  == Parsing '/etc/asterisk/asterisk.conf': Found
  == Sorcery registered wizard 'bucket'
  == Sorcery registered wizard 'bucket_file'
  == Parsing '/etc/asterisk/sorcery.conf': Found
Cannot update type 'bucket' in module 'core' because it has no existing documentation!
Failed to register 'bucket' object type in Bucket sorcery
Failed: ast_bucket_init

This means that Asterisk was built with documentation support but the documentation is not installed. Either you may be missing the path that you can fix in

 /etc/asterisk.conf 

If you dont want documentation the easy fix is using

 --disable-xmldoc 

while configuring use disable doc

./configure --disable-xmldoc

How Remove Files completely from git repository history

Sometimes it may happen that one of our team members commit unwanted files to git repo and later we may delete it. But the files are still in git history and on every clone it will consume too much bandwidth. Issue the below commands to completely delete file from git repo history.

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch filetoremove.zip -r' --prune-empty --tag-name-filter cat -- --all
 

Replace filetoremove.zip with the file you want to remove.

git push origin master --force

Push your changes to remote and try taking a new fresh clone it will take be of lesser size since the deleted files are excluded

How To Use SocketCAN With CLI

The native can interface usually named as can0,can1 etc

Identifying CAN interface

ip link show

if you can see can0 then, issue below command to get more details

ip addr ls dev can0

you can also use ifconfig command

ifconfig can0

or

ifconfig -a

Configuring And Enabling The SocketCAN Interface

sudo ip link set can0 type can bitrate 500000

This configures can0 for 500KB baud rate
Bring up the interface

sudo ip link set up can0

Send/Receive Data On SocketCAN

If you want to send/receive data on the CAN interface, you need can-utils package installed in your system

sudo apt install can-utils

To send data to the CAN bus, use the cansend utility:

cansend can0 123#1122334455667788

here ID is 0x123 and the data bytes are 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88.
To see received messages on can0 interface

candump can0

Happy Hacking 🙂