«
  • An Example Dropwizard Application with Guice for Dependency Injection

    Dependency injection is a tremendously useful design pattern. From my experience the direct benefits of this pattern are almost entirely realized as a reduction in the cost of building and maintaining good unit test coverage. Being able to swap out mocks and real instances or values very easily makes the creation of test suites a breeze in comparison to some of the alternatives. All the other benefits derived over the long time largely arise from having a far more comprehensive and maintainable set of tests, since the development team were able to do more in the time allotted. There are countless dependency injection frameworks in the Java ecosystem, but here I'll look at Guice. It is lightweight enough to drop into most application ...

    Read more »

  • PhantomJS Has Many Uses, But Functional Testing Isn't One of Them

    PhantomJS is a comparatively lightweight headless web browser built on WebKit. When it comes to rendering and interacting with web pages it does everything that any other full-featured browser does with the exception of providing a graphical user interface. You can install it via NPM, meaning that for Node.js ecosystem developers is easy to put PhantomJS in place on build, test, and deployment servers even in more restricted environments. You control PhantomJS either directly via a Javascript API or through a WebDriver interface such as that used by Selenium. So what can you do with a web browser that has no graphical user interface? Take Screenshots PhantomJS is fully rendering pages under the hood, so the results can be exported as ...

    Read more »

  • Run NPM Install on All Subdirectories Containing Packages

    Let us say that you have inherited an application deployment consisting of a directory tree containing multiple Node.js packages in various scattered locations. As a part of the setup you want to run npm install for each package individually, but the packages and locations have varied over time in the past and will continue to do so in the future. So you want to write a single script now that will walk through the directory tree, identify Node.js packages, and run the NPM installation where needed. Thus even if packages move around the script will not need any further update. The first tool to reach for in this sort of situation is some combination of find to identify package.json files followed by piping the resulting list through ...

    Read more »

  • Filenames that Alphanumerically Sort by Descending Timestamp

    The professional life of a programmer consists of an endless series of small trials that in a sane world would never exist. For example, finding oneself needing to generate filenames that sort in descending order by file modification timestamp. Why, oh why, would anyone ever be stuck with a file listing technology that doesn't allow the user to simply specify a sort by that timestamp? This does actually happen, however, I'm sad to say. It is trivial to create a filename format that sorts by ascending timestamp: anything like YYYY-MM-DD-HH-SS will work just fine. Then your file listing technology should have some simple way to reverse that list. What if it doesn't, however? Woe is you. For the sake of never again repeating the short ...

    Read more »

  • Practice Defensive Javascript: Assume Blocking of Third Party Resources

    I, being basically sensible and lacking any patience for the indignities that other people consistently try to force upon me in the name of their outdated business models, use a small array of browser add-ons that efficiently block near all trackers and ads. I have little patience for the idea that I should be donning a hair shirt and suffering because various entities can't figure out how to apply basic ransom and donation business models to their provision of content to the world. This is entirely as an aside to the thrust of this post, but here is news for you: if you are in the business of arranging bits into a specific order and then propagating that arrangement for profit, then whether you like it or not you are in fact running some ...

    Read more »

  • Progressive Lenses and Large Monitors Do Not Play Well Together

    Age chews up the eyes. If you wear glasses then at some point, on roughly the same timeline as noticeable graying starts in on your hair, you are going to develop the need for different prescriptions for computer use versus other activities. You'll notice because of a growing eye strain while coding, and eventually that will drive you to visit an optician. After sticking you in front of eye charts, shining lights at you, and so forth, that individual will no doubt try to sell you on a set of progressive lenses. When dealing with the need for different lenses for close and distance vision there are three options: firstly two different pairs of glasses that you swap out as needed, secondly bifocals, and thirdly progressive lenses. A ...

    Read more »

  • Varnish 4.0: Allow Clients to Specify Cache TTL

    Varnish is an in-memory cache tailored for use with HTTP servers. Perhaps appropriately for such a narrow usage, the Varnish Configuration Language (VCL) used to specify server behavior is opinionated and restricted in its structure. While you can always drop down into writing C code sections inside VCL documents when you want to do something complicated, that is rarely a good plan unless you know exactly what you are doing. It requires a good understanding of the Varnish internals, and C code is always going to be more fragile than simply using the VCL as it is written. So if you must create something out of the ordinary, it is worth spending a little time to see if you can twist the VCL into accomplishing your goal. For me, a recent ...

    Read more »

  • How to Politely Download All English Language Text Format Files from Project Gutenberg

    There are plenty of projects that can make good use of a large assembly of written works in a specific language. Training neural networks, testing natural language processing, use of Markov chains for generating content, and so on and so forth. Project Gutenberg is a repository of some 46,000 texts in various languages that are unencumbered by copyright, so their use in any project should be safe enough from the intellectual property annoyances that plague the world these days. The idea that anyone can actually own an arrangement of data is both ridiculous and outrageous, but those who can successfully use the apparatus of government for the purposes of rent seeking on the back of this assertion are unlikely to stop any time soon. So it ...

    Read more »

  • Four Word Phrase: Pseudorandom Generation of Word Lists from a Dictionary

    The ideal password is impractical for an attacker to guess, but nonetheless easy to remember. Any random sufficiently long set of characters will satisfy the first criterion, but "sufficiently long" is well past the point of easy recollection these days, and the needed length will only grow with time as the processing power available to attackers continues to increase. Choices such as your birth date or a single dictionary word with a few strategic alterations or additions are easy to remember, but are also easily bypassed. A compromise position is a non-grammatical passphrase: a set of four or five dictionary words selected more or less at random. This is weaker than a completely random string of the same length, but well beyond the ...

    Read more »

  • Managing HAProxy Configuration When Your Server May or May Not be Behind an SSL-Terminating Proxy

    I'm strongly in favor of consistent environments for development and deployment. Your development setup should be as similar as possible to the final production deployment. Obviously it cannot be exactly the same, since access to production APIs and alteration of production data is usually out of the question, but never forget that every point of difference between development and deployment environments invites bugs and misunderstandings. What to do when it is impractical to even try to replicate aspects of the deployment environment, however? This is often the case when deploying into AWS or other mature cloud platforms: an AWS CloudFormation stack involves all sorts of infrastructure components that would be exceedingly tedious and ...

    Read more »

»