This blog is now hosted at consciou.us

Saturday, February 27, 2010

Random bass

I suppose I have to do this sooner or later. Here's a track I recorded.

Gear:

Fender Squier 5 string Jazz Bass, defretted by yours truly.
Korg PXR4
Audacity for some post-recording cleanup.

I made this whole thing up on the fly; there were three tracks:

1) the "drum" part: basically a muted slap of the fingerboard
2) single notes
3) "7" chords (1,3,b7)

Random bass Read more...

Friday, February 26, 2010

Numeric Formatting in Django

You might have seen my previous post lamenting the weirdnesses around number formatting in python.  This spills over into Django; if you have DecimalFields in your models (especially if you are using the ModelForm object to create your forms.


The previous "format Decimal object as a string that any 10-year-old would expect" method is:

def dec_string(dec):
    if isinstance(dec, Decimal):
        if dec:
            if dec.normalize().as_tuple().exponent > 0:
                return "%d"%dec
            else:
                return "%s"%dec.normalize()
        else:
            return 0
    else:
        return dec
(I added the isinstance() bit to protect me from myself =)

Since we know how to format this, all that remains to be done is to create a widget that automatically formats DecimalFields correctly.


class DecimalInput(TextInput):
  def render(self, name, value, attrs=None):
    value = dec_string(value)
    return super(DecimalInput, self).render(name, value, attrs)
And then just use that in your form:

class EnergyForm(ModelForm):
    kwh = DecimalField(widget=DecimalInput(attrs={'size':'6'}))

There is more to the ModelForm, but that's what the docs are for, right? Read more...

Numeric Formatting in Python

Sometimes I hate Python. Here's the difference between Perl and Python: Perl accepts, even embraces the fact that language is messy. Python sometimes gets this wrong.

Here are some samples of dealing with formatting numbers:

from decimal import Decimal

>>> f= Decimal('1200.1')
>>> "%s"%f.normalize()
'1200.1'
Huzzah, it does the right thing!

>>> f= Decimal('1200')
>>> "%s"%f.normalize()
'1.2E+3'
 Doh!  But clearly, removing the normalize() will fix things, right?

>>> "%s"%f
'1200'
Yee-haw! Now we're cooking!

>>> f= Decimal('1200.100')
>>> "%s"%f
'1200.100'
Hm, users don't want the trailing zeroes.  The only thing that I can think to do is use a regular expression, and now I have two problems.

 But wait! If the number doesn't have anything after the decimal, then we do one, and if it does, we do the other!

def dec_string(dec):
    if dec:
        if dec.normalize().as_tuple().exponent > 0:
            return "%d"%dec
        else:
            return "%s"%dec.normalize()
    else:
        return 0
 And that seems to be working.  Note that the final version uses "%d"%dec, rather than %s, since we want to make sure and truncate past the decimal.

Update: check out my post about integrating it with Django forms to make it seamless. Read more...

Thursday, February 25, 2010

Nginx for static content

At Sage Steps, we're using Nginx (http://wiki.nginx.org/) as a front-end web server.  It serves up our static content, and load balances the back-end Apache servers.


location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|html|htm)$ {
root /static;
}

All of the dynamic stuff is happening in Django running under Apache using ModWsgi. Since this is a fairly heavy stack (Apache is very robust and featureful, but is also somewhat romanesque).

So that we're not using a 10 lb sledgehammer to do finish nails (remind me to tell you about the time that I saw a full-bird Colonel drop a sledgehammer on a Lt. Colonel's foot!), we basically tell Nginx to serve up anything ending in "jpg", "xls", "pdf", etc. from the static directory, without talking to Apache. Read more...

Wednesday, February 24, 2010

Blacklist in CyanogenMod

If you are running CyanogenMod on your Android device, and are surprised that some people seem to not be able to call you (half a ring, then hangup), you probably accidentally blacklisted that user.

My hope was that there was some simple method to clear this blacklist (which essentially "killfile"s phone numbers).  Either I misunderstood the user interface, or there was something desperately broken, but I could not figure out a way to clear the blacklist.  So I went digging in the source (yeah for open source!).

Turns out there is a file called blacklist.dat that stores these numbers, so here's my brute force solution for clearing the phone black list:

  1. open terminal
  2. su
  3. rm /data/data/com.android.phone/files/blacklist.dat
  4. reboot
Reboot is required.  Do it now.

And now, your wife is able to call you again, contributing to marital harmony FTW.

PS- no, I didn't tell you that you need a rooted phone, since you don't have this issue unless your phone is rooted. Read more...

Tuesday, February 23, 2010

Ribbecke Halfling For Sale

With a serious bit of sadness, I've finally made peace with the fact that it's time to sell the Halfling.  Breaks my heart to see this instrument go; I hope it goes to a good home.

It will be available on Bass Northwest's web site (http://bassnw.com/) by tomorrow.  You can also contact me if you are interested in purchasing.

I realized as I was getting ready to write this that I never did a full blown blog post about the Halfling (one under construction one was all). Shame on me!  This is one of the most unique bass guitars that I've ever seen; the tone, workmanship, and looks on this guitar rival any boutique, high-end guitar/bass. To make up for not doing a full post, here are some pictures of this very, very beautiful guitar.



Read more...

Sunday, February 21, 2010

New business card?


I'm looking for feedback. I'm thinking of making this my new "personal" business card.




Questions for the gallery:

  • What do you think of the tagline?
  • What do you think about the flourishes?
  • What do you think about the domain name (consciou.us)?




-- Read more...

Thursday, February 18, 2010

Purging a hard drive in Linux





There is a lot of information available out there on purging hard drives; this is the lower-security, quicker way to do it.

dd bs=1M if=/dev/zero of=/hard/drive/device

This will overwrite the drive with zeroes.

for more security, but a longer process:

dd bs=1M if=/dev/urandom of=/hard/drive/device

Which will overwrite the drive with random data.

Read more...

Wednesday, February 17, 2010

Haitz's Law, and what it means


What it means is this: you will be using LED based lighting within the next few years.

Haitz's law on Wikipedia. Briefly, LEDs' cost per lumen falls by a factor of 10 every 10 years, and the output in a particular format rises by a factor of 20.

In other words, that LED bulb that now costs $60 will be:

  • $12 in a few short years,
  • Will have a lifespan measured in tens of thousands of hours (rather than 1000 hours for the typical incandescent)
  • Will be 2-3 times more efficient in terms of energy usage than a comparable incandescent.
I don't think that the time to buy is right now (the economics are sound, but they are going to get significantly better), but in the next few years, LED lighting is going to be the obvious choice. Read more...

Tuesday, February 16, 2010

Want. Now.

Well, the title is Random Desiderata, after all.

I need one of these immediately: Millennium Falcon.


(from Gizmodo)

My faith in mankind has been restored.

Read more...