Linux `cal` utility in landscape mode

The cal utility in Linux does not, unfortunately allow one to output the calendar in landscape mode (4 columns or more). The default cal -y output mode will display 3 columns. Here’s a hack-around:

  • Download the latest release of util-linux
  • Extract and edit the misc-utils/cal.c file.
  • Find the yearly function.
  • Add a cal_month m4 variable, which will hold the fourth column.
  • A little lower find m3.next = NULL and change it to m3.next = m4;, add m4.next = NULL;.
  • Inside the for loop change the 3 to a 4 in the month += ... clause.
  • And make
  • If all went well the output of ./cal -y should yield four columns instead of three.

You can probably make cal output 2, 5 or 6 columns in a similar fashion. Crazy hack, eh?



Headless Google Drive Uploads

Uploading files to Google Drive from the command line without any fancy agents, exotic libraries, dependencies should be simple. And here’s how it’s done…

First of all we need an Access Token for the Google Drive account we’re uploading to. This can be attained in many different ways. I’ve written a simple bash script to get Google API authentication and access tokens, which can be found here. Note: due to a bug somewhere, Google doesn’t seem to like drive scopes, so I’m using the all-enveloping https://docs.google.com/feeds for now.

Once you have you Access Token, calling the Google Drive API is simple using mere cURL. Multipart uploads allow you to inject metadata along with your file data in one request.

In short, you make a PUT or POST request to https://www.googleapis.com/upload/drive/v2/files/?uploadType=multipart, with an Authorization: Bearer $ACCESS_TOKEN header, and a Content-Type: multipart/related; boundary=$BOUNDARY content type.

The payload should look like so:

--randomboundary
Content-Type: application/json; charset=UTF-8

{ "title": "My document", "parents": [ { "id": "xxxxxxxxx" } ] }

--randomboundary
Content-Type: application/text

DATA HERE, KTHNX!

--randomboundary

The whole script can be found here: https://github.com/soulseekah/bash-utils/blob/master/google-drive-upload/upload.sh. As you can see, we feed the whole file from stdin along with the necessary boundaries.

The “parents” argument “id” should be set to the ID of a folder in Google Drive. If left empty, the file will be uploaded to the root folder. You can get the ID from the URL in your Google Drive when visiting a folder. A list of mime-types for the file can be found in this stackoverflow answer.

Hope this helps folks out there that want to upload files to Google Drive from the command line.



Building WordPress for Android

WordPress clients are available for many devices, but since I’m an Android fan I get to use WordPress for Android.
Yesterday, I came across a bug report outside of the developer ecosystem, managed to reproduce the bug using the release version, and, decided to write and submit a patch to fix the bug.

The main WordPress for Android repository is over at GitHub. But as it turns out…

Building WordPress for Android

…one does not simply build WordPress for Android.

Continue reading



Differential Backups using Git Bundles

There are a lot of self-hosted file and data backup solutions out there, most of which are clunky to set up and configure correctly. Many simply tar your whole directory and let you download a huge archive. Others will store snapshots “in the cloud”.

I like minimal, self-contained solutions. One excellent tool is, of course, rsync, which offers incremental file transfers, which is pretty neat, and saves space by only saving changed files from last checkpoint. This type of backup is usually referred to as incremental backsup. For your media collection or user file uploads this is great. But space can be saved even more if most of the changes are inside the files. This is where differential backup comes in. rsync doesn’t do differential backups. Moreover, there seems to be no straightforward access to history, diffs, etc.

Differential Backups using Git

“history”? “diffs”? Sounds like version control…

Continue reading



WordPress Mail Routed via Postfix SMTP Relays

By default, the WordPress wp_mail function will not set the actual sender for sendmail and mail backends. This means that the Postfix relay will set the sender to the default $domain instead of the actual sender. Which, in turn, means that when using relay maps (sender_dependent_relayhost_maps) to map senders to correct SMTP relays none of them is matched because of the sender is not set correctly…

wpmail

Fortunately, the mailer class used by WordPress, PHPMailer knows how to correctly specify the sender via the chosen backend (which in WordPress is the mail backend). By setting the Sender property of the mailer we’re able to have Postfix identify the sender correctly.

Continue reading



WordCamp Russia 2013

I took part in WordCamp Russia 2013 this year, which was organized by my brother (with huge help from a handful of volunteers and the WordPress Foundation). This was the first ever WordCamp in Russia.

My talk was on testing automation in custom WordPress code, which covered some basics of unit tests using PHPUnit, system tests using CasperJS.

The talk is in Russian, but English subtitiles are available. Also slides and code. To view all other talks visit http://wordpress.tv/event/wordcamp-russia-2013/.

Konstantin wrote about the event in much detail.



Flask-Admin Hacks for Many-to-Many Relationships

Flask-Admin Many-to-Many Hacks

Flask-Admin is a pretty powerful administration solution, which, however lacks several important features for managing models with many-to-many relationships (or at least clear documentation thereof). Here are some useful (albeit perhaps unreliable) hacks to get Flask-Admin SQLAlchemy models to dance the dance.

Continue reading



Multiple Development Environments on One Domain

While it’s true that distributed development should be managed by source control, with each participating party pushing or issuing pull requests from within their own environments, this is sometimes not possible.

Participants might not be able to setup their own development environments in light of many possible reasons and limitations. So remote development environments are usually setup for such participants so that they can work on their own forks of a project without interfering with others’ work. S/FTP/S is usually used, due to their inability to use version control remotely.

Here’s an interesting strategy that came to mind that allows participants to have their own environments on one single domain, single server, with the ability to switch between them without having to edit their hosts files or any other magic.

Continue reading



PrestaShop Variable Shipping Carrier

PrestaShop Variable Shipping

Sometimes complex shipping and handling rules make it impossible for customers to place orders in PrestaShop. Lack of instant shipping quotes, huge quantities and large weights, limited shipping addresses, etc. And while PrestaShop administrators are able to create orders manually via the back-end, these manual orders are still subject to the same shipping carrier rules.

Continue reading



Consuming Hidden WCF RIA Services

A Silverlight application made it to my desk yesterday, an application that consumed a remote WCF RIA service running on a Microsoft IIS. The service did not provide a public API, nor did disassembly with dotPeek help get the service manifests to construct a WCF client with. WSDL files weren’t exposed either. A new, custom client was to be written by reverse engineering what was available without any fancy configurations.

Consuming Hidden WCF RIA Services

Continue reading