I have decided to start learning the boost C++ libraries via coding an IRC client class in C++. Currently it is not much, but it can connect to an IRC server and respond to pings.
I have become increasingly frustrated with people refusing to adopt the IEEE 1541-2002 standard. There is no real good reason why it should not be adopted. I think the most common argument I have heard against it is, “That’s stupid! The people who made that up are stupid! You’re stupid for using it!” That is to say, there are no very good arguments against it.
In fact the longer people continue to use the old terminology, the longer the hard drive manufacturers have to use the old terminology to rip off consumers. Did you ever wonder why your hard drive isn’t a full 80GiB? That’s because it said 80GB on the box.
Some argue that it makes no sense to have the extra terminology because computers operate using base 2. The problem with this argument is that the International Bureau of Weights and Measures published a paper in 1998 stating that SI prefixes should only be used with powers of 10.
I think anyone familiar with science understands the necessity for proper measurements. Without them, your data is bad. Let me present a quick example. Let’s say you were looking for a place to store copies of your digital movies. Your computer says they are 4.7GB (but it really means GiB), so you decide to get a 1TB hard drive in which you think you can store 1,000 / 4.7 = 212 full movies. However, the 1TB hard drive is really only 909GiB, which means you can only store about 193 movies. If you leave 20% free space to keep performance up, then that’s only 154 movies.
But the data on the hard drive box was not misrepresented, it was misunderstood. The reason it was misunderstood is because the neglect of the standard passes from the programmer to the average user via the software they use. There I said it, it is your fault programmers.
If you think you have a real reason why not to adopt it, please leave a comment.
A quick explanation of the standard, courtesy of wikipedia:
IEEE 1541 recommends:
- a set of units to refer to quantities used in digital electronics and computing:
- bit (symbol ‘b’), a binary digit;
- byte (symbol ‘B’), a set of adjacent bits (usually, but not necessarily, eight) operated on as a group;
- octet (symbol ‘o’), a group of eight bits;
- a set of prefixes to indicate binary multiples of the aforesaid units:
- kibi (symbol ‘Ki’), 210 = 1024;
- mebi (symbol ‘Mi’), 220 = 1048576;
- gibi (symbol ‘Gi’), 230 = 1073741824;
- tebi (symbol ‘Ti’), 240 = 1099511627776;
- pebi (symbol ‘Pi’), 250 = 1125899906842624;
- exbi (symbol ‘Ei’), 260 = 1152921504606846976;
- that the first part of the binary prefix is pronounced as the analogous SI prefix, and the second part is pronounced as bee;
- that SI prefixes are not used to indicate binary multiples.
MIT has been offering free videos of various courses for quite a while now. Today I came across this video series on multicore programming. I haven’t watched but a few minutes of it so far, but I am hoping to watch all of them before the next semester starts if it proves to be useful in some way. It uses the PS3 framework — I am not sure if this poses an issue with using the videos yet.
I was pondering the unix command line the other day while reading sed & awk, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or functions. Many of the programs one uses to build one-liners are essentially pure functions. An example of a pure function on the unix command line might be the programs uniq or sort. Various other functions such as ps and wget are not so pure, as their output relies on I/O with the operating sytem or server.
All theory aside, here are a few good one-liners.
Uploading Files
tar cjvf - yourDirectory | ssh uname@host "cat > yourDirectory.tar.bz2"
This command will create an archive of “yourDirectory” and upload it to your server via SSH, all in one chained command. Quite handy for uploading local content for sharing or backup.
Edit: Apparently this command transfers large files extremely slow. Oops.
Checking FreeBSD UPDATING File Automatically
portversion | awk '/</ {print $1}' |
xargs -I '{}' awk '/AFFECTS:.*{}/ {print}' /usr/ports/UPDATING > updates.txt
Ok. So this command pertains to the FreeBSD ports system. It is not recommended that you upgrade all your ports at once. There is often information contained in the file /usr/ports/UPDATING about special instructions you may have to follow while upgrading a package. Often times you may have to recompile other packages, or add a line to a configuration file, etc. The string above will check all of the ports tht are out of date, and compare them to the UPDATING file to see if the package is contained. If it is, it writes the name of that port to updates.txt. You can then use this file to know which ports have special instructions. You should probably write an alias for this one.
Converting Line Endings
The following two commands should help with reformatting files. Often times I find myself getting web designs from someone who uses windows. Most editors on windows will save files with DOS line endings. When you open one of these files in unix (in certain editors), the line endings won’t appear properly. The following commands will circumvent this problem, in either situation.
Convert from unix (\n) to DOS (\r\n)
awk '{sub(/$/, "\r")};1' unix_endings.txt > dos_endings.txt
Convert from DOS (\r\n) to unix (\n)
awk '{sub(/\r$/, "")};1' dos_endings.txt > unix_endings.txt
And yes, I realize that I use too many commas when I write: I’m working on it.