Saturday, January 9, 2010

tumble

I'm not happy with this blog, I'm not sure why I'm not happy with this blog, but I figure since it's 2010 I should get a tumblog.
http://jes5199.tumblr.com

Monday, August 17, 2009

ruby's sprintf considered harmful

irb(main):001:0> sprintf("%d", "01")
=> "1"
irb(main):002:0> sprintf("%d", "02")
=> "2"
irb(main):003:0> sprintf("%d", "03")
=> "3"
irb(main):004:0> sprintf("%d", "04")
=> "4"
irb(main):005:0> sprintf("%d", "05")
=> "5"
irb(main):006:0> sprintf("%d", "06")
=> "6"
irb(main):007:0> sprintf("%d", "07")
=> "7"
irb(main):008:0> sprintf("%d", "08")
ArgumentError: invalid value for Integer: "08"
from (irb):8:in `sprintf'
from (irb):8
irb(main):009:0> sprintf("%d", "09")
ArgumentError: invalid value for Integer: "09"
from (irb):9:in `sprintf'
from (irb):9

irb(main):010:0> sprintf("%d", "10")
=> "10"
irb(main):011:0> sprintf("%d", "11")
=> "11"
irb(main):012:0> sprintf("%d", "12")
=> "12"

Of course, this bug's been known for years.

Wednesday, May 6, 2009

unexpectedly dangerous commands

rsync! unexpectedly dangerous!

rsync -a . root@pom:~
sending incremental file list
./
.acl
README.txt


oops, I should have specified a sub-directory.
and then...

ssh root@pom -i ~/.ssh/id-key
root@pom's password:


ssh no longer accepts my key.
because rsync's "-a" flag changed the ownership of the target directory

Thursday, April 2, 2009

(rails) naming chained named scopes

Is nobody doing this?

Rails named scopes are chainable, right? Here's a traditional example:
class Story < ActiveRecord::Base
named_scope :hilarious, :conditions => ["type = ?","comedy"]
named_scope :popular, :conditions => ["popularity_level > ?", 3]
end

and then you can ask for Story.popular.hilarious.all

But it didn't take much complexity for me to want to make a named scopes that represented a chain of named scopes.
Here's my first draft of a solution:

named_scope :hilarious_and_popular, lambda{ self.hilarious.popular.scope(:find) }


It's a little ugly, but it seems to work.

Story.popular_and_hilarious.all.should == Story.popular.hilarious.all

Monday, March 16, 2009

TheSans

The guy who developed Inconsolata namechecked TheSans
I was particularly struck by the beauty of Luc(as) de Groot's Consolas, which is his monospaced design for Microsoft's upcoming Vista release. This font, similar to his earlier TheSansMono, demonstrated clearly to me that monospaced fonts do not have to suck.


And that piqued my curiosity. After a few days of hunting, I found a source that could get me the font for less than the list price of $Ridiculous

Even though it was explicitly designed for programming, it's a little funny looking. And the zeros aren't dotted or crossed.

in VIM


in Gnome Terminal

anti-aliasing nightmare on debian

Debian mysteriously turned on font-anti-aliasing when I upgraded my laptop a few days ago. I guess that's fine, but suddenly my terminal got completely unreadable.
before


after


I thought about turning it antialiasing off -- and I still may -- but it occurred to me that I could probably do better.
I asked around, and I found a few shootouts, including Jeff Atwood's, but none for my exact setup.
The problem is, Linux/X11's font renderer isn't really ClearType. Also, different applications seem to render the same font different ways: VIM and Gnome Terminal sometimes show the same character in the same font in a dramatically different way.

Now I've got a handful of beautiful monospace fonts, but I can't seem to decide which to use. I'll post some examples here, as I get time to make screenshots.

So far, I've got:
  • Andale Mono
  • Consolas
  • Consolas
  • DejaVu Sans
  • Inconsolata
  • TheSans Mono
  • Bitstream Vera


I don't have Monoco or Pragmata, but maybe I'll find them later.

Wednesday, February 18, 2009

Rails 2.2.2 is a lemon

There's one bug that makes my life miserable in all sorts of ways. It's the Catch-22 that you often can't run rake tasks if any of your models fail to compile.
It seems to be a bit of a heisenbug:
http://rails.lighthouseapp.com/projects/8994/tickets/1548-gem-tasks-fail-when-cache_classestrue
http://rails.lighthouseapp.com/projects/8994/tickets/802-eager-load-application-classes-can-block-migration
http://www.redmine.org/issues/show/2441

I've seen it bite me:
  • trying to migrate up fields in the database, while a model was trying to call "alias" on the field

  • trying to automatically install a gem dependency, including while a model was trying to mixin a module from that gem

  • trying to run specs in a plugin when the app it was plugged into had syntax errors in a model


Gaaah.

Monday, January 19, 2009

programming languages that I still can't read:
  1. LISP (and scheme)
  2. C++ Templates

which suggests I need to take some time to really grok macros.

Saturday, January 17, 2009

debian linux: bigmem gives you highmem and you need it or you'll be missing memory

if you're running a debian system, make sure you have a bigmem kernel installed, like this one, or memory above (somewhat less than) 1GB will be ignored.

before
sudo grep -i memory /var/log/dmesg
[ 0.004000] Memory: 899224k/917504k available (1693k kernel code, 17724k reserved, 746k data, 320k init, 0k highmem)


after
sudo grep -i memory /var/log/dmesg
[ 0.004000] Memory: 2059204k/2087744k available (1834k kernel code, 27260k reserved, 788k data, 256k init, 1170240k highmem)


Now I can stop blaming firefox.

Update:
I've become convinced that this is a bug in Debian's 2.6.26 image. The previous version (2.6.24) had "highmem" (memory above 1GB) turned on even if "bigmem" (memory above 4GB) was turned off.
(I think. Someone should confirm this.)

Monday, January 12, 2009

mixed types

In scala, it's possible to mix parameterized types (e.g. TypeOne[T]) with inheritance (e.g. TypeOneTwo extends TypeOne[TypeTwo] )
but it's complicated.
Lesson learned: if it's possible to just pick one or the other (pure inheritance or pure parametrization), do so.

more on that later.

Wednesday, January 7, 2009

gij is a bad citizen

I think I've found what was going on with my scala interpreter. The debian scala package depends on gij, the GNU Interpreter for Java. THIS IS BAD. I didn't notice it get installed, but suddenly everything that called java on my system was filling up system memory, going into swap, filling up the entire swap, and crashing. I suspect that if I install a version of scala that uses the real java interpreter, it won't use 1GB of RAM to call 'hello world'.
Come on debian. Java is GPL now. Let's get out of the ghetto.

Tuesday, January 6, 2009

TO: larry drebes <ltd@janrain.com>

Larry, I think it is despicable that the same company that was responsible for shepherding the OpenID 2.0 spec is now selling a proprietary product that capitalizes on the failures of that spec. I think it is obscene that the open source libraries that your company maintains[1] are now being pitched as excessively complicated[2] so that you can sell a proprietary wrapper for them. This is a fundamental conflict of interest.

~Jesse Wolfe

Monday, December 29, 2008

this is going to be a problem

jes5199@electra:~/code/scala$ time scala hello.scala 
Hello, world!

real 0m24.380s
user 0m0.564s
sys 0m0.036s

Sunday, December 28, 2008

Flickr reverse lookup bookmarklet

flickr reverse lookup bookmarklet

If you're on a flickr jpg and you want to get to the photo's page, click this bookmarklet. It's that simple.

Friday, December 12, 2008

semicolon semicolon

On wednesday, Kim Wallmark, Arlo Belshee, and I entered a quick little programming competition at Cubespace's Coder Social. We were encouraged to pick a programming language that we weren't terribly familiar with -- most of the teams seemed to be Ruby programmers trying Python or Python programmers trying Ruby. That didn't seem like a challenge to us, so we went with F# -- fortunately Kim already had an F# IDE installed, but otherwise none of us had ever used it.
The problems were all from Project Euler, so they were the sorts of things that tend to have deeply recursive solutions. So, in that department, F# was an advantage.
F# has some unpleasant quirks, though:

Monomorphism by default


We had this function:
let fibStep (a,b) = (b,a+b)
By default, it only works on ints! It should be valid for any numeric type! It's just addition! But no, we had to label the parameters:
let fibStep (a : BigInt ,b : BigInt) = (b,a+b)

Crippled type inference


Maybe I've been spoiled by Haskell, but I just assume that if I've got type inference, I've got Hindley–Milner over the entire program. In F#, types are only inferred within the boundaries of a single function. That means more type annotations.

Recursion requires annotation


And for some reason I don't understand, by default recursion is forbidden in a function, unless you define it with the "let rec" keyword. I have no idea why.

Find the missing library


Since F# is on the CLR, it inherits some VM design smells. Where's the Bigint type? Microsoft.FSharp.Math . You know, I would have expected the F# language to have implicit access to the FSharp namespaces. Nope.

Unusual punctuation


We knew about the confused usage of ;; for end of line and ; for comma, and , for a different kind of comma. But we kept having to look up operators (for method names we had autocomplete in the IDE! but dingbats were Google's territory.) I know we got confused on: cons (::), append (@), exponent (**), mod (%).

Cryptic error messages


And when you get it wrong, the interpreter is worthless. It had a tendency to entirely fail to parse our functions, and give us line/column numbers at the end of the code, rather than at the problem spot. I can't remember what the messages we were getting said, but it sure seemed like they just said "This is wrong"

Hard to google


Several times we tried googling some common function names like "head" or "tail" or "append" and found that mixed with the keyword "F#" you get nothing but music results. Way to go, marketing wizards.

Wednesday, December 3, 2008

baby's first spammer

the wiki that I'm hosting ( pdxipedia ) got a nice annoying spam infection. Mediawiki may be the world class software behind Wikipedia, but out of the box it's spambait. We're lucky only one got in (Hi, 194.165.42.59 ! How are things in [consults GeoIP], uh, Saudi Arabia? How's the business of ... jeeze these spams seem to be total nonsense ... search engine disruption? )
Today, I signed up for Project Honeypot, which keeps a blacklist of spammers. There's a plugin for Mediawiki that redirects known spammers away, and it's also supposed to have invisible honeypot links to ensnare unknown robots. The link generation is buggy though, so I'm not brimming with confidence about the whole thing.
So I wrote a script that runs through my Lighttpd access.log files (it probably would work for apache, too), and checks IPs of all the recent visitors against the Project Honeypot blacklist. If there's a match, I use iptables to block that IP. I've got it running once a minute -- that's still enough time for a fast bot to do some damage -- so it's not really going to be a complete solution, but it could potentially prevent denial-of-service caused by a persistent bot.

Tuesday, November 25, 2008

I can't yet call it Jes' Law

Has this been said before?
When you're working with more than one tool, the worst tool will use up the most of your time


I've seen this both at work and on some personal projects lately.

  • At work, we're adding an API to a PHP application so that we can control it from Ruby on Rails -- the API layer is supposed to be thin and clean, so we can do all of the complicated logic in Rails. Even so -- I've spent 90% of my time in PHP-land for the last month.

  • I just threw together a toy at http://jes5199.com/sunrise/ . I needed a calculator that could predict sunrises, and the first thing I found was a CPAN module DateTime::Event::Sunrise. But suddenly my light little Sinatra and Javascript app includes a nightmarish perl script and a patched version of the Sunrise library, since the package is abandoned and mildly broken. I spent easily six hours in perl, compared to two hours doing everything else. And I'm still not certain that there aren't edge cases where a sunrise gets skipped.


  • Corollary:
    If a job has good parts and bad parts, the bad parts will dwarf the good.

    Wednesday, November 19, 2008

    first post

    I want to talk about
    • new programming languages

    • code tool practices

    • disposable software (software as performance art)

    • general ranting