Comments:"How Our Terminal-Friendly Jobs Page Works - Cue Engineering Blog"
URL:http://tech.cueup.com/blog/2013/03/06/how-our-terminal-friendly-jobs-page-works/
Yesterday we submitted a jobs posting on Hacker News titled "curl -L cueup.com/jobs". Typing that command into your terminal leads to a scrolling terminal-friendly version of our jobs page.
A few people were curious how it it's done, so here's a quick explanation. The experience relies on the combination of two techniques: ANSI escaping and buffered output.
Most people use ANSI escape codes for simple coloring of their terminal, but (perhaps thankfully), its more advanced features are rarely used. Try this in your terminal:
1 printf "\x1b[4m\x1b[5m\x1b[44mHello World\x1b[0m\n"(There are many libraries that help with formatting ANSI escape codes. We used the termcolor Python module.)
After the initial "ACCESS GRANTED" message is shown, we slowly buffer output to your screen to mimic the feel of downloading a page on a slow internet connection. We use Tornado to serve our front-end which makes the process of buffering output pleasant to write.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class CurlJobsPageHandler(tornado.web.RequestHandler) """Renders the cURL jobs page""" TICK = 0.2 @tornado.web.asynchronous @tornado.gen.engine def get(self): text = colorMarkdown(htmlToMarkdown('jobs.html')) textParts = ['%s\n' % x for x in text.splitlines()] for part in textParts: self.write(part) yield tornado.gen.Task(self.flush) yield tornado.gen.Task(ioloop.sleep, random.uniform(max(tick - 0.10, 0.01), self.TICK)) self.finish()We hope you enjoyed our jobs page! When we're not trying to find new ways to catch your attention, we work on some pretty interesting technical challenges as part of our job. If you're excited about things like entity extraction, distributed search, mobile performance or ANSI escaping (just kidding - mostly) send us an email at jobs+curl@cueup.com.