Collected notes on programming
computer science dictionary
- Unicode: a standard for consistend encoding, representation and handling of text expressed in most of the world's writing systems.
- ANSI: American National Standards Institute, an organisation that oversees the development of voluntary consensus standards
- ASCII: American Standarc Code for Information Interchange, a character encoding standard representing text in computers.
- ANSI Escape Codes: a standard to control cursor location, color, font styling and other options on text terminals and emulators.
- UTF-8: Unicode Transformation Format, a variable-width character encoding, capable of encoding all 1,112,064 valid character code points in Unicode using one to four one-byte (8-bit) code units.
- Unix: a family of computer operatin systems that derive from the original AT&T Unix, started in the 1970s at Bell Labs research center.
- Linux: a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on in 1991 by Linus Torvalds.
- PCB: Printed Circuit Board
clang

C is a widely used programming language, developed by Brian Kernighan and Dennis Ritchie during the 1970s. It is closely tied to the development of the Unix operating system.
A program written in C needs to be compiled - I use the Ubuntu pre-installed gcc. C programs can be debugged using GDB.
Pointers
type *ptr | A pointer of type named ptr |
*prt | The value of whatever prt is pointed at |
*(ptr + i) | The value of (whatever prt is pointed at plus i) |
&thing | The address of thing |
type *ptr = &thing | A pointer of type named ptr set to the address of thing |
Converting strings to integers
ASCII | Decimal |
0 | 48 |
1 | 49 |
2 | 50 |
3 | 51 |
4 | 52 |
5 | 53 |
6 | 54 |
7 | 55 |
8 | 56 |
9 | 57 |
gdb

The GNU Project debugger, displays what is going on 'inside' a program while it executes - or what it was doing at the moment it crashed.
Commands
gdb ./program | starts gdb |
run | executes the code |
s | steps to the next line |
n | jumps over the next function |
c | continues execution |
l | prints 5 lines above and below current statement |
break | sets a breakpoint either at line number of function name |
watch | stops the execution everytime a variable value changes |
display | prints a variable value on execution stops |
info | displays information on breakpoints and watchpoints |
clear # | removes the breakpoint at line # |
condition 1 i == "test" | breaks at breakpoint 1 when i is "test" |
bash

Bash is a Unix shell and command language originally released in 1989. It can read and execute text files called shell script that are useful for automating tasks.
The terminal cheatsheet contains some of the commands that can be run as part of a bash script.
Running a script
Navigate to the directory containing the script and use ./scriptname.sh
to execute it.
If the script fails with an permissions error, use chmod 755 scriptname.sh
to make it executable.
#!
Shebang. Indicates which interpreter a script should be run with:#!/bin/bash
$1, $2, ...
The first, second, etc command line arguments to the script.variable=value
To set a value for a variable. Remember, no spaces on either side of =Quotes " '
Double will do variable substitution, single will not.if [ ] then else fi
Perform basic conditional logic.
Evaluating the arguments passed to a script
#!/bin/bash # case example case $1 in start) echo starting ;; stop) echo stoping ;; restart) echo restarting ;; *) echo don\'t know ;; esac
regex

Regular expressions are useful for extracting information from any text by searching one or more matches of a specific pattern.
A regex usually comes within this form /abc/
where the search pattern is delimited by two slash characters /
.
Anchors
^The | matches any string that starts with The |
end$ | matches a string that ends with end |
^The end$ | exact string match (starts and ends with The end) |
long | matches any string that has the text long in it |
Quantifiers
abc* | matches a string that has ab followed by zero or more c |
abc+ | matches a string that has ab followed by one or more c |
abc? | matches a string that has ab followed by zero or one c |
Character classes
User uppercase to negate.
\d* | matches a single character that is a digit |
\w* | matches a word character (alphanumeric character plus underscore) |
\s* | matches a whitespace character (includes tabs and line breaks) |
.* | matches any character |
Escaping
In order to be taken literally, you must escape the characters ^.[$()|*+?{\
with a backslash \
as they have special meaning.
Flags
g | global | does not return after the first match, restarting the subsequent searches from the end of the previous match |
m | multi-line | when enabled ^ and $ will match the start and end of a line, instead of the whole string |
i | insensitive | makes the whole expression case-insensitive (for instance /aBc/i would match AbC) |
incoming(1) | preonic