Posts for Tuesday, November 17, 2009

Countries in Django

Django is my preferred web framework. If you don't know what I am talking about, then you can read my previous posts, e.g. here and here and so on.

Anyway, for the people who do like Django, it comes with a nice set of local field types for inputting post codes and zip codes in different countries as well as Peruvian national identity numbers, Australian territories, Romanian Bank Account Numbers, Icelandic phone numbers and lots of other stuff. This saves you the hassle of implementing fields for these types of data yourself.

Somewhat bizarrely however, Django does not currently contain a field for what country the person or thing is in, which is often a very basic yet important piece of data to collect.

Fortunately, people have started work on this and on a LanguageField, however the patches have been languishing on the bug tracker for some time.

I wanted the CountryField now, so I copied and pasted from the patches and put it in a module, this is on my code page (direct link is here).

It is pretty obvious how you use it, import the field into your models file:

from whatever.countries import CharField

Then you can add it to a model:

class Whatever(models.Model):
    country_based_in = CountryField(blank = True)

Here the field is shown in the automatically generated admin:

http://commandline.org.uk/images/posts/django/django_countries_field.png

It seems to have all of the countries that one is ever likely to encounter on the web. The module lists countries alphabetically, however lots of online forms put the United States and perhaps the United Kingdom and other large Internet using countries at the top. If you want to do this, then just arrange the tuple in the order that you want, and delete everything from line 276 onwards (i.e. def sorted_countries etc)

This module is beautifully simple, yet it probably saved me 30 to 60 minutes of fiddling about. This is the joy of programming in a friendly open source community, someone has already done the hard work for you already, you just need to dig it out of some bug tracker and adapt it to your needs.

Happy hacking and all that jazz.

Discuss this post - Leave a comment

Posts for Monday, November 16, 2009

Fluxbox, we meet again

I'm sort of tired of KDE4 crashing left and right and Plasma barfing all over me all day. So I decided to check out the current state of lightweight window managers.

Lo and behold, Fluxbox is still going strong. It was the first WM I used way back in 2000-something when I started using Linux full-time. Last time I tried, there were always weird compatibility problems with system tray icons and pagers working properly when running a mix of KDE and Gnome and other apps, but those seem to have cleared up nicely; I have yet to hit any snags. Here's a screenshot.

Fluxbox

This took very minimal effort to install and set up. Maybe a couple hours total. I'm using ipager and conky. The wallpaper comes from the UniQ KDE theme. Vim and Emacs themes are my own.

The Fluxbox style is mydefcon_4 from tenr.de which is probably the largest and most thorough set of themes created by one person that I've witnessed. That fellow is motivated.

For all the bells and whistles of KDE4, what features did I actually use regularly?

  1. A menu of apps
  2. Taskbar + System tray + Clock
  3. KWin's good window management.
  4. Global keyboard shortcuts galore
  5. One widget: current CPU/RAM/Network usage
  6. Mouse/keyboard management, background-setting, etc.

Fluxbox gives me all but number 5, and Conky gives me that. Number 6 you can do with xset and feh and such.

And I like being motivated to use keyboard shortcuts for more things. I'm already halfway there. Maybe I can take the plunge eventually and try a tiling window manager. Not sure I've reached that level of nerditude yet though.

And now I can move and resize windows without my graphics card bursting into flames. Maybe when I can afford a few more cores worth of CPU I'll try KDE4 again. Honestly I think I have too much monitor real-estate for my ancient computer to handle smoothly in KDE4.

Not to knock KDE4; it's awesome and I'll probably go back someday. But everyone needs a break now and then.

Posts for Sunday, November 15, 2009

This Week in Python Stupidity: os.stat, os.utime and Sub-Second Timestamps


The primary design principle behind the Python programming language is to take everything that’s horrible and wrong with Perl and get it horrible and wrong in a completely different and even more hideous way. Today, however, we shall be looking at a particularly egregious case of stupidity the likes of which not even PHP has managed to replicate.

On Unix, timestamps have traditionally been held as an integer number of seconds since the epoch. The modification time for a file is one place such a timestamp has been used. Two groups of system calls are of interest to us here.

First, stat (and its fstat and lstat variants). The stat system call places information about a file into a struct also named stat (which is possible thanks to a lesser case of brain damage in C’s design). To get the mtime of a file, historically we would have used the st_mtime field, which is of type time_t, which is an integer of some kind:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
    struct stat s;
    if (-1 == stat("timmy", &s))
        return EXIT_FAILURE;

    printf("stat.st_mtime for timmy is %ld\n", s.st_mtime);
    return EXIT_SUCCESS;
}

Sometimes we might want to modify a file, but not affect its mtime. Thus, we need a way to set a file’s mtime to a given value, and to do this we would historically have used a function from the utime family:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <utime.h>
#include <fcntl.h>

int main(int argc, char * argv[])
{
    struct stat s;
    if (-1 == stat("timmy", &s))
        return EXIT_FAILURE;

    int fd;
    fd = open("timmy", O_WRONLY, O_TRUNC | O_CREAT);
    if (-1 == fd)
        return EXIT_FAILURE;
    if (0 != close(fd))
        return EXIT_FAILURE;

    struct utimbuf times = { .actime = s.st_atime, .modtime = s.st_mtime };
    if (-1 == utime("timmy", &times))
        return EXIT_FAILURE;

    return EXIT_SUCCESS;
}

(Sidenote: the above almost certainly should be using fstat and futimes instead to avoid race conditions, but this is irrelevant for our examples.)

But all of this operates only on a second-precision basis. For many applications this is no longer sufficient. Fortunately, some kernels and filesystems now support nanosecond-resolution timestamps.

First, for the stat family: rather than using st_mtime, we now use st_mtim, which is a struct timespec:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
    struct stat s;
    if (-1 == stat("timmy", &s))
        return EXIT_FAILURE;

    printf("stat.st_mtim for timmy is %lds %ldns\n",
            s.st_mtim.tv_sec, s.st_mtim.tv_nsec);
    return EXIT_SUCCESS;
}

And if our filesystem supports it, we get something like:

$ ./mtimens
stat.st_mtim for timmy is 1258321672s 173919603ns

As we can see, running our old utime-using code preserves the seconds but not the nanoseconds:

$ touch timmy
$ ./mtimens
stat.st_mtim for timmy is 1258321978s 62671870ns
$ ./utime
$ ./mtimens
stat.st_mtim for timmy is 1258321978s 0ns

To modify preserving nanoseconds, we use either utimensat or futimens:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <utime.h>
#include <fcntl.h>

int main(int argc, char * argv[])
{
    struct stat s;
    if (-1 == stat("timmy", &s))
        return EXIT_FAILURE;

    int fd;
    fd = open("timmy", O_WRONLY, O_TRUNC | O_CREAT);
    if (-1 == fd)
        return EXIT_FAILURE;
    if (0 != close(fd))
        return EXIT_FAILURE;

    struct timespec times[2] = { s.st_atim, s.st_mtim };
    if (-1 == utimensat(AT_FDCWD, "timmy", times, 0))
        return EXIT_FAILURE;

    return EXIT_SUCCESS;
}

And now it works as expected:

$ touch timmy
$ ./mtimens
stat.st_mtim for timmy is 1258322326s 852774523ns
$ ./utimens
$ ./mtimens
stat.st_mtim for timmy is 1258322326s 852774523ns

Incidentally, POSIX.1-2008 considers the non-nanosecond-resolution functions and members to be deprecated, although since the nanosecond resolution functions aren’t universally available yet, a certain amount of autovoodoo is generally required…

Now we shall look at some Python. First, the old way:

import os

s = os.stat("timmy")

f = open("timmy", "w+")
f.close()

os.utime("timmy", (s.st_atime, s.st_mtime))

Now, to see if we can guess how the new way works:

>>> import os
>>> os.stat("timmy").st_mtim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'posix.stat_result' object has no attribute 'st_mtim'

Mmm, nope. Time to consult the documentation. Nothing under stat, but there’s something interesting called stat_float_times:

stat_float_times([newvalue])

Determine whether stat_result represents time stamps as float objects. If newvalue is True, future calls to stat() return floats, if it is False, future calls return ints. If newvalue is omitted, return the current setting.

Uh oh. This can’t be good. Let’s look more closely at what happens when we run our code that uses stat.st_mtime and os.utime:

$ touch timmy
$ ./mtimens
stat.st_mtim for timmy is 1258324320s 762942258ns
$ python utime.py
$ ./mtimens
stat.st_mtim for timmy is 1258324320s 762942000ns
$ ./utimens 12345678901 111111111
$ ./mtimens
stat.st_mtim for timmy is 12345678901s 111111111ns
$ python utime.py
$ ./mtimens
stat.st_mtim for timmy is 12345678901s 111110000ns

What’s that, Lassie? Timmy has lost several significant digits of its sub-second mtime? Oh noes!

Yup, that’s right, Python’s underlying type for floats is an IEEE 754 double, which is only good for about sixteen decimal digits. With ten digits before the decimal point, that leaves six for sub-second resolutions, which is three short of the range required to preserve POSIX nanosecond-resolution timestamps. With dates after the year 2300 or so, that leaves only five accurate digits, which isn’t even enough to deal with microseconds correctly. Brilliant.

Posted in python Tagged: python

Migrated to Sabayon, in need of a EvroKorpus plasmoid

What I would give for a EvroTerm/EvroKorpus plasmoid right now!!! XD

Also, the stability of the Jamendo plugin in Amarok leaves a lot to be desired.

Sabayon is cool (for a temporary replacement for Gentoo).

hook out >> legal counciling, translating and sipping tea...
<!--break-->

links for 2009-11-15

avatar

A lovely little emoticon set from KDE.

I am of the opinion that the default emoticons on KDE are disgusting. Over time I’ve grown accustomed to them but lately I decided to do something once and for all. My solution was in the KDE forums – which had a different iconset (shouldn’t they be the same?) Sure, they didn’t have as many emoticons but I’m not an avid user. Anyways, here is a picture for those unaquainted with those iconsets:

… and of course you can download it here. KDE users can install it from System Settings, or even through Get Hot New Stuff. Users on other operating systems, it’s just a regular .tar.gz file so uncompress it and get the pictures inside and import it your own way.

Related posts:

  1. What is FTP?

It's Been Awhile...

Wow... It's been a long, long time since I updated anything about my life on here.  Mostly because stuff got really busy, and really interesting about April of this year.  I've documented all the crud that we've gone through, so no need to rehash that.

What I would like to say is that music is more a part of my life now than it ever has been.  I play my drums an average of about 30 minutes per day now, whereas before six months ago, I played them more like 30 minutes per month.  I've been spending a large amount of time learning how to properly track, mix, and master audio.  I've created a site for my studio, and am in the process of creating a site for something which I hadn't really seriously considered until two people started paying me to play my drums for their songs.

It's sort of a "remote drummer" type of thing.  Basically, musicians write their songs, record them the best they can, and then send them to me to play and record the drums for them.  Evidently, people think I can play much better than I think I can, and right now, we can certainly use the money.

So...  That's what's up.

Well...  Almost...    I've got a Christmas-based project I'm working on with a friend which is turning out to be one of the funnest and most professional projects I've ever worked on.  Talk about trial by fire.

Anyway...  As the project progresses, I'll let ya more in to what exactly is going on, but for now, I'm having the time of my life with it.

And that's about it for this time of the morning.  I've gotta go to choir in a few hours!

Posts for Saturday, November 14, 2009

Installing Go in Ubuntu Jaunty

Processor: x86
Operating System: Ubuntu Linux 9.04 Jaunty Jackalope

1. CONFIGURE THE ENVIRONMENT
Set the necessary variables in your .bashrc that is if you are using bash. Assuming you have a 386-descendant processor and you want to keep the installation clean in an external disk (/media/disk).

# Google Go Programming Language Settings
export GOROOT=/media/disk/go
export GOARCH=386
export GOOS=linux
export GOBIN=/media/disk/go/bin

2. INSTALL MERCURIAL.
Easy.

$ sudo easy_install mercurial

Install process,

Searching for mercurial
Reading http://pypi.python.org/simple/mercurial/
Reading http://www.selenic.com/mercurial
Best match: mercurial 1.3.1
Downloading http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz
Processing mercurial-1.3.1.tar.gz
Running mercurial-1.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-a3YaRd/mercurial-1.3.1/egg-dist-tmp-VyNqd2
zip_safe flag not set; analyzing archive contents...
mercurial.lsprof: module references __file__
mercurial.templater: module references __file__
mercurial.extensions: module references __file__
mercurial.i18n: module references __file__
Adding mercurial 1.3.1 to easy-install.pth file
Installing hg script to /usr/local/bin
	
Installed /usr/local/lib/python2.6/dist-packages/mercurial-1.3.1-py2.6-linux-i686.egg
Processing dependencies for mercurial
Finished processing dependencies for mercurial


3. CHECKOUT GO USING MERCURIAL

$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT

Checkout process,

requesting all changes
adding changesets
adding manifests
adding file changes
added 4016 changesets with 16888 changes to 2931 files
updating working directory
1640 files updated, 0 files merged, 0 files removed, 0 files unresolved

4. BUILD GO

$ cd $GOROOT/src
$ ./all.bash

Build process,

--- cd pkg/exp/ogle
rm -rf *.[568vqo] *.a [568vq].out *.cgo[12].go *.cgo[34].c *.so _obj _test _testmain.go ogle
8g -o _go_.8 abort.go arch.go cmd.go event.go frame.go goroutine.go rruntime.go rtype.go rvalue.go process.go vars.go
rm -f _obj/exp/ogle.a
gopack grc _obj/exp/ogle.a _go_.8
8g -I_obj main.go
8l -L_obj -o ogle main.8
	
real	0m2.264s
user	0m1.496s
sys	0m0.136s
	
--- cd ../doc/progs
	
real	0m4.430s
user	0m3.144s
sys	0m0.444s
	
--- cd ../test/bench
fasta
reverse-complement
nbody
binary-tree
binary-tree-freelist
fannkuch
regex-dna
spectral-norm
k-nucleotide
mandelbrot
meteor-contest
pidigits
threadring
chameneosredux

It should end with the following lines,

--- cd ../test
0 known bugs; 0 unexpected bugs

5. ENJOY!

avatar

Aspire One / X.org screen blanking

When using X on my Acer Aspire One (110L) and playing videos with mplayer, X would occasionally blank the screen after a few minutes without any way out but to suspend/resume to get your X back. This didn’t only happen with mplayer, and it didn’t have anything to do with xscreensaver.Anyway, after some digging I found that adding Option "FramebufferCompression" "off"to the Device-section of my xorg.conf resolved the problem.
Another cool thing I found out while going through ssh manpages is that you can silence the motd on login simply by touching ~/.hushlogin.

I'm turning into a Lisp snob

Reddit and StackOverflow and other websites I frequent are filled to the brim with discussion of Google's Go. The code snippet on the front page is:

package main

import "fmt"

func main() {
  fmt.Printf("Hello, 世界\n")
}

First thoughts that ran through my head as I looked over the site:

  • Ugh, look at all that syntax.
  • Nice(r) type system (than C++ and Java). I'll stick with multimethods though.
  • Concurrency semantics, hmmm... Shared mutable memory between threads? I think I'll stick with Clojure for now thanks.
  • Where are the macros?
  • It has anonymous functions and closures and sort-of first-class functions? Good. Welcome to the 1960's.
  • len is a special operator? Sigh. (Programming language quality is usually inversely proportional to the number of special forms.)
  • Cool that they used Japanese in the example though. (That word is sekai, "world", obviously.)

Compared to a Lisp, this language looks indistinguishable to C, Perl, Python, Java etc. It looks like such a small incremental improvement (if it even is an improvement). Yet another imperative, for-loop-wielding, curly-brace-using, pointer-mangling, state-mutating, OOP language.

In fact via Reddit today I read this awesome post to a mailing list which compares Go with ALGOL68, and it gave me a would-you-look-at-that moment. Once you learn a few languages that are significantly different from ALGOL derivatives, all ALGOLish languages start to look eerily similar. Are we really stuck with ALGOL-derived languages being the only viable mainstream languages for all time? How much polish can we possibly apply to the same turd?

Then I realized, I'm turning into a Lisp snob. : ( Learning a Lisp apparently does spoil you for the rest of time. I am without a basis to judge whether this language will be a successful replacement of anything. All I know is I probably won't use it. Honestly I'm much more excited about new things on the horizon in Clojure. And I still have getting better at Haskell on my TODO list.

Posts for Friday, November 13, 2009

avatar

Gentoo Wallpaper

I just found this wallpaper I seem to have made in ‘06 (around August) and posted to the Gentoo Forums. It never went anywhere, but it would be a shame to let it go to waste, so here you go. Don’t ask for any higher resolutions though ;)

Download it in 800×600, 1024×768 or 1280×1024.

Linux audio player comparison (nit-picking)

Given my inability to use Amarok 1.4 and my lack of desire to use Amarok 2.0, I tried loads of music players and for now I've landed on aTunes.

It's not perfect. It's far from perfect. But it's the best of the bunch. These are the features I MUST HAVE for a media player and which aTunes possesses.

  1. Last.fm integration. aTunes has probably the best integration I've seen in a player, without going over-the-top and stuffing a whole web browser into the app.
  2. System tray icon, right-clickable with song controls in the menu.
  3. Commandline interface.
  4. Able to display CJK fonts. In Arch (or in Gentoo using the icedtea6-bin VM) CJK fonts are displayed as empty boxes, but in Gentoo using Sun JVM, it works fine.
  5. Tag editing. aTunes has a pretty nice tag editor for single songs or multiple at once.
  6. Amarok-like tree of albums/artists/genres/whatever I want. I want a single expandable and collapsable tree-list, not 3 panes I have to click between.
  7. Equalizer.
  8. Skins are nice; aTunes has these.
  9. "Collection" support and folder-watching/auto-updating when I dump music into ~/music. aTunes does this very well. Scanned a few thousand files fairly quickly, and does updates very fast.
  10. Amarok-1.4-like spreadsheetish playlist layout.
  11. Lightweight build process. No gstreamer. aTunes provides Mplayer and Xine backends and has few to no other dependencies (besides Java). The Mplayer backend didn't work out very well for me, but Xine works beautifully.

It also has some other nice bonuses, like the elegant way it uses the Album Artist tag for albums with multiple artists, the interesting statistics and bar graphs it can produce from your song listening history, playlist tabs, and so on.

Things I dislike about aTunes... well it's a Java app, so it takes a decade to start up. It also has horrid fonts and the widgets are clunky. But it's responsive once it's running, and I don't care how it looks as much as how sane the layout is. Searching is also clunky. But these aren't show-stoppers.

Here's a list of other players I tried, and why I didn't use them.

Amarok 1.4

  • I'd use this if I could. :( It compiles and runs on my Gentoo box but too much stuff is broken due to bit-rot.

Amarok 2

Banshee

  • It wanted to pull in about a billion and a half Gnome dependencies. This is not fun for a KDE user.

Songbird

So close. This is probably second place behind aTunes. It has a great plugin system, it's skinnable, the layout is extremely functional and compact and easy to use and customizable. But...

  • No system tray icon in Linux! This is a show-stopper. There's alltray but it doesn't let me right-click and have song controls.
  • It has a clumsy commandline interface which makes setting global KDE keyboard shortcuts annoying.
  • Bloat. Do you really need a full-fledged web browser in your media player?
  • XUL, ew.

gmusicbrowser

This is very customizable (almost absurdly so) and looks promising. However...

  • Still a bit beta-quality.
  • Crashed on me a couple times in the short time I used it.
  • Interface has a kitchen-sink feel to it. Too many tabs and widgets all over the place. I couldn't find a layout I liked.
  • Looks pretty good, but no real compelling reason to use this.
  • Written in Perl?

amaroq

  • Alpha-quality PyQt4 clone of Amarok 1.4. Looks promising. I will keep an eye on this.

MPD

Last time I tried MPD was years ago. If aTunes doesn't work out, I'll try this next. But aTunes has kept me going for a week now, and I have very few complaints.

If they do a complete rewrite for aTunes 2.0 and destroy the interface, I'll jump off a bridge.

Clojure: redirecting output to a file

In a scripting language, you often run scripts from a command line and print things to STDOUT. For long output you can redirect it to a file via shell-redirection ($ foo.rb > foo.txt).

But if you're using Clojure for ad-hoc scripting, you're probably sitting in a REPL, not running from a command line. REPLs generally don't have shell-redirection. Printed output just gets dumped into your REPL. This can be annoying. (After a good 10,000 lines of output into a REPL buffer, Emacs starts to lag.)

But you can write a macro to handle this easily enough.

(use 'clojure.contrib.duck-streams)
(defmacro redir [filename & body]
  `(spit ~filename (with-out-str ~@body)))

Then:

user> (redir "foo.txt" (foo) (bar) (baz))

Now whatever (foo) and friends would've printed to STDOUT will instead go to foo.txt. I've found this somewhat useful at work lately.

Edit: better version via Graham Fawcett:

(defmacro redir [filename & body]
  `(binding [*out* (writer ~filename)] ~@body))

Sleep Button in KDE 4 Workaround


If you noticed that pushing the sleep button does nothing in KDE 4 (as of this writing <=4.3.3), this is because of a bug in KDEs’ power management tool Powerdevil. It appears that in most cases Powerdevil does not recognize the Xorg servers’ XF86Sleep key. To fix this, you may be able to rebind the sleep key in the KDE control panel.

Add a New Input Action

Open System Settings then Input Actions. Then add a new Global Shortcut:

Name it ‘Sleep’ or whatever you like. Add a Comment if you wish and in the Trigger tab select your hotkey. Try setting the sleep key first. For me, setting the hotkey to the sleep key didn’t work because I believe that Powerdevil already has it bound. There have been others though that look to have sucessfully done so.

Note: If someone knows of a way to decouple the Powerdevil sleep key please let me know.

I bound mine to Scroll Lock (hope I don’t need it anytime soon) then in the Action tab entere the dbus command to suspend to ram:

qdbus org.kde.kded /modules/powerdevil suspend 2

If this doesn’t work, try ’suspend 1′. If you would like to suspend to disk:

qdbus org.kde.kded /modules/powerdevil suspend 4

Posts for Thursday, November 12, 2009

Loggerhead Init Script for Gentoo

I just set up a Bazaar repository server at work. Gentoo has no official ebuild for Loggerhead, so I installed it from Mark Lee's Bazaar overlay. Unfortunately, this does not ship with an init script for serve-branches, so I wrote one.

The script is /etc/init.d/loggerhead (mode 755):

#!/sbin/runscript
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

PIDFILE=/var/run/loggerhead.pid
LOGDIR=/var/log/loggerhead

depend() {
    need net
}

start() {
    ebegin "Starting loggerhead"
        start-stop-daemon --start --quiet --background \
        --make-pidfile --pidfile ${PIDFILE} \
        --exec /usr/bin/serve-branches -- --log-folder=${LOGDIR} \
        ${LOGGERHEAD_OPTS}
    eend $?
}                               
                                
stop() {                        
    ebegin "Stopping loggerhead"
        start-stop-daemon --stop --quiet \
        --pidfile ${PIDFILE}
    eend $?                 
}

This uses a single entry from /etc/conf.d/loggerhead:

LOGGERHEAD_OPTS="/var/bzr"

It seems to work. When I get the chance I may patch the ebuild to include it and suggest it to the maintainer.

How Round Is Your Circle?


As everyone knows, a point is that which has no part, a line is a breadthless length, and it is possible to cut a sphere up into a finite number of pieces, move them around and put them back together again to get two spheres identical in every way to the original sphere.

Unfortunately, in reality, points have a size, lines have a width, spheres aren’t spheres and they can’t be cut up into infinitely complicated pieces. How Round Is Your Circle, Where Engineering and Mathematics Meet by John Bryant and Chris Sangwin is an attempt by engineers to convince mathematicians that caring about real world issues can be interesting.

The book covers various practical issues, such as:

  • How to draw a straight line, and how to make a ruler
  • How to test how circular a circle is
  • How to measure area

In the process, it discusses all kinds of cunning gadgetry used in the olden days before digital computers and mass production, from steam engine linkages and pistons to slide rules and draughting devices. It also covers various physical demonstrations of geometric problems, and illustrates what happens when physical inaccuracies are ignored:

64 = 65

It’s certainly an interesting read, although I would have preferred more emphasis on the tools and gadgets used than on demonstrations of things they can be used to make. The maths isn’t particularly heavy, and shouldn’t put too many people off. Similarly, there’s nothing on the engineering side that would be inaccessible to anyone with no engineering background.

Posted in hardware Tagged: books
avatar

stackoverflow response that I absolutely loved


I absolutely love this quote:

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand” (Martin Fowler, “Refactoring: Improving the Design of Existing Code”)

Check out this question/answer on stackoverflow.com.

Is Google evil?

Google has become quite ubiquitous in our modern world. Starting out as a pure search engine, the company added Email and online office applications as well as a maps and route planning software and many many more. Whenever Google sees a need for more or better software they seem to jump in trying to fix it.

Google is really into personalization: They offer to store your search history in order to improve future searches for example. Their contacts application transcends application borders to make finding your contacts simple (as long as everybody has a Google account).

On the other hand Google is being severely criticized for their monopoly on information: If Google drops your page from their index it's basically dead because people will not find it (given Google's marketshare). Google's company motto is "Don't be evil" but how serious can we take that statement? Are we too focussed on that one service to rule them all?

Let's look at how Google got where it is today. Back in the day there were many competing search engines (and meta search engines) but at some point everybody started using Google because it was the best product, it provided the best (most relevant) results, it was not as cluttered as the other offerings, it was simple to use but powerful.

From their very strong position in search they branched out: When GMail came out, most other services didn't offer as much storage and Gmail's interface is still one of the best (if not the best) webmail interfaces out there (and it supports real tagging).

Instead of relying on slow Java Applets, Google Maps ran quick in every browser. It had not just abstract maps but also the overlayed satellite photo view which looks really cool.

Looking back Google got into the position they are in by competing and winning. I'm not one of those "the market will fix everything, yay" kind of people, but if you think that markets are such a good thing, Google did play your game.

Well let's get back to the topic at hand, are they "evil"?

Looking at how Google seems to work and what kinds of software they release they are not evil they're just radical pragmatists, or even simpler: Engineers. The engineer sees a problem and seeks a technical solution to it. But many of the problems that technology creates (for example privacy issues) are not technological problems themselves and therefore cannot be solved by technology.

I've heard people joking about Germans based on the existence of the word "Technikfolgenabschätzung". That a word like that could just come from Germans cause they take everything to seriously. But technology assessment, as it's called in English, is often what Google lacks. Google's not evil, they just seem to look at the world through a purely technological filter and (please engineers, don't cry) most problems are not technical.

I do absolutely agree with people that advise others to reflect their media and service usage, to think about whether putting all their data into one company's hands is such a smart idea, to see whether other services might serve them better, but I also believe in using the best tool for the job.

It's kinda funny how people complain about Google building a monopoly when they run Microsoft's Windows on all their machines. Monopolies slap you in the face all over the place.

And Microsoft isn't "evil" either, they just produce an operating system that is not good enough for me to use. "Evil" and "good" are words that fit into fairy tales and religious texts but they usually do not apply to what people in the real world do because they are not absolute.

We all know the "evil genius" character from movies, but does that happen in the real world? Do people use an evil laughter and plan nasty things? No.

Everybody acts on what they know and think is right. Their assumptions on what is right, their priorities might be different than yours, but nobody acts "evil". If you look at other people's actions you might consider them to be evil, but that's because you compare them to your own set of rules and priorities. We as a society have agreed on a certain canon of things generally to be considered "good" but probably everybody could name a few circumstances where those rules don't apply: Many people would agree to killing a mass murderer "for the greater good" for example even though killing people is generally considered to be "bad".

Google isn't evil and I love many of their services but I'm always careful when it comes to giving others full access to my data (which is why I host my own mail server for example). The monopoly Google built is based on merit. You are concerned about that? Fix it, build something better.

My boss recently said that maybe the government should provide a search engine (obviously an uncensored one) and actually I think that is a great idea: Let's take all that EU money they burn in worthless projects every year and hire a bunch of smart people to run a not-for-profit search engine. Don't outsource it to companies that just try to milk the project but really set up your own group doing it. If your service is as good as (or even better than) Google's, the monopoly will be broken. But just telling people to use services that work worse for them won't help and isn't the right way.

Clients are annoying, but life goes on

It's only Wednesday, and it feels like tomorrow should be Friday or Saturday. It's been a long week at work, dealing with some annoyances from clients. One in particular is rushing us along with any real understanding of the underlying process and order that tasks need to be completed in. I'm sorry, but we can't take your site live until your previous host releases your domain name to us. Maybe you should call them.

Another client is just being stubborn when we're working as fast as we can to get his site up. If we ask you to test-drive the site, don't tell us that you'll test drive it after we do. If you work at the same pace we do, we'll hammer out more bugs in a shorter period of time.

We're going to be re-working our terms with the latter of those two clients after this project is completed. We have so many pressing projects right now that every spare moment is precious. When we're ready for you to test the site, you will test the site.

Outside of work, I've enjoyed the last few nights. Sunday night, a few friends and I saw The Reverend Peyton's Big Damn Band at Pittsburgh's Hard Rock Cafe. Tuesday, I helped my friend Nick set up his new blog that I'm hosting. He'll be focusing on a lot of computer security matters, so it should be a good read.

Which brings me to today — Wednesday — where I received a phone call around 3:30PM asking me to come in and help cook for burger night at my Moose Lodge. I worked burger night from when I was fired from Buffalo Wild Wings up to when I landed the job at Savvior. I stopped only because burger night starts at 5:00PM, the same time I leave work. Somehow, I managed to make it from the Northside to Greensburg in just under an hour. We had an easy night.

I have so many projects I want to pursue right now that it's ridiculous. There are so many time constraints between work and friends, that it seems impossible to even maintain one of these projects. And I only continue to add more projects to that list! And now I'm back to the spot where I'm considering taking an officer position at my Moose Lodge. Maybe if I take the time one day and finally hook up the lodge's DSL and put in a wireless router I can work on my projects from there. We'll have to see.

Are you treating your computer better than yourself?

Yes, I am guilty. Most of us are not aware that we are treating our computers better than ourselves. We often juggle tasks like a computer processor. It has been proven by experts recently that multitasking drops IQ. The Dumb Little Man has some cool tips for us.

Read the article, Are You Treating Your Computer Better Than You Treat Yourself?

Posts for Wednesday, November 11, 2009

Doukutsu (aka Cave Story) with an Xbox Controller


What do you know, Doukutsu (aka Cave Story) can be played with a Gamepad! For a Xbox controller this is how I set the controls:

SVG

And how to configure it:

Works great. I love this game. If you don’t want to install Wine (the configuration tool requires Wine) you can download this config file and place it as ‘~/.doukutsu/Config.dat.

tar -xvf doukutsu-config.tar.gz -C ~/

It’s an executable file (probably because the Wine app edited it), haven’t bothered changing it :).

The Go Programming Language

Good day! Try out [The Go Programming Language].

As quoted from its home page,

Go is …

… simple

package main
	
import "fmt"
	
func main() {
  fmt.Printf("Hello, 世界\n")
}

… fast
Go compilers produce fast code fast. Typical builds take a fraction of a second yet the resulting programs run nearly as quickly as comparable C or C++ code.

… safe
Go is type safe and memory safe. Go has pointers but no pointer arithmetic. For random access, use slices, which know their limits.

… concurrent
Go promotes writing systems and servers as sets of lightweight communicating processes, called goroutines, with strong support from the language. Run thousands of goroutines if you want—and say good-bye to stack overflows.

… fun
Go has fast builds, clean syntax, garbage collection, methods for any type, and run-time reflection. It feels like a dynamic language but has the speed and safety of a static language. It’s a joy to use.

… open source

Install Go! Click [here].

Posts for Tuesday, November 10, 2009

avatar

finally attempting to use stackoverflow


For a while now, I’ve seen stackoverflow in my google searches, but whenever I went there, I never felt like I wanted to participate.  But after watching this google tech talk about stackoverflow, it kind of inspired me to start using it.

Upon navigating to stackoverflow.com, I also stumbled upon sister sites of stackoverflow and promptly signed up with them too.  But one in particular caught my eye, careers.stackoverflow.com.  It is basically a supped up resume platform.  It looks pretty awesome and I’ve signed up for that also.  Just need to get working on filling it out.  I’ll probably do that tonight and post it on here when I’m done with it.

Pretty cool none-the-less.

To Parted Magic with <3


I’ve never gotten into a good grove when it comes maintenance of a hard drive. Usually this process involves me loading a LiveCD like Ubuntu, downloading the tools I needed (Gparted, shredder, Partiso…) and going through the slow proccess from there. On occasion when I have to do this process over I have to download all the tools again and it’s just not that much fun to try to remember where the package manager is and what the package names are. This is probably one of those cases where everyone has heard about it but me, but I just discovered Parted Magic and I’m… in… love.

Parted Magic is just a really well put together tool. It boots with a number of options in Grub (a nice feature [and the default] is that Parted Magic will load into RAM). The Grub menu also features SuperGrub which I’ve never tried before but am glad it’s there in case anything goes wrong. This is the first CD that I’ve booted to RAM (expect the Gentoo minimum install CD [which doesn't really count]) and the ability to take off the sludge of constantly churning, throughput-hogging CD drive is nice. Programs start in a snap and I feel that in my time I’m actually doing something instead of pretending I want another sip of coffee.

Parted Magic keeps it lightweight and uses the LXDE Desktop. I have never tried the LX Desktop Environment before but it is very responsive – something you can kinda forget about with modern desktops. Beside being fast, for the basic tasks I really didn’t find anything on LXDE I could not do on my KDE desktop. Thankfully too, Parted Magic keeps it lightweight by only including the needed programs so you won’t find yourself digging to find a program. Since I like to keep to the basics on my desktop (and trust me on KDE that isn’t an easy thing to do), I really appreciated this.

Parted Magic had all the tools I needed to be able to install a new hard drive. Since I wanted my old system on the new drive, I used Gparted to format it, then Clonezilla (yes, it’s included) to image it over. Afterwords, I resized the partitions with Gparted, then shredded the old drive with the Erase Disk utility. Other handy tools are also included like a mounting tool that makes mounting/unmounting quick and easy, TestDisk for possible repair of a damaged partition table, Photorec to recover Photos on a damaged drive, other cloning tools and believe it or not Firefox (which I think is a good idea in case you ever get in trouble). If you install on a USB stick you also have the ability to save the settings so they will be remembered on the next boot. This is really nice feature but must still be new as I found it would only work part of the time when the USB stick is loading.

Overall Parted Magic is a nice tool that I deperately needed. Thanks to Patrick who developed this tool and making my life in Linux alot more pleasant.

Wonders from a KDE fan and developer about some KDE design choices

Technologies going forward..

Twenty years ago, I was reading some books about Unix at the local library. By the time, it was really difficult for me to see, touch, or test an actual unix system and reading books was the closest I could get.

I remember that among the numerous very good ideas ™ in this system, one totally buzzed me : processes and memory protection. A piece of software was protected from other pieces. If one crahes, the other ones could still keep on doing their stuff. Amazing feature, isn’t it ??

Years later, and until very recently, I could proudly say to my friends: “I use linux, I don’t have such problems that you have in Windows and MacOS”. Well, of course, now at least MacOS is based on a serious kernel and the Windows kernel is far better in this regard. But still, unix has had it for very long, and among them, my favourite Unix : Linux.

… forward …

And then, people started to talk about plasma. It is cool, it is great, it is beautiful. One of the reasons I like KDE so much, is that I am very happy with the technology choices made by the project over the time (do you remember the drop of CORBA ?). I’m not into buzz and fancy desktop, so I did not pay much attention to plasma at the beginning. Later on,  I started to try KDE trunk again. For months, it was about: compile, start, wait few seconds, plasma crashed, and the whole desktop/X session restarted.

Then, it got better : plasma crashing would not make the whole session crash, and plasma would handle its own crashes gracefully by restarting. Trust me, I really like KDE, but I could NOT resist to think “Hey, they now handle crashes as well as MS Word do!, great job!”. Well, of course, It was still pre-alpha times, you are not supposed to expect more at this time.

.. and backward

Still some months pass by, and came the beta time. I could finally get into KDE and plasma would not crash on startup. So I tried this new plasmoid thinguy. I added few plasmoids, played with them, even configured some. I tried to add a new one… and WLANG, suddently the whole thing crashed.

Do you see my point ? One of the plasmoids made the whole plasma thing crash. We are back 30 years ahead in time. End of process separation and memory protection. Back to the “don’t try to touch anything, it WORKS, don’t disturb it” and “I do not dare trying this new cool stuff because it could crash it all”.

Design

This sounded weird. Really, really weird. I wondered, and learned that indeed plasma was only one process. It seemed to me like a very bad design choice, but I do not know much about all of this, so I just kept my faith in KDE and did not worry too much. I don’t know anything about internals. I talked to a few people, on IRC, in real life… but nobody seems concerned. Nothing about that on the FAQ, not even on the (short) architecture documentation.

As time goes by, people put almost anything into plasma. I mean it : anything. Developers and users for once seem to agree, and everybody is happy. I still do not really understand the need to put a browser in a plasmoid, but if people enjoy that, I don’t have a problem with this. Free software is all about fun, isn’t it ?

After I updated to KDE 4.2.1, I’ve spent one hour to fix it, finally removing the plasma configuration files to get a usable system. I did not look further, but I guess I could have removed only one part of one file, or maybe even just remove a faulty plasmoid.

I don’t mind the hour I’ve spent… but I worry about the design of plasma. I do not dare asking plasma people, as it seems so.. deeply obvious. They MUST have thought about it, mustn’t they ?

A trend in KDE ?

Today I had to kill one of my konsole because one of the software I’m working on was eating all the memory. I used the great CTRL-ALT-ESCAPE kill feature and that saved my computer. Once recovered, I was really surprised to see that all my konsoles were dead. “ps” could confirm this. I usually have 4 or 5 konsoles with 5 or 6 tabs each. Lot of opened vi inside and so on. A doubt came to me and i started several new konsole, and then issued a “ps aux | grep konsole”. You’ve guessed it, only one was present. I rushed on konsole source code and konsole/src/main.cpp confirmed my fears : konsole uses only one process on purpose, through the use of KUniqueApplication.

I don’t understand and I’m sad about this.

Conclusion

Don’t get me wrong , I still think that a lot of things are still done right in plasma (and KDE in general): separation between data and views (nothing new, but still a great thing to do), packaging (though it’s not done yet, I like the ideas). And it looks darn good, that’s right, too.

I just feel very uncomfortable with this. This is the first time ever in more than 10 years  that I am not happy with a KDE design choice, and a blog post looked like a great way to release this embarassment. As usual I’m afraid that people will read this post lightly, will feel insulted, and will answer with even more insults.

Planet Larry is not officially affiliated with Gentoo Linux. Original artwork and logos copyright Gentoo Foundation. Yadda, yadda, yadda.