Skip to content. | Skip to navigation

Sections
You are here: Home Resumes Code Samples

Code Samples

The principal work product of a software engineer consists of his or her software and documentation.

Virtually all my work over the past 20 years consists of free software, copyleft publications, and Libre services. My entire body of software is freely available for examination and reuse by anyone, and my entire body of publications is available for readership and verbatim copying.

As an engineer I take pride in my professional accomplishments, and believe my body of work speaks for itself.

Employers, clients, colleagues, partners and others wishing to work with me can review my software, my publications, my services and my reputation.

Contents

1  Code Samples

In addition to the mentioned software collection, here I provide pointers to some select smaller pieces of software that can be easier and faster reviewed as samples of my code.

The reasons for selecting these particular samples, include:

  • They are widely distributed and widely used.
  • They have proven to be useful.
  • They are all part of some bigger picture. I am glad to have contributed.

1.1  C Libraries And Protocol Implementations

1.1.1  Data Communications and C Language – FCS Implementation in PPP RFCs

In late 1980s I posted various pieces of C code on Usenet’s comp.protocols.tcp-ip hoping that they will be useful to others.

One of those pieces of code was part of a Fast Frame Check Sequence (FCS) Implementation.

The author of the PPP protocol chose to include that code in an appendix to RFC-1134.

Subsequent updates to that RFC, RFC-1171, RFC-1331, ... have continued to include that code as an appendix.

Part of that little code which evolved to become part of a reference implementation for something relatively useful and important is included below. The complete code can be found in the appendix of the above mentioned RFCs.

Clearly it is not anything terribly exceptional, but I am happy to have participated in moving things forward.

C.1.  FCS table generator

   The following code creates the lookup table used to calculate the
   FCS-16.

   /*
    * Generate a FCS-16 table.
    *
    * Drew D. Perkins at Carnegie Mellon University.
    *
    * Code liberally borrowed from Mohsen Banan and D. Hugh Redelmeier.
    */

   /*
    * The FCS-16 generator polynomial: x**0 + x**5 + x**12 + x**16.
    */
   #define P       0x8408

   main()
   {
       register unsigned int b, v;
       register int i;

       printf("typedef unsigned short u16;\n");
       printf("static u16 fcstab[256] = {");
       for (b = 0; ; ) {
           if (b % 8 == 0)
               printf("\n");

           v = b;
           for (i = 8; i--; )

               v = v & 1 ? (v >> 1) ^ P : v >> 1;

           printf("\t0x%04x", v & 0xFFFF);
           if (++b == 256)
               break;
           printf(",");
       }
       printf("\n};\n");
   }

1.1.2  Open C Platform – OCP

OCP is a highly portable environment for developement of embedded systems from bare metal to embedded linux.

The software for OCP as a tar file is at:
http://mohsen.1.banan.byname.net/content/generated/doc.free/neda/PLPC/110301/current/ESROS-MulPub.tar.gz

The Access Page is at: http://mohsen.1.banan.byname.net/PLPC/110301

Usage document in PDF format is at:
http://mohsen.1.banan.byname.net/content/generated/doc.free/neda/PLPC/110301/current/main.pdf

1.1.3  C Reference Implementation of ESRO (RFC-2188)

I designed and published RFC-2188 –
AT&T/Neda’s Efficient Short Remote Operations (ESRO) Protocol Specification
https://tools.ietf.org/html/rfc2188 – in 1997.

ESRO provides very efficient reliable connection-less services on top of UDP. ESRO can be of use in Internet Of Things applications.

The software for ESRO as a tar file is at:
http://mohsen.1.banan.byname.net/content/generated/doc.free/neda/PLPC/110303/current/ESROS-MulPub.tar.gz

ESRO source code documentation (Both Server And Device Side) including a full service definition and a C Language Binding (API) is available at: http://mohsen.1.banan.byname.net/PLPC/110303

Full documentation for ESRO in pdf format is available at:
http://mohsen.1.banan.byname.net/content/generated/doc.free/neda/PLPC/110303/current/main.pdf

1.1.4  Example Of An OCP/ESRO Feature Walk Through – FSM_ Finite State Machines

OCP and ESRO are relatively large pieces of software. To get a feel for my design and implementation style in C, you could consider implementation of a commonly needed feature, for example finite state machines FSM_.

  • Section 6.19 – Finite State Machine (FSM_) – of http://mohsen.1.banan.byname.net/PLPC/110301 describes the fsm_ interface
  • The implementation of fsm_ is in ./ESROS-MulPub/src/multiocp/base.ocp/fsm_/portable/fsm.c
  • For ESRO, the invoker state table action transitions are in ./ESROS-MulPub/src/esros/erop_eng/invokact.c
  • For ESRO, the performer state table action transitions are in ./ESROS-MulPub/src/esros/erop_eng/perfact.c

1.2  Python

1.2.1  Interactive Commands Modules And BISOS (ByStar Internet Services OS)

Over the past two decades or so, I have been working on the design and implementation of a loosely coupled “On Unix” internet services OS –called BISOS– that can then be used as the primary building block of an autonomy and privacy oriented digital ecosystem that I have named: “The Libre-Halaal ByStar Digital Ecosystem”. An overview of that totality is available at: http://www.by-star.net.

All executions/commands of BISOS conform to the ICM (Interactive Commands Module) framework. An ICM is a collection of command line invokable functions that automatically map to command line parameters and arguments. The ICM framework is language independent and Python and Bash implementations are available.

You can get the Python ICM libraries with:

pip install unisos.icm

unisos.icm makes heavy use of python AST (Abstract Syntax Tree) analysis to map command line information on to class and function names within modules. unisos.icm also uses a good number of decorators and class inheritance hierarchies. The ICM implementation is a good example of my design style.

As a bootstrapper for putting BISOS on Unix, I have customized pip. Running:

sudo pip install bisos.bx-pip

would install bx-pip and bx-bases in the usual /usr/local/bin.

bx-pip can be considered as a simple example of an ICM that uses unisos.bx-pip.

I then use bx-pip to install the entire BISOS on Unix – as opposed to in Unix. This model can be used by any organization that wishes to distribute and manage large pieces of software and data.

ICMs are able to communicate through the command line all capabilities of themselves as modules. This allows for user interfaces other than command lines to be used for configuring and executing the modules through richer than command line interfaces which we call “ICM Players”. An Emacs ICM player is in use – This is briefly described in Section 1.4.2. A JavaScript ICM player is in the works.

1.2.2  X822Msg Pipeline And Marme

Multi Account Resident Mail Exchanger (MARME) is a general purpose autonomous software package that implements mail sending and mail processing facilities based on python’s smtplib library.

The software for Marme as a tar file is at:
http://www.by-star.net/content/generated/doc.free/bystar/PLPC/180051/current/marme.tar

Documentation for Marme is at its access page at: http://www.by-star.net/PLPC/180051

1.3  Bash, Sh, Ksh

1.3.1  ByStar Services Integration Platform

The collection of bash scripts that manage http://www.by-star.net will be pointed to here.

1.4  Lisp/elisp

1.4.1  Multilingualization (m17n) And elisp – Persian Input Methods In Emacs 24

I have been using emacs since 1986. When support for bidirectional (bidi) text was included in Emacs 24 in 2011, I jumped in and added two input methods and Persian language support to emacs. These are now part of Emacs. Complete documentation for these input methods is available on-line at:

Persian Input Methods – For Emacs And More Broadly Speaking
شیوه‌هایِ درج به فارسی‌
http://mohsen.1.banan.byname.net/PLPC/120036

That emacs lisp code is now distributed with emacs24 – usually in leim/quail/persian.el.

The latest Persian Input Methods code is available at: http://www.persoarabic.org/emacs/persian-input-methods.tar

The significance of this implementation and its inclusion in emacs is that it can pave the way towards a different model for inputing text in Persian.

To select the input method in emacs:

  • M-x set-input-method
  • Respond in mini-buffer with farsi-transliterate-banan
  • or eval (set-input-method "farsi-transliterate-banan" t)

1.4.2  Blee ICM Players

The ICM (Interactive Commands Modules) that I described in Section 1.2.1 can be played using org-mode panels. I have built an easy to use emacs interface that uses org-mode dynamic-blocks to dynamically configure and then execute ICMs in command line.

That lisp package will also be made available through bx-pip.



Document Actions
Libre/Halaal Internet Services Provided At LibreCenter By Neda

Member of By* Federation Of Autonomous Libre Services

This web site has been created based exclusively on the use of Halaal Software and Halaal Internet Application Services. It is part of the By* Federation of Autonomous Libre Services which in turn are part of the Halaal/Libre By* Digitial Ecosystem which incorporate the following software components: