Notes
Martin Olsen
2012
Copyright
©2011–2012 Martin
Olsen
The
latest
version
of
this
book
can
be
located
at
martinolsen.net,
in
both
HTML
and
PDF
format.
This
copy
was
rendered
on
January
24,
2012.
Contents
Preface
I previously stored my notes in a public accessible wiki (UseModWiki). This worked
great except, without proper access control, it is vulnerable to spam. As I
have always wanted to learn TEX, I instead decided to start this book of
notes.
Part I
Computing
Chapter 1
Programming
1.1 C
1.1.1 Private Functions
Use the static keyword!
1.1.2 autotools
For reference, see private progen or libweb repositories.
Required (debian) packages:
- autoconf
- libtool (optional)
Initial configuration:
$ autoscan # Generate configure.scan
$ mv configure.{scan,in}
$ vi configure.in # Adjust for correctness
# Pay attention to AC_CONFIG_
$ vi Makefile.am src/Makefile.am
# Write relevant Makefile.ams
$ touch NEWS README AUTHORS INSTALL ChangeLog
# Touch required files, edit if
# you like
$ touch COPYING # Touch required file license file.
# Skip this to install default GPL
Configuration after checkout:
$ autoreconf --install # Generate everything.
Build distribution:
$ mkdir build && cd build
$ ../configure && make dist-check
Build cycle (Makefiles invoke autotools):
$ ./configure
$ make
1.1.3 Garbage Collection
Some preliminary thoughts on implementing a garbage collector in C. This has not
yet been implemented in practice.
The basic idea of this garbage collector is to maintain a structure of each memory
chunk allocated including a reference count. Client code must manually reference and
dereference each block when it enters and exits scope.
Functions needed:
-
void *gc_alloc(size_t sz)
- Allocates memory and increases refcount.
-
void *gc_ref(void *o)
- Increases refcount.
-
void gc_deref(void *o)
- Decreases refcount.
An example:
void foo()
{ void ∗obj = gc_alloc(1024);
bar(obj);
gc_deref(obj);
} void bar(
void ∗obj)
{ internal_structure.obj = gc_ref(obj);
}
Here foo() creates an object and passes it to bar() and informs the garbage
collector that it is done with allocated chunk. bar() tells the garbage collector that it
will hold on to the object.
Improvements (a.k.a things to ponder ’bout):
-
multithreading
- Should be easy - whenever refcount goes to zero it can never
go up again.
-
subrefs
- Sometimes sub-references could be nice. An example could be a
lexer/parser that only wants to reference parts of the input (i.e. a string).
-
debug
- Convert gc_alloc() to a #defineed wrapper that stores __FILE__ and
__LINE__ to display and/or store for debugging purposes.
1.2 Perl
1.2.1 Bootstrap Module::Install project
Makefile.PL:
use inc::Module::Install;
name ’FooBar’;
all_from ’lib/FooBar.pm’;
license ’bsd’;
perl_version ’5.010’;
requires ’Moose’ => 0;
requires ’namespace::autoclean’ => 0;
test_requires ’Test::More’ => 0;
WriteAll;
lib/FooBar.pm:
package FooBar;
use Modern::Perl;
our $VERSION = 0.01;
=head2 AUTHOR
Martin Olsen <my@e.mail>
=head2 LICENSE
Copyright 2011 Martin R. Olsen
This library is free software; you redistribute it and/or modify
it under the BSD license.
=cut
1;
Then run:
perl Makefile.PL
Relevant Makefile is now ready. Write some tests in t/ and run them
with:
make test
1.3 Functional vs Procedural paradigms
Consider the difference between functions and procedures: functions takes optional
arguments and returns a value, procedures invoke sequential statements.
1.4 Graphics Programming
Notes one graphics programming.
Rendering:
Chapter 2
System Administration
2.1 Debian
2.1.1 debootstrap
Step-by-step example of a Debian ”Squeeze” installation with debootstrap.
Step by Step
Remember to correct hosnames, mirrors, devices, etc.
Squeeze installation:
- boot livedisk
- apt-get update && apt-get install deboostrap
- fdisk /dev/sdX
- mkswap /dev/sdXn && swapon /dev/sdXn
- mkfs.ext4 /dev/sdXm
- mount /dev/sdXm /mnt
- sudo debootstrap –arch amd64 squeeze /mnt
http://ftp.dk.debian.org/debian /mnt
- mount -o bind /dev /mnt/dev
- mount -t proc proc /mnt/proc
- mount -t sysfs none /mnt/sys
- LANG=C chroot /mnt /bin/bash
- create etc/apt/sources.list
deb http://ftp.dk.debian.org/debian squeeze main contrib
non-free
deb http://security.debian.org/ squeeze/updates main
contrib non-free
- aptitude update
- create etc/fstab
/dev/sdXm / ext4 defaults 0 1
/dev/sdXn none swap sw 0 0
proc /proc proc defaults 0 0
- aptitude install locales console-data
- dpkg-reconfigure locales
- dpkg-reconfigure console-data
- dpkg-reconfigure tzdata
- aptitude install wireless-tools wpasupplicant firmware-iwlagn
- setup etc/network/interfaces
auto lo wlan0
iface lo inet loopback
iface wlan0 inet dhcp
wpa-ssid bluebox
wpa-psk *******
- chmod 0600 /etc/network/interface
- echo ”HOSTNAME” ¿ /etc/hostname
- create etc/hosts
127.0.0.1 localhost
127.0.1.1 HOSTNAME
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
- passwd
- aptitude install linux-image-vserver-amd64 grub-pc
Bugs
- Wifi interface named wlan1 had to edit file under etc/udev/rules.d/
Reference
2.1.2 Mail Setup
This is a short description of the mail setup for mo.n.
Following this: Backing Up Your GMail with Ubuntu
Packages:
- exim4 - Send mail directly to recipients through SMTP.
- fetchmail - Fetch mail from Google.
- procmail - Local delivery.
- spamassassin - Assassinate Spam.
- mutt - Reader.
2.2 Networking
2.2.1 Block IP
sudo /sbin/iptables -I INPUT -s <IP of infected scum> -j DROP
2.2.2 Forward external port to internal port
Do you need to publish a service from behind a firewall to the public internet? Easy!
All you need is SSH access from a local machine to an external machine (with an
open public port) and you can use this command:
ssh -fN external.example.org -R external.example.org:11:internal.local:22
This will make ssh connect to external.example.org and listen on port 11. All
request on this port will then be forwarded, through the machine where you started
ssh, to port 22 of host internal.local.
2.3 Links
Links relevant to computing.
Assembly:
Compilers:
Manuals:
Part II
Electronics
Chapter 3
Links
- Basic:
- Components:
- Circuits:
- Synthesizer:
- Kits:
- Sequencer:
- Computers:
- Shops:
- Software:
- Other:
Part III
Sound
Chapter 4
Links
- Hardware Synthesizer Workflow:
- Theory:
- Shops:
- Nord Lead 2X patches:
Part IV
Personal
Chapter 5
Wishlist