Recent Posts

Nick Jacob Git Hooks for Clean Repos

One of the version control mistakes I really worry about, especially when working in repos with a chance of very large files (e.g., trained neural nets, data sets, log files), is the checking in of relatively large data that is heavily modified by scripts (not by users). While it can be useful to have version control on something like neural net parameters, I think this is better accomplished by versioned keys in s3 corresponding to git tags, or to a CHANGES.txt file or equivalent.

To avoid accidentally adding these files for all users of a repo, I like using git hooks to check the staging area before a commit. Here’s a simple pre-commit hook that checks for large files:

It would be nice to turn this script into a system that offers some kind of versioning for the large files (like s3 upload or renaming/gzipping as with logrotate), although at that point maybe you should just work more towards having your team involved more in maintaining a good repo/use of VCS.

Nick Jacob How to write a tiny client-side, compiled-template library

In writing quick/one-off web apps, I often find myself really wanting some client-side templating. In general, I think it’s a good idea to move all presentation to the client and let any front-end servers work mainly to proxy/authenticate requests to backend APIs, containing any scoping/formatting but not dictating presentation. This makes responsive presentation more flexible (you can limit display on smaller screens, or reeuse the same data across views without making extra backend calls. This also makes it easier to make a completely static site (e.g., hosted in s3) with a backend service using some scoped CORS–this is how works. With the rise in popularity of client-side frameworks, it seems like this approach is pretty well accepted.

At the same time, I rarely need all of the features of a templating library like handlebars.js, and I don’t usually include underscore in simple apps, even though I do think it’s pretty great.

I figured all I really need in client-side templating is string interpolation, possibly also with nested property access. So I put together a couple of javascript functions to create some compiled templates:

This can be represented in a lot fewer lines, although I have to admit it’s still not really super readable. Just to break down the compile function.

On a high level, the function produces a new function that performs string interpolation using concatentation, dynamically looking at the object passed in (using with statement). Ideally, this could be called with a context that would provide additional helpers:

There are a lot of improvements that could be made, but I’m a fan of this for its simplicity and the fact that it forces me to avoid pushing to much logic onto the actual view.

subscribe via RSS