Alan Orozco

Sofware Developer

Minimal Publishing

2014 01 26

I created a specific blog, but got too lazy to install the workflow I use on this site, so I came up with a very simple script to publish it:

All of the posts reside in a single src/ file, and there’s a simple template file (src/template.html) that simply contains a <%= @body %> ERB tag and HTML boilerplate. This only requires the kramdown gem and standard UNIX tools. If you run it using the publish argument, it will automatically publish to whatever server is included via SSH.

This doesn’t support indexes (which Jekyll does), but it’s fine for the purpose. This will only contain about 15 articles total, so let’s take advantage of that. You could get fancy and concatenate different Markdown files, one for each post, automatically include all the dates and maybe create permanent links. But why would you? This is minimal, this is beautiful.

Even though this isn’t quite code golfing, I wanted to create a very short implementation of Conway’s Game of Life in Python.

This was done under the following constraints:

  • Make it somewhat modular and readable. This meant not being able to stick everything inside the main loop.

  • Use (and abuse) as many Python features as possible.

  • Allow it to receive the initial state from the standard UNIX console.

  • Have it pass PEP8.

Here it is, just under 40 lines including whitespace:

Some things I learned while doing this:

  • itertools.product can save a few nested loops.

  • Lambdas can be defined as class properties, effectively turning them into methods. This works even for magic methods, which is surprisingly acceptable within PEP8.

  • The whole transition logic for each cell can be reduced into neighbors == 3 or is_alive and neighbors == 2.

  • The list multiplication syntax will create references and not copies of the lists if they are nested. For example, I tried doing the following to create the empty board:

    [[False] * w] * h

And while that seemed to work initially, it took me a while to realize that every instance of [[False] * w] was a reference to the same list. I had to settle for the somewhat dirtier approach of using list comprehension for the outer dimension of the matrix.

A simple test for the script (with just one glider) can be run with the following command:

$ printf "010\n001\n111" | python

  • coj: a collection of solutions for the Caribbean Online Judge ICPC problem archive. There’s not much there yet, and I’m yet to solve a really tough problem. It’s really fun though, so I hope to keep up with it.

  • smoothcurves: a basic curve smoothing algorithm test. It does so by avering the n last points with its most recent immediate neighbor.

  • pewpew: a basic space shooting game I’m building to teach myself Ruby. It’s already playable and has two levels, mostly done just to test it.

2012 10 09

A thing I made that creates images of pretty triangles out of other images. Supports vector output for all your infinite-scaling needs.

Source and instructions are on Github.

Requires Python, PIL and, optionally, svgwrite for vector output.

I coded this little application for my Object Oriented Programming class last semester.

The general concept is allowing to build simple programs based only in flow of inputs and outputs. It’s similar to circuitry design, based on the idea that everything can be routed and processed with black boxes.

It’s aimed at children. Hopefully I’ll be able to continue to work on this, and even use it as a practical tool sometime in the future.

It’s going to be showcased in my university’s Computer Science department project expo today.

Download the application here. Requires Java 6+.

Fractal Landscapes

2012 08 15

I’m obsessed with fractal landscapes. The algorithm used to generate them is so beautifully simple that it’s amazing a human came up with it. Mandelbrot was really a brilliant man.

Currently, I’m toying with fractal mountain generation. All that’s needed is creating a slightly irregular pyramid, and then creating an inner triangle in all of the resulting triangles. You move all the resulting nodes randomly, inside a difference range with limits inversely proportional to the total amount of nodes. Repeat both previous steps until happy with it, et voilĂ !

The principle of that is the Diamond-square algorithm, which can be used to generate a bunch of other natural-looking stuff.

This is something I had put online a while ago, but had never bothered to announce publicly. Here it is, Alan Orozco’s Unsorted List of Favorite Movies.

Why unsorted? Because ranking things belonging to broad categories is futile and unfair to everyone. Plus, whoever sees it can maybe see it without judgement and, hopefully, find something new that they’ll appreciate.

It expect to update this regularly. Making a list of movies I really liked, and then cutting it down to the ones I really loved was a fun exercise. Doing it with albums could be just as fun, we’ll see.

So, a few hours ago I deployed this site. Truth is, it wasn’t the first deployment I had done in a while. In fact, I already had a Jekyll/Git deployment workflow set up. What I actually did in a couple of hours was redesigning and deploying the thing from scratch.

However, there are some funky things I had to do to get around the constraints of my hosting service. These are some of the solutions I came up with.

Using LESS

The site’s stylesheet is written using LESS. That means that everytime I push a style change to the server, the stylesheet needs to be compiled to CSS. The best way to do this without disrupting my workflow was using one of the many LESS plugins for Jekyll available.

I couldn’t do that, since there was no way to install the lessc compiler under my shared hosting account. I figured any compiler written in a scripting language would do, so I used lessphp. The path to the stylesheet is now hard-coded in the post-receive hook script, so that’s one disadvantage, but that beats having to compile the file manually everytime.

GZip Compression

So, apparently, NearlyFreeSpeech doesn’t have the Apache GZip/Deflate modules installed. No problem, we just need to pre-compress all static content and then serve it conditionally.

To pre-compress, the following is needed to run after the site has been compiled with Jekyll. I included this near the end of my Git post-receive hook.

This simply finds all files with an extension that denotes plain-text (e.g. html or css), and saves a compressed version of them with a gz extension added.

We could use Apache Multiviews to serve the compressed files, but I found that solution a bit verbose. Instead, I opted for a rewrite directive:

Assets specific to the server

Certain objects that need to be served from this domain name have no relevant place in the Git repository for this website. I didn’t want to clutter the repository by including them.

I uploaded such files to a private directory on the server, and let my Git post-receive hook copy those files to the public directory everytime the site is compiled. It’s not the best solution, since I can’t push those files via Git, but it’s good enough for now.

Complete Workflow

I based my complete deployment workflow on the one found here. Basically, I only git-push to the remote repository (conveniently named production) whenever I want to deploy, and the post-receive hook takes care of the rest.

The post-receive hook I use is in this Github gist. It includes everything described here except, of course, the Apache configuration directives.


2012 08 05

It’s almost 4 in the morning and I’m done rebuilding this thing. I started a couple of hours ago. Improvisation yields the best kind of satisfaction.

There are still a lot of details to be worked out. I don't even have an RSS feed yet. There’s also not much for content. At the moment, I’m just planning to sleep.

This was built using Jekyll, deployed using Git, and is running under Apache on NearlyFreeSpeech. Cheers.