Introduction
My collection of Crib sheets and notes to support my aging memory. Nothing fancy, as the site is written in "Mark Down", using mdBook.
About: I am a software developer based in South Wales with an interest in TV accessibility, Ruby, Python, Bash, C, C++ and many other things.
I can be contacted at jontbell40(AT)gmail.com
Random Pictures of my life :-)
Jon
Ruby
A simple Ruby Sentence Swap
@in_str = "This is a string to be reversed"
@instr_a = @in_str.split(" ");
@instr_a.reverse!
@rev = @instr_a.join(" ");
puts "Reversed String = #{@rev}"
Python
Simple Dos2unix python Application.
Note I found that using the same code to make a package between both windows and linux based system often had issues with file directories. This maybe because we only used internally created libraries,this is common in some area. The original libraries perhaps didnt consider cross platform compatibility. Its not something I came across in general. One remaining issue is I still prefer to use Bash to wrap some scripts, which means git-bash on windows, however this does not present itself well in system like uname. I often add switches to handle the different platforms and sub platforms.
import sys
filename = sys.argv[2]
operation = sys.argv[1]
if operation == 'dos2unix':
text = open(filename, 'rb').read().replace(b'\r\n', b'\n')
print(text)
open(filename, 'wb').write(text)
elif operation == 'unix2dos':
text = open(filename, 'r').read().replace('\n', '\r\n')
open(filename, 'w').write(text)
else:
sys.exit('Possible args can be dos2unix or unix2dos')
C++
Lambda functions
int main(int argc, char **argv)
{
std::string A = "Steve";
std::string B = "James";
// A + B declared outside of Lamdba so must be in capture list.
[A,B]( std::string a,std::string b) {
std::cout << "Concatenated strings: "<< A << " " << B; << std::endl;
}(A,B);
}
you can also specify output or use a lambda function in line.
int main(int argc, char **argv)
{
// A + B declared outside of Lamdba so must be in capture list.
std::cout << []()->std::string{
std::string A = "Steve";
std::string B = "James";
std::string C = (A + " " + B);
return C;
}() << std::endl;
}
You can also name lambda functions as such:
test = [](){std::cout << "Hello" << std::endl"};
Note the capture list can capture everything of the parent scop by using [=] or [&] to capture everyhing by reference.
Sample programs to tackle some common interview questions.
A sentence reverse application.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *in_str = "This is a string to be reversed";
int cpy_char(char* dst,char *src,int size)
{
int i= 0;
for (i = 0; i<size; i++)
{
dst[i] =(char) src[i];
}
return i;
}
char *reverse_sen(char *in_str)
{
int size=strlen(in_str);
char *padDest = alloca(size+2);
char *startP;
char *endP;
char *destP = malloc(size+1);
char *destI = destP;
int wordSize = 0;
/* memsets */
memset(destP,0,size + 1);
memset(padDest,0,size+2);
/* create a padded version space at front */
strcat(padDest," ");
strcat(padDest,in_str);
startP = padDest;
endP = padDest + size + 1;
/* step back from the Null terminator */
endP--;
while(endP >= startP)
{
if(*endP == 0x20)
{
endP--;
if(wordSize > 0)
{/*Store a word */
cpy_char(destP,&endP[2],wordSize);
destP += wordSize;
*destP=0x20;
destP++;
wordSize = 0;
}
}
else if(*endP != 0x20)
{ /* load a word */
wordSize = 0;
while (*endP != 0x20)
{
wordSize++;
endP--;
}
}
}
return(destI);
}
int main()
{
char *ret = reverse_sen(in_str);
printf("In String= %s\n",in_str);
printf("reversed sentence = %s\n",ret);
if(ret)
free(ret);
return (0);
}
GDB Crib Sheet
Compilation
Ensure the source is compiled with debug information as such:-
gcc -o test -g -Wall ./test.c
Getting started
gdb ./test
set args 1 + 3
break main
r ← run
start ← starts with a break point.
start takes you to main but inserts a temp break point.
Changing views
ctl-x a show tui
ctl-x 2 show assembler
ctl-x a clear
ctl l → clear gdb screen
set listsize 100
list ← set code around present point.
list func ← will center around function.
General commands
break test.c:45 if 1 > 20 ← conditional breakpoint.
watch counter → will execute until watch point is changed.
rwatch counter → will print when it is read
bt <- show bt of execution stack
up/down move up and down call stack.
frame shows present position in call stack
file ./test will re load a file that has changed, updating the debug info.
Call a function : call add(1,2)
Alternative runnnig
sudo gdb -p <pid> will attach to a running process.
Cores
Load a core file
gdb -c core.xxx
then load symbol table if you have the file, and the code was not compiled with -g
cores in linux are often in /var/lib/systemd/coredump
or use cordumpctl to show where stored, if not available, try enabling
ulimit -c unlimited (See online things may have changed since systemd)
Redirection
Redirecting output to another terminal.
Find terminal by typing tty → /dev/pts/1
in gdb then type tty /dev/pts/1
More Break Points Things
set b func1
p $pc
p value
end← will run after every hit.
Set a variable
set var i=30
Gdbserver
gsbserver 192.168.1.1:2345 –attach 6683 & ← on sash/bash of machine
on machine with code, ie nfs share.
target remote 192.168.1.2:2345
best to define in local .gdbinit but it is not a built with -g , load ./execute
define tgtr
target remote 192.168.1.2:2345
display/i $pc
end
Using from emacs
In emacs if you want to add a link to a cross compiled gdb add this to your .emacs file
(defvar gud-gdb-history ‘(“/toolkit/crosscompiler/bin/xxx-gdb”))
Other useful debugging tools: ddd
Allows graphic view of gdb, but also good data viewer.
Other tools:-
ltrace ← view calls to libs strace ← view system calls
valgrind –leak-check=full ./executable
cordumpctl debug will start debug on last generated core file. In c++ you can put virtual function in objects and confirm a function is called from which object by typing
info vtbl obj as typing whatis obj would only show you the parent class not any derived classes.
Bash
Bash Crib Sheet
Recent Git bash issue.
I recently had a issue with running bash scripts from Git-Bash. The python variant I was using being windows compiled required windows stlye paths not linux I needed to know which system the bash scripts were run from. (Linux,Windows Bash/ Windows Cywin) For this the uname function can be used from the Bash scripts.
# detect real bash
function LINUX?() {
if [[ $(uname -s) == "Linux" ]]; then
return 1
else
return 0
fi
}
#detect git bash
function GITBASH?() {
if [[ $(uname -s) == *"MINGW64"* ]]; then
return 1
else
return 0
fi
}
I also created sed based scripts to convert between both windows and linux paths, as the script used an environment varible to set a path reference.
# replacements
rep_lin_path_start='\/c\/'
rep_win_path_start='C\:\\'
lin_dir='\/'
win_dir='\\'
wback='\.\.\\'
lback='\.\.\/'
empty=
function LIN2WINPATH () {
local STR="$1"
local var1=""
var1=$(echo $STR | sed "s#${rep_lin_path_start}#${rep_win_path_start}#g" \
| sed "s#${lin_dir}#${win_dir}#g")
echo $var1
}
function WIN2LINPATH () {
local STR="$1"
local var1=""
var1=$(echo $STR | sed "s#${rep_win_path_start}#${rep_lin_path_start}#g" \
| sed "s#${win_dir}#${lin_dir}#g")
echo $var1
}
# Will remove any ..\ references
function LIN2WINREALPATH () {
local STR="$1"
local var1=""
var1=$(echo $STR | sed "s#${rep_lin_path_start}#${rep_win_path_start}#g" \
| sed "s#${lback}#/#g" \
| sed "s#${lin_dir}#${win_dir}#g")
echo $var1
}
# will remove any ../ references
function WIN2LINREALPATH () {
local STR="$1"
local var1=""
var1=$(echo $STR | sed -e "s#${rep_win_path_start}#${rep_lin_path_start}#g" \
| sed -e "s#${wback}#/#g" \
| sed -e "s#${win_dir}#${lin_dir}#g")
echo $var1
}
# Remote access using sudo and still get X windows to work
sudo xauth add $(xauth -f ~/.Xauthority list| tail -1)
Linux
My fedora install script
!# /usr/bin/bash
echo "Fedora 35 standard installation, should be run with root privalages";
echo "Install Teams";
sh -c 'echo -e "[teams]\nname=teams\nbaseurl=https://packages.microsoft.com/yumrepos/ms-teams\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/teams.repo';
dnf check-update;
dnf install teams -y;
if [ $? -ne 0 ]; then
echo "Teams install failed";
fi
echo "Install Zoom";
wget https://zoom.us/client/latest/zoom_x86_64.rpm;
dnf install -y zoom_x86_64.rpm;
rm zoom_x86_64.rpm;
if [ $? -ne 0 ]; then
echo "Zoom install failed"
fi;
echo "Install Flatpack, Gaphor";
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo;
flatpak install -y --user flathub org.gaphor.Gaphor;
if [ $? -ne 0 ]; then
echo "Flatpack/Gaphor install failed"
fi;
echo "Install Qnotes";
dnf install -y qnotes;
if [ $? -ne 0 ]; then
echo "qnotes install failed"
fi;
echo "Install Emacs, gdb automake git";
dnf install -y emacs gdb automake git;
git config --global user.name "JB";
git config --global user.email "XXXXXXX";
if [ $? -ne 0 ]; then
echo "Emacs/gdb/automake/git failed"
fi;
echo "Install Emacs customisations"
#emacs changes
rm ~/.emacs;
echo "(require 'package)
;;(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes '(waher))
'(custom-safe-themes
'(\"77fac25c0276f636e3914636c45f714c2fd688fe1b1d40259be7ce84b8b5ab1e\" default))
'(show-paren-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(setq
backup-by-copying t ; don't clobber symlinks
;; Default and per-save backups go here:
backup-directory-alist '((\"\" . \"~/.emacs.d/backup/per-save\"))
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(defun force-backup-of-buffer ()
;; Make a special \"per session\" backup at the first save of each
;; emacs session.
(when (not buffer-backed-up)
;; Override the default parameters for per-session backups.
(let ((backup-directory-alist '((\"\" . \"~/.emacs.d/backup/per-session\")))
(kept-new-versions 3))
(backup-buffer)))
;; Make a \"per save\" backup on each save. The first save results in
;; both a per-session and a per-save backup, to keep the numbering
;; of per-save backups consistent.
(let ((buffer-backed-up nil))
(backup-buffer)))
(add-hook 'before-save-hook 'force-backup-of-buffer)" > ~/.emacs;
cd ~/.emacs.d;
mkdir -p backup/per-session;
mkdir -p backup/per-save;
git clone https://github.com/emacsfodder/emacs-waher-theme.git;
cd emacs-waher-theme;
cp waher-theme.el ../;
rm -rf emacs-waher-theme;
if [ $? -ne 0 ]; then
echo "Emacs customisation failed"
fi;
echo "Install Microsoft code"
rpm --import https://packages.microsoft.com/keys/microsoft.asc;
sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo';
dnf check-update;
dnf install -y code;
NFS Notes:
Allow NFS with selinux enabled
Temp:- sudo setsebool -P use_nfs_home_dirs 1 sudo setsebool -P nfs_export_all_rw 1
perm:- sudo semanage boolean -m --on use_nfs_home_dirs sudo semanage boolean -m --on nfs_export_all_rw
Firewall:- sudo firewall-cmd --add-service=nfs --permanent sudo firewall-cmd --add-service={nfs3,mountd,rpc-bind} --permanent sudo firewall-cmd --reload
Exports file /home/jonb/work 10.10.10.16(rw,sync,no_subtree_check,no_root_squash)
Restart
sudo systemctl restart rpcbind nfs-server
Docker Notes
Container Notes
A container is a instance of running image.
sudo docker container run --publish 80:80 nginx
sudo docker container run --publish 80:80 --detach nginx
sudo docker container ls
sudo docker container stop bab <-- only needs to be as long as unique
sudo docker container run --publish 80:80 --detach --name webhost nginx
sudo docker container logs webhost
Running a Rails app from Docker.
Sample Docker file for Running my Rails App
FROM fedora:32
RUN dnf install -y nodejs.x86_64
RUN dnf install -y nodejs-devel.x86_64
RUN dnf install -y gcc g++ make
#RUN dnf install -y mariadb.x86_64
RUN dnf install -y rubygem-sqlite3.x86_64
RUN cd /opt
RUN mkdir MyApp
COPY ./ /opt/MyAPP/
WORKDIR /opt/MyApp
FROM ruby:2.6.3
RUN gem update --system
RUN gem install rails -v 5.2.3
RUN gem install bundle
RUN gem update --system
RUN bundle install
ENV RAILS_ENV=development
RUN rails db:schema:load # Note migrations got large, so transferred most to the schema.
RUN rails db:migrate
RUN rails db:seed #load existing data
CMD ["rails", "server", "-b","0.0.0.0"]
$> cd MyApp
$> docker image build -t myApp-init . ← will run the requests in the docker file
$> docker run --detach --publish 3000:3000 --name my-app myApp-init
listing running containers:-
$> docker ps
Listing existing containers
$> docker container ls (or -a for all, including stopped)
Listing available docker images
$> docker image ls (or -a for sub images?)
Other useful
$>docker start my-app
$>docker stop my-app
$>docker container rm b8fbabf2e771 40c986ecbfe1 2413da657642 502a491735ed
$>docker run --it --publish 3000:3000 --name my-app myApp-init /bin/bash <- will dump you into bash window to help diagnose bugs
$>docker logs my-app
Gcov Notes
`
//test.cpp
#include
using namespace std;
int used() { std::cout << "Used" << std::endl; return 0; }
int unused()
{
std::cout << "Unused" << std::endl;
return 0;
}
int main(int C,char *[]) { used(); //unused(); used();
return 0; }
`
For a given file gcov can give code use coverage. For example , lets start compiling this code.
g++ --coverage test.cpp -c g++ --coverage test.o
you will notice a file called test.gcno is created.
next run the executable
a.out; used used
Another file is now created test.gcda
run gcov now against the source file
gcov test.cpp -m
File 'test.cpp' Lines executed:70.00% of 10 Creating 'test.cpp.gcov'
This suggest that only 70% of the code is used.
opening the create file test.cpp.gcov
-: 0:Source:test.cpp
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 1:#include <iostream>
-: 2:
-: 3:
-: 4:using namespace std;
-: 5:
2: 6:int test()
-: 7:{
2: 8: std::cout << "Used" << std::endl;
2: 9: return 0;
-: 10:}
-: 11:
#####: 12:int unused()
-: 13:{
#####: 14: std::cout << "Unused" << std::endl;
#####: 15: return 0;
-: 16:}
-: 17:
1: 18:int main(int C,char *[])
-: 19:{
1: 20: test();
-: 21:// unused();
1: 22: test();
-: 23:
1: 24:return 0;
-: 25:}
shows which functions are called etc, which are not.
Jonathan Thomas Bell
Senior Software Developer
jontbell40
Profile
Experienced Software Developer with 30 Years in Consumer Product Development
I have extensive experience across all stages of product development, from requirements gathering to product testing, final approval, and customer support. I believe strongly in integrating testing and development from the initial concept stage to ensure the final product meets customer satisfaction.
During my time at Panasonic, working on both television and set-top box products, I developed customer-facing applications as well as low-level supporting daemons. I possess a strong knowledge of both Linux and FreeBSD operating systems, which I used extensively in embedded products and to create test applications that ensured comprehensive end-to-end testing.
I also developed front-end applications in HTML5 and Vanilla JavaScript for use in embedded browsers. Working as part of a small team of four developers, I contributed to the first television implementations of the Freetime, Freeview, and Freeview Play broadcast systems. In this role, I collaborated closely with broadcasters, often helping shape industry standards, and held sole responsibility for maintaining the applications throughout their product lifecycle.
Before transitioning to software development, I held roles in hardware design and factory support, which helped me adapt to rapidly evolving technologies. Following the closure of Panasonic’s development center in Cardiff, I joined Airbus.
Area of Expertise
• Linux/FreeBSD
• C/C++ programming and debugging
• HTML5/Javascript development
• Ruby
• Ruby on Rails
• Lisp
• Docker
• Accessibility
• GIT
• L.A.M.P. Systems
• Extensive Digital Video Knowledge.
• SQLite
• Embedded Electronics
• Kernel debugging
• DVB
• Third party library integration/support
* Python Development for test support. including using Flask/torch etc.
Accomplishments
• Developed applications for the first TV implementation with the Freesat,
Freeview and Freeview
Play Television systems, including responsibility of applications
such as the Channel list Management and meta data daemons, using both IP and broadcast data sources.
(Over 1 Million products sold for
Freeview TV’s alone)
• Creation of end to end testing tools for confirmation of
emerging standards.
• Software lead for the development of Panasonic Olympic TVs
used at the 2012 Olympics.
• Development of both the decoder and the TV application
for the first broadcast of the DVB
system software update system.
• Supported the introduction of DVB into Panasonic’s UK
TV development factory.
• Electrical Design of DVB Common interface circuits for
Panasonic Product.
• Customer and factory support both in the UK and abroad.
• Member of Technical standards steering groups, such as the DTG
group on Broadcast record
lists and the operation of the engineering channel.
• Introduced first TV with Text to Speech EPG to UK Market,
working closely with the RNIB to identify issues.
Employment History
Employment History
Senior Software Engineer - Airbus Space & Defence, Newport
March 2022 - Present
Involved in various products both restricted and research based.
Software Specialist (DVB) – Panasonic-IDSC, Cardiff
June 2012 – March 2022
At Panasonic, I developed software for a range of IPTV solutions, both within the products and for external test systems. My work involved using C, Ruby, Rails, JavaScript, SQLite, and HTML5. I was responsible for creating daemons and user applications that processed metadata for the Freesat and Freeview Play product lines.
Senior Software Engineer (Team Leader) – Panasonic Manufacturing UK Ltd, Cardiff
March 2002 – March 2011
As Technical Lead for the Middleware team and Team Leader for the Application Development Team, I spearheaded software projects including DVB SSU and the development of driver and package encoders. I represented the company on government technical committees and played a key role in the Digital TV project. My responsibilities included developing applications for UK-specific features and providing general IT support, such as generating auto-build scripts and managing server operations.
My work covered a broad range of areas including Linux/BSD kernel, driver and application development, GUI and user interface design, and DVB-T, DVB-C, and DVB-S technologies. I utilized languages such as C, Lisp, MHEG, SQL, Ruby/Rails, and various scripting languages. I applied SCRUM methodologies for project management and oversight, including requirement gathering, and was involved in the full software lifecycle from concept through coding to verification and validation. I also provided support for third-party vendors, integrated code, and analyzed system faults using Linux and BSD kernel debugging.
Design Engineer at Matsushita Electric UK Ltd., Cardiff
March 1998 — March 2002 Digital Hardware Design. Design of DVB common interface circuits, creation of on-board test code. Linux based development work on TV and set top box projects. Boot-loader development for set top box. Design and specification of automated test system used in the production of Television receivers. Factory Support both locally and abroad. Overseas sales samples visits and customer/market support.
Technical Engineer at Matsushita Electric UK Ltd., Cardiff
August 1991 — March 1998 Introduction of Digital TV product to the UK, Technical interface to Factory and Japan, Production support, specification and test. Automated test generation. Using Labview/C.
Additional Training undertaken
• Compliance/Competition law/Data protection.
• Broadcast security
• MPEG DASH
Education
MSc Computing for Commerce and Industry, The Open University, Cardiff
2007 — 2011 Msc (CCI). My dissertation investigated the transfer of WCAG (Web Content Accessibility Guidelines) described accessibility barriers between the PC and connected TV (HBBTV) domains. I researched how the barrier walkthrough method could be used to investigate transfer, implementing voice guidance on a TV browser using the Web Speech API. (2018). Postgraduate Diploma in Computing for Commerce and Industry (2007-2011). Modules studied to gain qualification:- Software Requirements for Business Systems. Managing the Software Enterprise. Relational Database Systems. User Interface Design and Evaluation. Project Management. Analysis and Design of Enterprise systems: An object orientated approach. Architectures of computing Systems. System Engineering.
BTEC National Diploma in Engineering (Electronics), Llandaff Technical College, Cardiff 1987 — 1991
Hobbies And Interests
I enjoy jogging, and gardening. During the Covid lock down I experimented with seeing how much of my own food I could grow in the limited area of our garden. I hope to document my successes and failures of growing food in this way and will document the present year on my website: TheDrownedGardener.com
References
Available upon request.