Archive for March, 2010

Inelegant Combobulation

Wednesday, March 31st, 2010

Here’s the code:

(define (in-forum-thread-descriptions forum-number)
  (let ([chain (list capture-text
                     'spacer
                     (both (is-tag #"a")
                           (has-class #"thread_title")
                           (has-attr-match #"href" #px#"showthread\\.php\\?threadid=(\\d+)")))]
        [combiners (list text-combiner car)])
    (in-match-and-combine chain combiners (get-forum-html-stacks forum-number))))

And here’s the result:

> (for ([desc (in-forum-thread-descriptions 202)])
    (printf "~a: ~a\n" (cadr desc) (car desc)))
2779598: Ask General Programming Questions Not Worth Their Own Thread
2836504: Cavern of Cobol FAQ (Read this first)
3048157: iPhone Development Megathread
3161913: WordPress - Development, Themes, Plugins.
2672629: SELECT * FROM Questions WHERE Type = 'Stupid'
2773485: C/C++ Programming Questions Not Worth Their Own Thread
3286714: "Run As Administrator" on Win2008 getting in the way of SQL SSIS jobs?
3263809: Another How Much Money Should I Be Making Thread
3283309: Ada Lovelace Day
2841382: Post screenshots of stuff you're working on!
2675400: Python information and short questions megathread.
2802621: <?PHP questions that don\\'t need their own thread ?>
3246449: Goons for Hire: Get your Developers here
3286440: Powershell
2803713: Coding horrors: post the code that makes you laugh (or cry)
3070034: Javascript questions which don't deserve their own thread.
2692947: Game Development Megathread
2262300: .Net Questions Megathread Part 2
2790475: Django Web Framework: The 'D' is silent dumbass
2718078: Web Design/Development Small Questions - Rev Holy Grail
3286273: Planning/Building Family Websites: What's this family tree doing in my web?
2780384: Java questions which don't deserve their own thread, yet.
3108969: a Vim thread
2662688: Xcode and Cocoa Megathread
2664804: The Perl Short Questions Megathread: executable line noise
3281048: When to (and not to) use goto;
2897255: 3D graphics questions that do not deserve their own thread (OpenGL / Dx10)
3113983: Version Control Questions Megathread (SVN / git / whatever else)
2585949: Ruby on Rails Love-In
2385157: Flash Questions Megathread

PLT Scheme sequences are annoying

Tuesday, March 30th, 2010

I don’t really know much about PLT Scheme sequences, but they seem to be fairly warty. First of all, consuming a sequence may destroy the sequence (at least if you use in-generator to make one). This is annoying, but I suppose it could also be regarded as a dangerous feature. Also, there’s no easy way (as far as I can tell) to convert sequences to lists. All I can find is

(for/list ([x seq])
  x)

Generators are pretty nice, and in-generator is okay, you can make sequences like this:

(define (in-filter pred seq)
  (in-generator (for ([x seq])
                  (when (pred x)
                    (yield x)))))

Right now, if you try to enumerate a sequence defined by uses of in-generator that have side-effects, you end up eating the sequence, so that subsequent enumerations nonchalantly tell you that the sequence has no elements. I’ll have to make a version of in-generator that throws an exception on subsequent enumerations. Here’s a function that would benefit:

(define (in-matches pattern port)
  (in-generator (let loop ()
                  (let ([matches (regexp-match pattern port)])
                    (when matches
                      (yield matches)
                      (loop))))))

This function consumes the port. It either needs to use (in-memo (in-generator ...)) or it needs to use in-destructive, which would be the exception-throwing generator I would have to implement.

Here’s my implementation of in-memo, for what it’s worth.

;;; Makes a memoized version of the sequence, which you can iterate
;;; through without destroying the sequence.
(define (in-memo seq)
  (let-values ([(has-next? next!) (sequence-generate)])
    (letrec ([next-node (λ () (if (has-next?)
                                (cons (next!) (delay (next-node)))
                                '()))])
      (let ([stream-head (delay (next-node))])
        (in-generator (let loop ([forced-stream (force stream-head)])
                        (when (not (null? forced-stream))
                          (yield (car forced-stream))
                          (loop (force (cdr forced-stream))))))))))

I don’t know, that seems fairly ugly.

--------------------------------
Side discussion below this point
--------------------------------

Sometimes I get annoyed by Scheme’s lack of laziness. I’m used to Haskell’s laziness, you see. For example, you can’t implement Data.Function.on in Scheme — not in the same way — because something like ((&&) `on` f) wouldn’t short-circuit. I wanted short-circuiting behavior, and the only way to do it was to define a macro…

(define-syntax-rule (on binary-op f) (λ (x y) (binary-op (f x) (f y))))

This is much uglier. Scheme is generally uglier, but more comely, than Haskell.

Slight HTML “Parsing” Adjustments

Monday, March 29th, 2010

I made some slight adjustments to the HTML Parsing.

> (define txt (string-append "<!DOCTYPE HTML><html lang=\"en\"><head><title>"
                             "Hello</title>  </head><body>text</body></html>"))
> (map (λ (stack) (matches-predicate-chain stack (list 'spacer (both (is-tag "html")
                                                                     (has-attr-value "lang" "en")))))
       (get-html-stacks (get-html-segments txt)))
(#f #t #t #t #t #t #t #t #t #t #t #f)
> (map (λ (stack) (matches-predicate-chain stack (list 'spacer (both (is-tag "html")
                                                                     (has-attr-value "lang" "foo")))))
       (get-html-stacks (get-html-segments txt)))
(#f #f #f #f #f #f #f #f #f #f #f #f)

Now attributes can be reasoned with. And the parser now generates stacks with top nodes on the top — with text nodes on top, and so on.

Minimalist HTML “Parsing”

Sunday, March 28th, 2010

I’ve decided to go with my own cheap HTML “parser.” Right now there are just some functions for cutting an HTML document into tags and text node substrings, and then code for building a stacks of start tags that lie under each substring. There’s also a primitive matcher that matches search expressions that check for a tag name. For example, here we mark as #t the substrings <title> and Hello, because they’re directly atop the TITLE element, followed by some other containing elements, followed by the HTML element.

> (define txt (string-append "<!DOCTYPE HTML><html lang=\"en\"><head><title>"
                             "Hello</title>  </head><body>text</body></html>"))
> (map (λ (s) (matches-predicate-chain s (list (is-tag "title")
                                               'spacer
                                               (is-tag "html"))))
       (get-html-stacks (get-html-segments txt)))
(#f #f #f #t #t #f #f #f #f #f #f #f)

It looks like I beat my 24-hour posting time limit by 6 minutes.

Goon Project

Saturday, March 27th, 2010

I’m going to break from my habit of scheduling most posts at 5:00 AM and instead intend to go for a more brutal pattern, one of posting at least once in any 24 hour period. I’ve decided to start a little project to make a little iPhone app that I have wished the existence of for a little period of time. It’s going to be the usual sort of forum reader software like “Forums” or “Forum Pro” or what have you, except that it won’t suck, it’ll use a proxy server with a relatively custom protocol (probably just gzipped json or equivalent), for the purpose of lowering bandwidth and for the purpose of being able to add support for new forums that use weird skins or structures whenever it’s needed, so that users can complain and have their problems resolved instead of having to give up or wait for an update. (And I guess I better check if that’s allowed, according to the app store policies.)

My postings will be about what I’ve done in the previous sub-24-hour period. This will force me to actually get stuff done.

I have made my first decision about this project already.  I’m going to use PLT Scheme for the server end.  Part of the reason is that I just read this comment by boskone on Hacker News, basically saying,

IMHO, there are currently only 2 top tier active hotspots where the cool theoretical meets with the practical and usable in programming language theory, the Haskell and PLT ecospheres.

Well that’s very sweet.  Anyway, I think it deserves a leap of faith, especially since, if I ever decide that I really want a statically typed language, I can just go with #lang typed-scheme.  So I will try it and report back on my trials and tribble-ations with PLT Scheme.

Edit: tribble-ations? Sigh.

Fuck!

Saturday, March 27th, 2010

Every time I use Clojure,
I want to use Scala.
Every time I use Scala,
I want to use Clojure.

Why I Don’t Write Science Fiction

Friday, March 26th, 2010

Every once in a while, I get this idea that I could be this great science fiction author.  I’ll write a story that follows the hero’s journey, where the hero is my self-insertion: a witty genius with a sexy body, l33t hacker skills, and backdoors into every computer system this side of the equator.

So then what happens?  I begin writing, and finish a few pages.  Yay.  But then some Vernor Vinge novel comes along and says, “You haven’t read me yet!  You haven’t read me yet!  La de da de daaaa!  La de da de daaaa!” And then I start to read it and I’m all like, “How could I possibly think I was at a high enough caliber to write science fiction?”  Vernor Vinge is the kind of author who just makes you feel bad for even considering writing.

Lately, I’ve been reading Rainbows End, and now I’m starting to feel the shame again. I’ve only read a few pages, and I can just feel the future buzzing on the horizon.

So that’s that. I had to bloge something today. I guess I’ll write a full-blown review of it at some point in time.

Updating Theme

Wednesday, March 24th, 2010

I’ve decided to update the theme from something less matrixy to something more computery and 1990′s in nature.  I will aim for something that captures the utilitarian soul of computing and information organization.  I will now proceed to edit the theme.

I suppose I will update this post as I make changes to the theme.

16:51 PT – Removing all references to colors and background colors, except for special things like calendar css (whatever that is for) and htmlize.

16:56 – Removing all font-family settings.

17:00 – Removing all the weird wp-calendar CSS, wtf is that, I don’t want a calendar.

17:01 – Removing all border stylings.  And removed weird caption css.  And removed weird <hr> css.

17:05 – Removed #pagewrap div.

17:08 – Removed anal misc tags/classes’ css like blockquote, abbrev

17:10 – Removed peculiar post <hr> styling.

17:12 – Removed all font css properties.

17:13 – Removed .category-serious css.

17:15 – Removed line-height and text-decoration css.

17:17 – Set background color to an ugly gray.  Too ugly.  Specified link colors to be blue and purple, explicitly.

17:20 – Removed virtually all of the typography CSS.  A little too much.

17:22 – Lightened up the background color, and removed a bunch of margin/padding fascism… wrecking the layout in the process!

17:24 – Removed some before & after CSS.

17:26 – Removed most #sidebar CSS except the width specifier.

17:37 – Okay I edited something and now the change isn’t showing. F this.

21:43 – Adjusted CSS to work properly, got columns working again, but with the side column on the left side.

9:42 – Updated htmlize theme to something ugly but black on gray.

9:48 – Changed left column positioning mechanism, positioned left column to top left of page and made header centered with respect to the content column below.  Made the content column fit the remaining width of the page.

The Right To Be Invisible

Monday, March 22nd, 2010

In a previous post, I posted about some fun ways to be paranoid.  I’m not going to link directly to it, because then you’ll have to find it yourself, which means you’ll see more of my blog.  Anyway, with this latest healthcare bill being passed and the latest census being taken, you might ask…. Do you have the right to be invisible?

A long time ago, if you wanted to be invisible, you just had to get a cabin in the woods and live in it.  Then you had to not get sick and not die.  It was easy.  You could have kids, and nobody would know you had kids!  Except your wife.  But you could kill her and get away with it.  You were free!

And that’s pretty much how human rights worked.  If you wanted to explain human rights, you could just measure the amount of freedom you had.  Actually, that’s a little immature.  You get freedom and privacy.  Privacy counts, too.

Of course, now we’re even more free.  We have automobiles and can travel the world!  But you’re more observable.  With computers nowadays, the government can track you.  They can track where you drive with license-plate recognizing cameras.  They can track where you live.  They can track everything about you.  You won’t be truly free until you join a seasteading community — but then if you want enough reputation to be permitted to attach to any of the cool communities, you’ll need to emit a public persona.  You can’t be completely private.  And of course they couldn’t track you by satellite because your personal seasteading pod would be submersible.

Ideally, you want to have maximum freedom and maximum invisibility.  Like God.  Except that maybe you’ll actually choose to be observable from time to time.  If that’s your thing.

To be unobservable in this modern society, your only hope is to basically put a backdoor in all government systems.  You need a Ken Thomspon-style backdoor in all the assemblers, compilers, and what-have-you that is intelligent enough to insert itself into anything.  You need your own army of artificially intelligent agents to wipe out any trace of you from all security systems.  You need an army of intelligent autonomous robots to physically break into computer systems that haven’t been backdoored or aren’t connected to any networks so that you can remove your physical traces from them.

Someday, somebody’s going to become the first person to build their own personal army of autonomous agents, connected to their brains via neuroelectrical interlink, and then he’ll go invisible, and then he’ll secretly rule the world.  The singularity will not be televised.

Practical Sociopathy

Sunday, March 21st, 2010

Suppose you’re evil.  Well, ha ha, okay, you don’t have to pretend, I get it.  Yes, that was funny.

Or was it?

Anyway, suppose you’re evil.  You like causing misery in others.  You’re not selfish — in fact, when it comes to your self-control and the desires you have, you’re practically a high-functioning Buddhist.  Except, of course, that you want to cause as much human misery as you possibly can.

Being the kind of lifehacker-reading sociopath that is so cliché nowadays, you want to consider the following question: What’s the optimal way to cause human misery?  Let’s consider some ways of causing human misery, trying to improve on them each time.

Walking Around, Kicking People

Walking around and kicking people is one way to cause misery.  People feel hurt after you kick them.  A few people might fall over, if you kick them hard or if you kick them while you’re off-balance.  If you’re lucky, a few will hid their head on a sharp corner or fall on a knife and die.  However, you’ll soon be arrested or beaten up.  You’ll only get to kick a small number of people.

Shooting People From a Clock Tower

This is a more famous method, but still, you’ll only cause a small amount of human misery.  The people you do kill will die quickly, at most surviving a week before death.  Then there’s the relatives and the rest of the school, who will feel miserable for some period of time, but in this era of video games, not even that will last.

Throwing A Game

Suppose it’s the NCAA final.  Your team is down by a point, and there’s five seconds on the clock.  The ball comes loose!  You grab it, and dribble down the court.  There’s no defenders in front of you.  You race up to the basket, jump up for an easy dunk, and… throw the ball into the stands.  Game over.  Your team loses.  Everybody is angry about the outcome of the game.  The winners aren’t happy.  The losers aren’t happy.  Everybody wants to know why you did it.  You answer, “I did it for the lulz.”  A lot more people are affected this than the few victims of a clock tower shooting.

Torture Somebody For A Decade

Quick deaths and brief peculiar sports incidents aren’t particularly miserable.  The most miserable sort of thing you can do is to kidnap somebody, put them in your basement dungeon, and torture them, every day.  Build a machine that automatically tortures them.  Remove some body parts.  Put itching powder on them.  Make them watch the Wide World of Sports.  A decade of pain is much more than fourteen quick deaths’ worth of misery.  The worst best part is when you send the videotape to their family.

Oh, hello FBI.  I don’t have a basement.

Become A Politician, Get Dumb Laws Passed

Nobody has more of an ability to cause misery than politicians.  I this day and age of countries with hundreds of millions of citizens, a politician can pull all sorts of misery-inducing business, without even starting a war!  Even the slight marginal damage caused by not doing as good a job as you possibly can will be worse than torturing somebody for a decade.

Become President, Nuke China

Think of all the radiation burns.

Discover Penicillin, Outlaw Abortion

The best way to cause human misery is to save lives.  The more lives you save, the faster the population grows.  The faster the population grows, the more people there are.  The more people there are, the more misery there is.  If only a million people were alive today, there would only be a million people’s worth of misery.  If a billion people are alive, that’s a thousand times as much misery!  A true sociopath tries to cure diseases, solve international conflicts through negotiation, prevent the spread of birth control, oppose women’s rights, and invent affordable spacecraft and terraforming technology.