Extracting Tiles from PMTiles

There are a couple ways to extract map tiles from the various archives - the most popular being MBTiles and PMTiles these days. The best way, though, is using tile-join from felt/tippecanoe:

tile-join -e dir/ input.pmtiles

This will output all tiles as a hierarchy in dir - dir/{z}/{x}/{y}.{ext}. When working with vector tiles, you might need to specify -pC (no tile compression). By default, tiles are compressed in the archive, but if you need the raw tiles in a directory, specifying this option will output the raw, uncompressed files.

Read more

Ruby/WordPress

Too long? tl;dr.

Situation: You’re migrating a big site to WordPress. You don’t want to make 1,000+ posts manually, do you?

Meet Ruby/WordPress. I’ve made a quick little Ruby gem that interfaces with your WordPress database, so you can manipulate it within Ruby. This opens up a whole world of possibilites - the most exciting being Nokogiri, of course.

Here’s a quick code sample that will create 100 new posts!

require 'wordpress'

# Configuration
wp = WordPress.new { host: '127.0.0.1',
                     port: 3306,
                     username: 'test',
                     password: 'test',
                     encoding: 'utf8',
                     database: 'wordpress',
                     wordpress_prefix: 'wp_' }

(1..100).each do |i|
  post = wp.new_post { post_name: "post-#{i}",
                       post_status: 'publish',
                       post_title: "Post #{i}" }
  post.post_content = "This is the content for post #{i}"
  post.save!
end

Note that the configuration must point to a valid WordPress database (and make sure you don’t use one with valuable data… I don’t take responsibility for any lost data. You should be backing up anyways.)

Read more

LocationMatch and ProxyPass

Want to mix LocationMatch and ProxyPass? Not so fast.

<LocationMatch ^/(regex/here/.*)$>
  ProxyPassMatch http://backend/$1
</LocationMatch>

Don’t forget to use ProxyPassReverse if you need it (it shouldn’t be inside the LocationMatch directive, though).

References:

Ruby 2.0.0 p195 PSA

In Ruby 2.0.0 patchlevel 195, you can no longer mix old- and new-style hash syntaxes in method arguments.

For example:

Wrong

method hello: 'there', :goodbye => 'goodnight'
method { hello: 'there', :goodbye => 'goodnight' }

or

method :hello => 'there', :goodbye => 'goodnight'

Apparently this has been fixed in another patch to Ruby 2.0.0, but that doesn’t really matter, since p195 is out right now.

Source: https://gist.github.com/stephencelis/5595842

My Experiences with Rubinius

Rubinius is an implementation of the Ruby language spec. I’ve been using it recently for a project, and I’ve been liking it so far. Here’s a few thoughts I’ve been having while using it.

Philosophy

The Core

Rubinius, in its core, is written in C++ and uses LLVM (Low Level Virtual Machine). Without getting too technical, it translates the Ruby code that you write into efficient machine code, then executes the machine code directly on the CPU. This architecture is very similar to Google’s V8 (and one of the reasons that Google Chrome is a fast browser).

Read more

WordPress Install Script pt. 2

A week ago, I posted Automate your Workflow: Local WordPress Install with a script that helps you install new WordPress installations. I’ve been using it regularly, and have made some improvements:

  • Multi-language support (install a different language with the -l switch)
  • Nightly build support ( -v nightly)
  • Multi-version ( -v {code in the 'Version' column})
  • Arbitrary URL support ( -u {URL})

As always, the script is available as a gist.

Automate your Workflow: Local WordPress Install

Lately, I’ve been pretty obsessed with streamlining my workflow, which means writing scripts (read: building tools to do stuff for me). They say that the best programmers are the laziest; I can’t vouch for being a great programmer, but I can proudly say that I am pretty lazy.

So, I’ve decided to start cleaning up my tools and posting them here as I make them. Use at your own risk!

Read more

The AppleLanguages switch (langchooser.app)

The Google Chrome(tm) title bar in English, Japanese, Russian, and Chinese

In the past few weeks, I’ve found myself demonstrating how to do things on my computer for other people. You know, screenshots, screencasts, the like.

I ran into a small problem: Most of the people I need to teach don’t understand English.

And my default user interface is in English.

So, I ran into this little trick:


$ [path to app]/Contents/MacOS/[app name] -AppleLanguages '([language code])'

That little bit of Terminal code will launch that app in the specified language code you entered, if supported by that application. For those of you who don’t have 10 terminal windows open at any given time, don’t worry! I’ve made something for you too. :)

Read more

Anchor Links inside Facebook Apps

If you haven’t noticed, you can’t use anchor links:

<a href="#hello">Go to id="hello"</a>

Inside Facebook Apps (Page tab, Canvas app, etc). So I wrote a little snippet that emulates this behaviour by using FB.Canvas.scrollTo(x, y);

/*
anchorlinks-fbcanvas.js

Enables anchor links (<a href="#hello">Go to id="hello"</a>) in
Facebook Canvas (page tabs, canvas app, etc)

Requires: jQuery, Facebook JS SDK
*/

jQuery(function($) {
  $('a').filter(function() {
    return $(this).attr('href').match(/^#/);
  }).each(function(i, el) {
    $(el).click(function(e) {
      e.preventDefault();
      var elementId = $(el).attr('href').replace(/^#(.*)/, '$1');
      var $goTo = $(document.getElementById(elementId));
      FB.Canvas.scrollTo(0, $goTo.offset().top);
    });
  });
});

謎WordPress Part 1

There’s a Japanese word I like, “謎” - the dictionary defines it as “a mystery”, “riddle”, or “enigma” - I like to define it as “something that makes no logical sense whatever”.

Here is a part of WordPress that I think makes no logical sense whatever.

Inconsistent Naming Convention

In The Loop, as WordPress likes to call it, you are given some functions that will output information for you. Handy!

Read more

Fighting Against Internet Explorer, Part 2

I’ve been making a Facebook iframe app recently, and I found that this little code »

jQuery('a').children('img')

just doesn’t work on Everyone’s Favorite Browser™ (Internet Explorer 8).

jQuery('a').children('img').length

always returned “0” for me. So I had to end up using .find('img') instead.