The random rantings of a concerned programmer.

(Untitled)

June 28th, 2009 | Category: Random

Oh man, I brewed some beer today. Made the wort for a nice Hefeweizen — it’ll be 2-3 weeks before I bottle it, and another 2-3 weeks before the bottles are drinkable. Have 5 gallons of the shit — about 48 bottles worth. Moreover, brewing beer is surprisingly easy; I might have to get carried away with it :3

On the Haskell side, I wrote a TCP multiplexer. It’s a toy, but I like doing random things with MUDs and shit and it’s really useful for that kind of stuff (ie, writing bots etc). The code is written in a very Erlang style, calling forkIO twice for each client and using a bunch of STM channels to pass messages around. Probably a better way to do it but this was the most coherent in my mind.

Also, the mux function is an unfortunate mess etc. lol haskell.

No comments

(Untitled)

June 27th, 2009 | Category: Random

I mentioned (discreetly) the other day that I had written an Omegle client library in Haskell. After working out some kinks yesterday and this morning, I now have a simple CLI Omegle app which lets you chat with people without using a browser. Wrote the CLI app as a test of the client library but etc, probably not going to do anything else with it.

  • WWW.Omegle
  • WWW.Omegle.Client
  • WWW.Omegle.TTY

Was pretty fun to implement. The client library makes use of the StateT monad transformer (easy examples) to wrap the Omegle state (specifically, the Omegle ID). The TTY thing uses STM for inter-thread communication. So, despite the fact that I’m probably never going to use it, it was a fun foray into some fun Haskell features.

3 comments

(Untitled)

June 26th, 2009 | Category: Random

Well 4scrape is back up, dicks, etc.

Yesterday I hacked out some code which I cleaned up tonight. Not going to bother explaining what it is — just going to link it. It’s pretty obvious what it’s used for (LOL). Probably going to rig up something so that renders through hscolor instead of just being served as text/plain; will append the source to this post once it’s ready.

I’m completely reorganizing my code and shit. Before, I had a ~/dev/ which contained a directory for each project I worked on. There was no place for common code, so I ended up having multiple copies of shitloads of files everywhere. That’s shit. It’s a nightmare to maintain — makes it impossible to find anything and makes starting new projects a fucking hassle.

Instead, this time I’m keeping everything (at least, the Haskell stuff) in a single hierarchical directory and keeping it all backed up in a remote repository (a jail on Kirakishou). That way, starting a new project (ie, WWW.HsColorizer) is really easy and doesn’t become a mess.

etc. meh.

Update: Finished writing a FastCGI script which runs requested files through HsColourize before serving. The source can be viewed through itself here. Huzzah. (though I still need to tweak the hell out of the default CSS shit so it isn’t so bright fuck yeah got my darkies up in here).

3 comments

lawds animu bullshit

June 08th, 2009 | Category: Random

One of the many things I hate is having to keep up to date on downloading animu bullshit. I want to be able to come home from work and have something say “OH HEY THE LATEST EPISODE OF EDEN IS OUT AND OH BTW I ALREADY DOWNLOADED IT FOR YOU” so I can focus on more important things like taking off my ID badge and whipping my dick out.

I’m sure I’ve ranted about wanting a system before so I’ll spare the gory details. I’ve got the first half done — it pulls the RSS feed from Baka-Updates (since they publish in an easily parseable format1) then dumps any new entries into an Sqlite3 database. I’m half-tempted to scrape all the torrent data off Baka-Updates but I’ve found a lot of that shit gets out of date pretty fast (trackers change, takedowns, etc).

Also, fuck the goddamn Gist plugin for not displaying a vertical scrollbar and just shitting all over the page layout in general. [view source]

5907

Just two components left to write — a utility to maintain a list of series to track (and drop the .torrent file into rtorrent‘s watch folder) and another utility ala xeyes that lets me know when the shit is done in a reasonable manner2.

Also, I’m going to write my own fucking Gist WordPress plugin that fucking proxies the cross-domain request and buffers the result so the fucking JavaScript doesn’t have to use a slow-as-fuck JSONP request to GitHub’s slow-as-fuck services.


References:
[1] parse_title = head . (=~ "\\[([^\\]+)\\](.*) ([0-9]+)?(v([0-9]+))?")
[2] dicks everywhere

6 comments

Shit Yaml Parser with Parsec

April 20th, 2009 | Category: Random

Hurr, so I actually spent the night going through the Parsec documentation and implemented the first half of a shitty Yaml parser (doesn’t meet spec but who the fuck cares — it’s 100x better than the shit regexes I was using before). Still need to instance Read and Show properly (and then Data as well, and toYml/fromYml to marshall values around). But it seems to work so far.

Honestly, I couldn’t figure out most of Parsec’s combinators (specifically, the Token parsers) because they need a tokenizer definition or something and I was like “cbf’d”, so I only used the primitive constructs. Additionally, for some reason, I couldn’t get between to work — though I can’t fucking figure out what I couldn’t understand with it because it’s working now. But my re-implementation was kind of amusing –

pbetween o c p = do
    o
    v <- p
    c
    return v

I also ended up implementing a combinator to concatenate Parser results (inb4 someone optimizes these with Arrows) --

pjoin f p1 p2 = do
    v1 <- p1
    v2 <- p2
    return $ f v1 v2

(<++>) = pjoin (++)

I guess I should stop ranting and be a bit more concrete about why Parsec is cool. Parsec is a combinator-based parsing framework, so instead of mucking around with specially-formatted lists of regular expressions (lex, I'm looking at you), you bind combinators together to describe the parser.

Parsec comes with a bunch of commonly used combinators like string, char and digit which are pretty bread-and-butter (though you can use satisfy, which takes an arbitrary Char -> Bool to do pretty much any low-level bullshit).

So let's say you wanted to parse an integer --

{- Helper function which returns "-" if it's there -}
pneg = option "" (string "-")

{- Parses an integer out of the stream -}
yvInteger :: Parser YamlValue
yvInteger = do
    {- bind i to the negative sign (if it exists) concatenated with [0-9]+ -}
    i <- pneg <++> many1 digit
    return $ YInteger $ read i

Excessively verbose (noting discretely that that performs both lexing and parsing -- Parsec operates simply on streams of characters), but awesome.

Taking it a step further, the parser for lists isn't that bad either --

{- parse out lists like [1,"hello",1.45] -}
yvList :: Parser YamlValue
yvList =
    {- make a list of the things between '[' and ']' which are separated by ',' -}
    liftM YList $ btw $ sepBy yvValue sep
    where
        {- takes a parser and wraps '[' ']' around it's expected input -}
        btw = between (char '[') (char ']')
        {- just a separator -}
        sep = char ','

And then I was going to show the yvObject function which keeps track of state (indentation for nested objects etc) but I'm too lazy to type any more; would be better for me to just type up some Haddock to refer to later. The full source is on github somewhere but they're taking forever to process my push so dicks etc.

10 comments

Next Page »