Let’s write a compiler in rust: pt1

In the tried and true tradition of building esoteric things to deal with
brainfuck, nelhage nerdsniped me into writing a brainfuck compiler
in rust.

I’m gunna gloss over tons of stuff, and only write about the interesting parts.
I’m also not going to actually walk through the code as I wrote it because it
was and is incredibly sketchy, but it’s better seperated now so we’re going to
look at master (at time of writing).

Writing a parser

Rust makes this comically simple.

We define a recursive enum containing all the opcodes, and a Vec to hold the
contents of any loops:


#[deriving(Show)] pub enum OpCode {
Lshift,
Rshift,
Putc,
Getc,
Inc,
Dec,
Loop(Vec<OpCode>),
}

By deriving Show we’ll be able to use format!, println! and friends at
various points of debugging and get something plausible ish.

Our actual parser is just about as simple. I won’t inline the
code, but it should read pretty simply.

We create a mutable vec to hold our actual program, and a loop_stack to hold
the contents of each nested loop, inserting those loops into it’s parent each
time we enounter a closing bracket. This also makes it simple to test for
unbalanced brackets.

This then lets us return the Program. Using Option was left as an escape
hatch (unbalanced braces could be caught, as could the file errors, but for now
failing is reasonable since it’s not exactly “production ready”).

Next time, the evaluator.

Posted in Articles | Tagged , , | Leave a comment

Programming is literally the hardest thing

A conversation on the twitter really got me thinking, both about
programming as a profession, the human obsession with winning at everything (Up
to and including failing at life), and much though it kills me to say this,
privilege.

The blog post that started it all is interesting- it begins by
saying that the authors friends who have a more physical job than he does, and
he goes on to explain why programming is so awful.

It’s not that I don’t see the point of his post. Programming really is awful.
These past few weeks have been among the most harrowing and demoralising that I
can remember, both in terms of invested effort and in losing faith in the tools
that we trust day to day. I enjoy ranting about what a hilarious shitshow
software is well above the mean for people who do what I do.

That said though- it’s worth maintaining some modicum of perspective. Ignoring
everything else, programming is innately safe. No job is without its risks,
but comparing the outcome of RSI to the average workplace injury on a
construction site I would wager skews way in favour of the construction site
for both frequency and severity. (As an aside, where the hell would I find
stats for this?).

Michael raised a valid point about mental health, but I totally fail to see how
this relates to computer science. If you’re in a workplace that’s causing you
mental or emotional harm you should seek help, immediately. My intuition
suggests that you stand much better chances of actually receiving it if you’re
in the typically privileged shoes of your average software engineer.

My intent with this post isn’t to victim blame or to tell anyone miserable in
their job (or just needing a space online to vent) to ‘harden up’. I do really
stop to wonder though, when I read about the number of studies showing that
using a male name improves chances of success in the
workplace and academia whether taking to a privileged soapbox to complain how
hard it is after you get there without a handicap might be missing the bigger
picture.

Posted in psych0tik News | 3 Comments

Heartbleed, psych0tik edition

As per the rest of the internet, our collective jaws fell through the floor when Heartbleed was disclosed.

First and foremost- our IRC server was not vulnerable. At present, the only live IRC node is magikarp, owned and run my carbon, and running gnutls. OpenSSL based *clients* on the other hand, could plausibly have been compromised.

With that said, the first order of business once patching was in order was to develop a working exploit. Given that the internet has had a few days to patch, and that numerous other exploits are now public anyway, I’m releasing mine.

Given the time sensitive nature of the situation (We needed a working PoC to quickly enumerate internal services at $dayjob), I took the quick and dirty approach, rather than developing from scratch I produced a patched libssl that when linked against turns any SSL client into a working heartbleed vector.

You can find it at https://github.com/richo/openssl. For obvious reasons I would recommend building without shared object support, and not installing this anywhere.

Posted in psych0tik News | Leave a comment

Caffeine napping for glorious success

Toward the end of my biphasic experiment I started experimenting with caffeine napping- I don’t remember where I originally got the idea, but there are plenty of plausible sounding posts on the internets.

Basically, the routine is simple. Wait till you’re tired, have a shot of espresso and immediately get 15-20 mins sleep. I’ve found it borderline impossible to pull off if you’re not tired, although I find it difficult to sleep without impetus anyway. I’m not convinced this is something I could do longterm, but it’s proving to be significantly more convenient to slot in around my work/life balancing act than the 45 min daily naps I was taking during the biphasic experiment.

Posted in Articles | Tagged , | Leave a comment

Choon

For the last couple of days, I’ve been hacking on something shiny for pebble.

Being able to control music on my phone is cool, but I often listen to music on my laptop while wandering around the house, and I wanted to be able to control that too. Enter choon.

If you want to use it, you totally can, but right now it’s a pain to setup. I’ll do my best to explain how though.

First of all, install the pebble app. It uses httpebble, so bear in mind that you’ll need to httpebble app for your phone, and if you already have an app that uses it, it will clobber it due to the uuid collision.

Then, you’ll need to install the desktop app. Which is currently only for OSX, but the protocol is dead simple so if you want a hand writing one for win32 or linux reach out to me. If I get bored enough I’ll write one sooner or later anyway. You’ll need to get the bluetooth address of your pebble (Settings -> About -> BT address) and save it without the colons in your home directory as

.choon

.

Currently, Choon assumes you’re using iTunes. Again, I’m more than happy to write bindings for other players, but I need to know what you’re using.

Start everything, and press the middle button on your pebble with choon active. There’s no ui, but you should hear music within a few seconds. If the watch vibrates there was an error transmitting the message, try again in a few seconds.

Everything is open source: watchapp, desktop app, backend. There’s currently a backend running on app.choon.io, which is free to use.

Feel free to file issues on any of those repos if you run into issues.

Posted in psych0tik News | 10 Comments

IRC Upgrades (and downtime) … [and other issues]

The IRC has been a bit dodgy the week due to some updates we’ve been working to push out.  As part of our irregular upgrade cycles, I’ve been working on getting Storm re-built and back online.  A large part of this process involved adding Storm back to the IRC network.

Following psych0tik standard operating procedure, this was procrastinated and when I finally got around to doing it, we discovered magikarp had file system corruption and required a reboot and fsck.  With the magikarp splashing around ineffectively, we pointed irc.psych0tik.net to (a mostly unconfigured) Storm.  Shortly there after, we brought magikarp back online, hashed out the final issues with linking, and connected the two.

During magikarp’s reboot, our services database was corrupted and due to lack of backups (lazy.jpg), we’ve had to revert back to a version from about 6 months ago.  We apologize for this inconvenience.

With that all said, we do have a shiny new IRC node to connect to.  Now that Storm is back and functional, I’ll be working to restore some of the services that have been absent for the last few months.  This will include proxyElite and our GoogleSharing proxy.

Our recommended IRC domain, irc.psych0tik.net, has been re-pointed at magikarp and users who wish to use a US-based server (or otherwise desire to use Storm instead) should connect directly to storm.psych0tik.net.  As always, you’ll need to use SSL on port 6697 is required.

Posted in psych0tik News | Tagged , , | Leave a comment