Posts

Emulating line-buffering mode (Gradle example)

C printf() function doesn't flush buffers by default, and a lot of code using it may miss this, therefore creating interactivity problems to the end user. It's not specific to C though - it's about the standard I/O streams, and the problem may appear anywhere. The post is based on StackExchange discussion, so you can dig deeper if you want: Turn off buffering in pipe.

Xcode build settings

Image
Xcode build locations may mislead developers hoping to fully control the output of the IDE. While we can use CONFIGURATION_BUILD_DIR for the xcodebuild tool during continuous integration, IDE generates files in different locations, and sometimes we want to control it too.

Thunderbird Grammar Checker 0.7 has been released

Link: https://addons.mozilla.org/en-US/thunderbird/addon/grammar-checker/

This is a maintenance release that has fixed the compatibility issues with the LanguageTool API v2 (the current one) and the new Thunderbird API. No functionality has been added, but now the add-on actually works.

Development of the add-on have been moved to Github: https://github.com/nuald/thb-gramchecker

Unfortunately, I can't actively maintain the add-on, but all pull requests are welcomed.

Gradle task for launching Android simulator

Android build toolchain, albeit being powerful, sometimes lacks some essential functionality required for the modern software development. In particular, running instrumented unit-tests in the CI environment: those tests require a device or a simulator running, however developers need some scripting to make it work.

To simplify the task, I've created a Gradle task that verifies if any Android device or simulator is connected. If not, the task launches a simulator with the first AVD in the list (or fails if no AVDs are found). It's up to you to make the dependencies for the connectedCheck task. The sample output:

> ./gradlew connect --info

...

:AndroidSampleApp:connect (Thread[main,5,main]) started.
:AndroidSampleApp:connect
Executing task ':AndroidSampleApp:connect' (up-to-date check took 0.001 secs) due to:
  Task has not declared any outputs.
Detecting devices...
Launching emulator for Nexus_5_API_25 ...
:AndroidSampleApp:connect (Thread[main,5,main]) completed. Took 14.18…

Simple HTTP/HTTPS server on Scala/Akka

Let me present a simple Scala script to serve local files over HTTP or HTTPS. I've used Scala/Akka to get the good performance and to play around with the programming language I really like.

Toolchain
We need Scala, SBT (Scala interactive build tool), Conscript (a distribution mechanism for Scala apps) and Scalas (the script runner for Scala). Conscript is needed only to install Scalas here, so you may want to install the runner manually (see the Scalas link above) if you don't want to install Conscript.

For Mac OS X we're going to use Homebrew to install Scala and SBT:

 $ brew install scala sbt

Next step is Conscript (please follow the installation instructions on the official site):

 $ wget https://dl.bintray.com/foundweekends/maven-releases/org/foundweekends/conscript/conscript_2.11/0.5.1/conscript_2.11-0.5.1-proguard.jar
 $ java -jar conscript_2.11-0.5.1-proguard.jar

Next step is installing Scalas (please follow the installation instructions on the official site):

 $ cs sb…

Android screen capture with GIF format

GIF format is still here, and it's a handy way to make small videos. It's very easy to do despite of all ads telling us to buy their commercial software, and I'm going to describe the tools we need.

First, we need to capture the video of the screen. For Android, you can use ADV Screen Recorder, but surely there are tools for any platform. Please verify the recorder settings (you may want to disable mic recording and change the output folder to be on an external SD).

Second, after we recorded the video, we need to convert it into GIF-format. For that we're going to use FFMpeg tool (on Mac, just use "brew install ffmpeg").

GIF uses 256 colors, so we need to create an auxiliary palette file. Therefore, the converting process takes two steps: 1) create a palette, 2) use a palette and an input file to create the output GIF. The commands for that:

$ ffmpeg -i input.mp4 -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png
$ ffmpeg  -i input.mp4 -i palette.png

shelljs node module

Let me share a little gem I've found: shelljs node module. I was working on updating my Cordova hooks to work with Windows environment and had to replace my bash script with the corresponding JS code. Unfortunately, the node modules I've found were disappointing, especially copying the files. Surely I could write the copying code by myself, but I supposed that in 2016 year one is not required to do such menial tasks.

The biggest problem for the modules I've tried was the glob matching - I have to copy files from the sibling directory, and modules couldn't find it (looks like they don't parse ".." notation). I've tried fs.extra, fs-extra, ncp, filecopy, cp, but no luck. I guess I could find the good module after all, but after I've discovered shelljs I don't need it anymore anyway. With shelljs porting the code was a piece of cake - see the results below (the original and the new scripts).