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  Computing
1 Programming
 1.1 C
  1.1.1 Private Functions
  1.1.2 autotools
  1.1.3 Garbage Collection
 1.2 Perl
  1.2.1 Bootstrap Module::Install project
 1.3 Functional vs Procedural paradigms
 1.4 Graphics Programming
2 System Administration
 2.1 Debian
  2.1.1 debootstrap
  2.1.2 Mail Setup
 2.2 Networking
  2.2.1 Block IP
  2.2.2 Forward external port to internal port
 2.3 Links
II  Electronics
3 Links
III  Sound
4 Links
IV  Personal
5 Wishlist

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:

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:

Bugs

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:

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

Part III
Sound

Chapter 4
Links

Part IV
Personal

Chapter 5
Wishlist