ali

Archive for the ‘Uncategorized’ Category

Proof for the summation formula S(n)=n*(n+1)/2

In Uncategorized on February 5, 2010 at 5:20 pm

I was explaining to a co-worker how supposed worked out the formula and illustrating my simple proof. I tried to look it up online, but didn’t find it.

So, here it is:

1 2 N = \sum_{1}^{N}N
N N-1 1 = \sum_{1}^{N}N
N+1 N+1 N+1 = N*(N+1)

Thus

\sum_{1}^{N}N + \sum_{1}^{N}N = N*(N+1)
2\sum_{1}^{N}N = N*(N+1)
\sum_{1}^{N}N = N*(N+1)/2

For a better explanation, see this PDF.

Same binary, every build

In Uncategorized on February 4, 2010 at 11:47 pm

Wouldn’t it be nice if you did a make today and a make a week from now, and if nothing had changed, you got the same binaries? This is quite useful when trying to reproduce old firmware images.

I set out trying to carry out this task:

  • Replace all references to the current date (__DATE__) with references to the last modification time of the file from your revision control system (CVS $Date$).
  • Pass the --user=0 and --group=0 arguments to tar so that the same user is listed for every build.
  • Use touch before running tar or gzip to likewise set the modification date of any binaries. I have a small C program that will go through a tar file and “fix” the modification dates.

I’m still working on a program to have the e2fs UUID be the MD5 or such of the contained binaries. I’m not sure I want to go ahead with this, it’s something I ran into quickly when trying to reproduce a file system image bit-for-bit.

Why ECC is necessary

In Uncategorized on February 4, 2010 at 11:16 pm

After spending a few hours trying to debug why a certain program would crash. It turns out that the memory on this particular system is bad.

It’s bad in such a way that Linux boots up, init runs, most of our startup succeeds, yet the first program with a large memory footprint fails.

Here are some successive runs of md5sum:

5b9e3287070f2f117adf77da90a0a5f7 flash-3002-1.sh.gz
2ed0de72c3bcbb7c882588781fbff676 flash-3002-1.sh.gz
292ea7da110c63d0014f2d1f804ed3c8 flash-3002-1.sh.gz

While dmesg shows that:

ERROR DDR0 ECC: 3 Single bit corrections, 1 Double bit errors
DDR0 ECC:       Failing dimm:   0
DDR0 ECC:       Failing rank:   1
DDR0 ECC:       Failing bank:   1
DDR0 ECC:       Failing row:    0x3123
DDR0 ECC:       Failing column: 0xee0

Patch for the Meschach C library

In Uncategorized on February 4, 2010 at 11:06 pm

I had some old code sitting around for polynomial regressions. A colleague wanted some sample code for curve fitting. However, I must
have compiled it a long time ago, as it wasn’t linking any more.

I went back and fixed up version 12a of the Meschach library. My changes were all autoconf related.

You may find the patch at:

http://github.com/im/snippets/blob/master/patches/mesch12b.patch

Comparison of build systems

In Uncategorized on February 4, 2010 at 11:05 pm

Some time ago I went looking for build systems. Currently we use
GNU Make and our make files have become unwieldy.

I remember reading an article comparing different build systems and going through the alternatives one-by-one.

Here’s what I looked at:

Jam

Jam is a make alternative developed by Perforce Software.

Not chosen because:

  • The last release was in 2003
  • It seems very C/C++ specific
  • No community (BTS, forums, public repository)

CMake

CMake is a build-system generator. It will generate project files for Visual Studio etc. and also create make files. Note that CMake must be installed on every machine where the build takes place.

I may eventually switch to CMake, as the lesser of all evils.

Not chosen (at the moment) because:

  • Complicated
  • The scope didn’t seem to fit: I don’t want a build system generator, I want a build system

Ant

We use Ant for Java. I’ve played enough with Ant to know that I don’t want to use it. To be fair, I could have invested more time learning Ant, but I really, really don’t want to write XML.

Not chosen because:

  • Complicated
  • XML
  • Requires the JVM to run (huge)

Scons

I played with SCons and Waf a little bit. I gave up on Waf after trying to do a few odd things and not finding any documentation.

SCons was OK. I tried a small project and it seemed to work.

Not chosen because:

OMake

I like OCaml so I tried OMake. After doing two or three projects, I ended up not using it because:

  • Last release in 2007
  • Project seems dead
  • Cute output that is difficult to change
  • No package for Fedora

I say the project seems dead because:

Summary

At the moment I’m back to using GNU make after realizing that OMake is dead. I’ll investigate CMake and SCons again. If SCons hasn’t improved (speed wise), then alas, CMake is my only viable alternative.

WordPress themes that support tables

In Uncategorized on February 1, 2010 at 11:04 pm

Alas I had to switch from MistyLook. Surprisingly, many of the top themes don’t support tables: Cutline, Freshy, Blix etc.

I had two requirements: a light theme, with a right sidebar.

Multilated table in the MistyLook theme

Table viewed in MistyLook

I looked at the CSS, but I couldn’t find anything wrong. It was a choice between a theme, and displaying tables. I choose to switch themes.

Cardinal, Ordinal, and Nominal numbers in software engineering

In Uncategorized on February 1, 2010 at 9:15 pm

I have two hands. I was the second person to arrive in the morning. My employee ID is 2.

Cardinal numbers are used for counting.

Ordinal numbers are used for ordering items.

Nominal numbers name things.

Even in regular prose we distinguish between cardinal and ordinal numbers.

Number Operations Supported
Cardinal Addition, Subtraction1, Comparison
Ordinal Comparison
Nominal

The only language that I know of where I could easily restrict operations on numbers is Ada. I don’t like Ada. I think that’s because we misused Ada at work. All cardinal numbers were new types, and explicit coercions were strewn throughout the code base.

For instance, the work philosophy would have me create:

  1. Type Fan_Count to count the number of fans in a system (range 1..10).
  2. Type Fan_Index to index into an array of fans (range 1..10).
  3. Type Fan_Controller_Count to count the number of fan controllers (range 1..10).
  4. Type Fan_Controller_Index to index into an array of fan controllers (range 1..10).

We never created a Fan_Identifier type.

Now, the problems with the above were:

  • What if I can’t communicate with any of the fans? I can’t represent 0 fans.
  • I want to count the fans in two chassis. All of a sudden I overflowed the bounds of Fan_Count. Likewise with Fan_Controller_Count.
  • I want to count the total number of fans and fan controllers in a chassis. I need to cast both to an integer.
  • I want to look up some fault code depending on the number of fans, or fan controllers that have failed on a system. I needed two arrays containing exactly the same information, or I needed a cast.

Over time I came to believe that we should use natural numbers (Natural) for counting.

These days I program in the C programming language and I have the opposite problem. I wish for some type checking. Most C code conflates the index of something, with the count of something, or the index of something, with the identity of something.


1. Other operations such as multiplication and division may be supported.

Install a font using “runas” under Windows

In Uncategorized on January 22, 2010 at 1:46 pm

My Windows account does not have administrator privileges. I used the following recipe to install a font under Windows.

  1. runas /user:Administrator cmd.exe
  2. cp *.ttf c:\windows\fonts
  3. start c:\windows\fonts
  4. When the Fonts folder pops up, select File->Install New Font and browse to the c:\windows\fonts folder.
  5. Pick all the copied fonts, and click OK.

Set up a DNS blacklist using ISC bind

In Uncategorized on January 19, 2010 at 2:47 pm

Here’s how I created a DNS blacklist using bind 9.3.4. I used 1 and 2 as resources.

Set up the blackhole IP address

I didn’t want to redirect everyone to 127.0.0.1 or some invalid address. I wanted to display some message that the domain in question had been blacklisted.

So, I set up an Apache config file:

NameVirtualHost 192.168.0.20:80
<VirtualHost 192.168.0.20:80>
    ServerName blocked.mydomain.com
    AliasMatch "^/(.*)" "/var/www/blocked/blocked.cgi"
</VirtualHost>
<Directory "/var/www/blocked">
    Options +ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

The CGI file is rather simple. It outputs a message saying that the URL you’re trying to access has been blocked.

Set up bind

At the end of named.conf, I included two files:

// blocked due to local policy
include "/etc/blocked-local.conf";

// wget -O blocked-malware.conf 'http://www.malware.com.br/cgi/submit?action=list_bind'
// sed -i 's,mbl.zone.file,zones/blocked,' blocked-malware.conf
include "/etc/blocked-malware.conf";

Each file has lines of the form:

zone "a.amg777.com" { type master; notify no; file "zones/blocked"; };

The file zones/blocked looks like:

$TTL 600        ; 10 minutes
@                       SOA     server.mydomain.com. root.mydomain.com. (
                                42         ; serial
                                900        ; refresh (15 minutes)
                                60         ; retry (1 minute)
                                604800     ; expire (1 week)
                                43200      ; minimum (12 hours)
                                )
                        NS      server.mydomain.com.
                        MX      1 server.mydomain.com.
$TTL 302400     ; 3 days 12 hours
@               IN      A       192.168.0.20
*               IN      A       192.168.0.20

1. http://isc.sans.org/diary.html?storyid=7930

2. http://fnord.no/sysadmin/dns/dns-blacklisting/

Setting up Git for use with Github on Windows

In Uncategorized on January 15, 2010 at 3:40 pm

I followed the tutorial here:

http://nathanj.github.com/gitguide/tour.html

  1. Download and install msysgit.
  2. Install with the following options:
    • No additional icons.
    • No Explorer integration.
    • Use Git Bash only
    • Use PLink
    • Use Unix style line endings
  3. Go through the following steps to make sure my connection works:
    • Connect using PuTTY to git@github.com and accept the key
    • Make sure the key is loaded in Pageant
    • See this Github guide if you have issues
  4. Set up Git preferences (see this Github guide)
    • user.email
    • user.name
    • github.user (perhaps not needed)
    • github.token (perhaps not needed)
  5. Create a README.md file (Github flavored Markdown)
  6. Commit the file and push to remote repository
    • git add README.md
    • git commit -m "Added README" README.md
    • git remote add origin git@github.com:...
    • git push origin master