Code linting with webpack and JSHint
In this post, we are going to configure webpack to automatically check your code with JSHint with each build. First of all, you need to install the jshint webpack loader. Assuming you are using npm, type npm install jshint-loader in your project directory. This should download jshint-loader into your local node_modules directory and make it available to webpack. Now let’s look at how to configure the webpack JSHint loader. If you want to check your code before any transformations are applied (for instance, because you do not want JSHint to check code generated by a transpiler) you should configure JSHint as a preloader.
Can you use React without JSX?
ES6 classes as React components
FixedDataTable React.js tutorial
Uploading a directory to Amazon S3
If you want to translate a directory structure on a disk to Amazon S3, you need to use the file path as the object key for the file. For instance, if you want to obtain the path /bar/foo/baz.jpg, you need to store ‘baz.jpg’ with an object key of ‘bar/foo/baz.jpg’. In the administration console, it is possible to create “folders”. There is no such thing in the API. Amazon has decided to introduce this concept in their interface.
Recently, I’ve had to work on an application where, for reasons that are best glossed over, a lot of the business logic resides in the Apache configuration. This requires continuously updating a fairly complicated set of mod_rewrite configuration. The configuration needs to be installed on the test server and Apache itself restarted in order to test again. This is not terribly time-consuming, but repeating the over and over can become wearisome and above all, tempt you to modify the Apache config in place instead of keeping all changes under version control.
Computing’s layer cake
There is the ISA, an abstraction built on top of the physics of the materials out of which electronic calculators are built. From the standpoint of the application developer, the ISA, this incredibly powerful abstraction, is a meaningless mechanism. Its concepts, its meaning and its purpose are the fruits of further abstraction. So, in a computer at least, abstraction is a relative concept. One could fend off accusations of abstract thinking in more general matters by pointing out this fact.
Scraping ISO country codes with Nokogiri
The ISO country codes are used in many business settings to identify the countries of the world: for instance, to indicate the destination of a shipment. ISO makes the two-letter codes available for free, but the three-letter and the numeric codes are jealously guarded and even if you pay you will not receive them in a very friendly format (only PDF and Microsoft Access are available). Wikipedia has got a table containing all the ISO country codes you will ever need, so I have decided to write a little script to extract the ISO country codes from the web page.
Simple Java builds with SBT
SBT is a build and dependency management tool written in Scala. When I need to quickly setup a project with some dependencies, I often use SBT, because setting up a simple build is very easy and takes much less typing than with Maven. There are also a couple of other advantages with SBT, namely: sbt automatically recognises your application’s main class and can launch the application just by typing sbt run (no need for a plugin like the Maven exec plugin just to run the application).
Client side web applications
The cost of writing
After a manuscript contains certain number of words, the effort to add more to increases. A 200 page book takes much more than twice the effort of a 100 pages book. Anyone can write a mediocre short story, but you cannot write a some exercise. On the other hand, a book that is twice as long easily delivers less than twice the value to the reader. You can fix higher margins on shorter books.
Here are my notes after attending the Jfokus in Stockholm this year. Tradition Java EE programmers seem to feel most at home in the JEE/patterns paradigms. Injection, repositories, DAOs are everyday fare. The Java worldview has been abundantly shaped by this ‘software engineering’ worldview. Hacking or intellectual sophistication of the mathematical kind come second. Attendee profile Striped shirts, higher education. Serious engineering. Big company culture. Mostly male, as always. Why aren’t there more women in software engineering?
Fixtures vs Factories
Many web frameworks integrate fixtures: a mechanism to define sample data to be loaded in the database for testing. The format of choice is often YAML, and the frameworks supplies classes for setting up and removing this data. But all too often you load data into the database when all you really need is to access sample objects in your test code. Inserting data into the database for each run slows down tests considerably.
The refactoring dilemma
It is an accepted principle that you should leave working code alone. But sometimes you need to modify its behaviour. Now admit that the existing code is fairly opaque, that there are no tests and that the application has never been used nor tested extensively. In any case, you will need to change. You could either introduce your change with minimal modifications refactor the existing code into something more understandable before introducing your change The second option seems riskier at first thought.
Up and down the stack
I am starting to become more and more convinced that to spot issues with a piece of software, you need to go take a wider view of what consitutes ‘the application’. In a typical Java server side application, ‘the application’ does not include only the code running on the JVM. For instance, looking at a database query log can be very instructive. It is amazing how much the number of generated queries can be reduced in some cases by some simple changes.
How to sell tech books in a physical bookstore
I am leaning towards the opinion that it is pointless to keep a tech book assortment in a physical bookstore, as the target audience is going to buy their books online and tech books run out of date so quickly that they probably are an inventory headache. There is a large general bookstore called Selexyz in Rotterdam. By all appearances, the least likely place where to look for an interesting tech book assortment.
Mapping a composite key in JPA with @EmbeddedId
Why @Embedded objects? JPA sits in the uncomfortable middle between managing relations stored in the database and providing object-oriented programming facilities. The general rule is that you annotate your classes with @Entity and each class will correspond to a separate table, with while each field of the class will correspond to a column in that table. The @Embedded and @Embeddable annotation exists to allow you to define two separate classes without using two separate tables in the database.
Packet Analysis with Wireshark
Some months ago I wanted to remind myself of how the Web works. In addition to Computer Networking I went through the second edition of Practical Packet Analysis, by Chris Sanders. Notwithstanding the general-sounding title, Practical Packet Analysis is very much about Wireshark, which is a GUI tool to analyse network traffic, released under the GPL version 2. On a Fedora Linux machine, running Wireshark is very easy, you just start it up and it does its magic; no configuration required except adding yourself to the wireshark group.
Some Perl idioms
Recently I have worked with Perl again for some system monitoring scripts. Some people at Lunatech, where I work, are real Perl mavens. Here are some quick reminders Constants use constant CONSTANT_NAME => "constant value"; creates a compile time constant. It is mainly useful for clarifying intent, although if the right side is a more complex expression, for instance a calculation, there might be some performance benefit. Learn more about constants in the official Perl docs.
Java programmers are haunted by inferiority complexes. Before the functional programming wave, a much ink had been spilled debating the benefits of dynamic languages such as Python and Ruby. While the discussion focused mostly on syntax and the pros and cons of dynamic typing, it recently struck me that the major reason something like Python feels so much more easy to experiment with than Java is that the interpreter manages to import most installed third-party libraries automatically.