Skip to content


LaTeX: solving “pdflatex.EXE (file t1-zi4r-0): Font t1-zi4r-0 not found”

Got that puzzling error, “pdflatex.EXE (file t1-zi4r-0): Font t1-zi4r-0 not found“, which was blocking me when trying to build an R package. At a higher level in the code, the error message was a more obscure “Warning: running command Rcmd.exe Rd2pdf had status 1“.

Anyway, that second one means there’s been an error, and the first one is the clue: a font is missing. Problem: Latex is supposed to fetch missing files on the fly, and for some reason in this case it didn’t. No obvious solution to this, LaTeX was working very fine apart from that. So I just tried the random thing to do: update it (hadn’t updated it since install time about 2 years ago – oops).
And that turned out to be it. The install was so old that I needed to run the update program twice, once to update the update program and core, and once to perform the hefty amount of package updates. After the update, running the R package builder again made LaTex successfully fetch the missing font (said hello to the firewall ;) ), and all worked. Tada :)

Posted in LaTeX.


How to enable hibernate mode in Windows 7

I’m a HandBrake occasional user and I’m having trouble making my computer suspend operation when an encoding job is running: when in sleep mode, handbrake keeps running (!!), emptying the battery about just as fast as when not in sleep mode (and making about just as much noise).

I later read that there are actually 2 different “suspend” modes: hibernate and sleep. To summarize the difference very quickly (more details there), sleep mode keeps the RAM powered and suspends most computer operations, while hibernate is supposed to write the RAM to disk, shutdown the computer completely and then load the RAM with what was saved on the disk when you turn the computer back on.

Hibernate and sleep can both be access from the start menu, in the drop-down button next to “Shut Down”. Except that for some reason, in my case hibernate didn’t show. Apparently in such (common) case, you need to enable it first, and there’s no GUI for that: you need to use the command line. In start menu, run “cmd” (without the quotes – or [windows key] + R works too) and then type powercfg /hibernate on.
If after that you still don’t have the hibernate option (wasn’t my case), reportedly you’ll need to disable hybrid sleep mode in the power options : in start menu, search for “edit power plant” then click “change advanced power settings” and browse to Sleep → Allow hybrid sleep.

Now you should have the hibernate option. If you don’t, you may want to check Microsoft’s FAQ entry about that, but I found it quite helpless.

Last but not least, hibernate seems to crash my computer (and not suspend handbrake anyway), so in the end that was a bit useless :/

Update (2015-03-15): not only Handbrake seems to defeat hibernation, also hibernation will create a huge file to store the RAM’s content. This file, C:\hiberfil.sys will always take up the equivalent of a large proportion of your RAM’s size (I have 20 GiB RAM, the hiberfil.sys file is 15 GiB). So when you don’t need it and want to reclaim some disk space, I believe it’s worht disabling it ;)

Posted in Windows Se7en.


Tools to download APKs from Google Play Store

Android is the most brilliant example of how to do a closed system based on something open. The complete entrapment of APKs on the Play Store, even though it’s “soft” (developers could distribute their own APKs themselves, or at least on alternative stores, but most of them don’t bother), is one among the many ways Google uses to try and track everyone.
Gladly, some people worked on tools to manually fetch APKs. They remain limited due to all the restrictions imposed by Google, but are still better than nothing.

The first kind of tools requires you to have a device with Google services installed and linked to a Google account. I’m not really sure how useful this is, then: sure you can download APKs, but you are still tracked by the GMail man and you still have Google stuff on your device. Still, here is a brief list (I only found 2):

Long story short, those programs run locally on your PC, you need to provide them with your device ID and your Google account (I’d recommend creating a Google Account just for the occasion – if you do have a normal one even though you shouldn’t :p), and then they pretend to be your smartphone and grab what you want from the Play Store (I think it doesn’t work with paid apps though).
I tried APK downloader about 2 years ago, just after I rooted and “cyanogened” my phone, it worked fine. But since then I lost my device ID (:x) or maybe it got unlinked from my Google account anyway. Or maybe I forgot which Google Account I used to fetch APKs. I don’t know why I didn’t save those data. Duh.

Anyway, the second kind of tools is quite the same principle, although they are provided as a web service and you don’t have to use your own device ID and Google account as the service provides some. Sadly there isn’t a lot of them either:

These will definitely not grab paid APKs: as you can understand, they probably don’t want to get into piracy issues. My advice on paid APKs is buy them from some other shop so as to discourage the Play Store monopoly. Aptoide, Amazon, SlideME… you have plenty to choose from and Wikipedia has a list. Enjoy.

Posted in Cyanogenmod, Google, software.


phpThumb: how to switch error messages on

phpThumb is a free, open source (GPL) image thumbnail generator. Even though the site feels like the beginning of the century, development is still going on as can be seen on Github.

This software has weird configuration options to enable the display of errors. To be able to see errors, you should set the following in phpThumb.config.php:

$PHPTHUMB_CONFIG['error_die_on_error']          = true;     // die with error message on any fatal error (recommended with standalone phpThumb.php)
$PHPTHUMB_CONFIG['error_silent_die_on_error']   = false;    // simply die with no output of any kind on fatal errors (not recommended)
$PHPTHUMB_CONFIG['error_die_on_source_failure'] = true;     // die with error message if source image cannot be processed by phpThumb() (usually because source image is corrupt in some way). If false the source image will be passed through unprocessed, if true (default) an error message will be displayed.

But also, and this is the tricky one as it’s away from the other error parameters, you need to enable (or rather, “not disable”) debug mode:

$PHPTHUMB_CONFIG['disable_debug'] = false;

Now phpThumb’s output will still seem like an image to your browser, but if you save it and open it with notepad or equivalent, you’ll be able the read the error message.

Posted in software, web development.


aToaD #13: regex101

Writing regular expressions about always give me a headache… You probably know about the nice regular-expressions.info website, containing a lot of useful information and what seems to be a fairly exhaustive reference.

Yet it misses a useful tool: a way to test your regex. That’s where regex101 (“Regular Expressions 101″) comes in handy. You simply enter your regular expression, pick modifiers (help available for those), then enter some text and see if the regular expression matches it.
Other interesting features:
– quick regex reference in the bottom right corner
– supports regex particularities of 3 languages (PHP, Javascript and Python),
– (very) basic code generator in those languages to use your regular expression
– you can create unit tests
– you can save your stuff either via unique URL or by using a Github or Google (yuck) account. I haven’t tested this, though.

In a somewhat related area, Code Beautify will help you reformat your code in a nicer way. Works with quite a few popular languages (JSON, XML, JavaScript, and many more)

Posted in A Tool A Day.


How save a list of all files in folder + subfolders

(in Windows via command line)

Go to Start Menu → Run (keyboard shortcut: [windows key]+R) and run “cmd”
Browse to the folder you want to list
Then type: dir /s > listing.txt

This is assuming you want to create a file named listing.txt and put the list in it.

If you want to append the listing to an existing file, use a double > :
dir /s >> listing.txt.

If you want to output the result to the console and not to a file, just skip the > listing.txt part.

If you don’t want to browse to the folder, you can specify it as an argument to dir:
dir c:\somefolder /s > c:\listing.txt.

Posted in Windows.


How to convert Dolby DD5.1 to stereo

I’ll just cover the main points, the hardest part was to find appropriate software and to figure which sound channels to keep, the rest is just fairly trivial and usual stuff.

Get Audacity and the FFmpeg library (needed to import from usual video formats like MKV – for Audacity 2.0.6 pick ffmpeg-win-2.2.2.exe)
http://manual.audacityteam.org/o/man/faq_installation_and_plug_ins.html#ffdown
http://lame.buanzo.org/#lamewindl

Import the video file into Audacity (or audio, if you already have it as a separate file).

If the channels/tracks aren’t split already (in the MKV file I had, they were), split all channels to mono.

Keep channels 1 and 2 (remove 3, 4, 5 and 6). NB: apparently in some cases channel 3 should be kept instead of 2 – check them to be sure you keep the good one. In my case, the audio track visualizations showed that track 3 was obviously too different from track 1 to be the other side, so track 2 was good.

I’m not sure it’s mandatory but it doesn’t cost anything to do anyway: merge the 2 tracks you kept into one stereo track. To do so, select both, click one of the tracks’ drop-down menu and select “Make stereo track”. If you have trouble finding it, here’s a video: https://www.youtube.com/watch?v=qz23hdW9sWc

Export in whatever format you want. As of today, Audacity can’t export in Opus, so I chose to export in FLAC, and then I used fre:ac to convert from FLAC to Opus.

Source (for more details and some screenshots): http://forum.videohelp.com/threads/336694-Simple-Guide-How-to-convert-DD5-1-AC-3-448-640-to-stereo
Also, for the reverse operation (stereo to DD5.1, which seems quite pointless to me though, but still interesting to read): http://forum.videohelp.com/threads/335904-How-to-Convert-2-channel-stereo-wave-into-DD5-1-AC3-448-AC-640

Posted in multimedia, open source.


[R] How to install FunNet from source (on Linux, sorry for Windows…)

FunNet was removed from CRAN to due import conflicts, but thankfully still is available from the archives. That makes it a bit harder to install it, yet still fairly easy on Linux.

First, install system dependencies. If you’ve already installed other R packages, you’ll have the usual development stuff which I don’t remember (gcc, g++, etc I assume). To this, you’ll have to add the dependencies of the Cairo R package, which are the Cairo software itself and some development library for the X server:
apt-get install libcairo2-dev libxt-dev
(NB: for the latter, it may be different depending on your distribution, see also this post on Stackoverflow)

With this done, you’re ready to head on to R. Just maybe first grab the latest FunNet source:
wget http://www.cran.r-project.org/src/contrib/Archive/FunNet/FunNet_1.00-12.tar.gz

Now in R, install dependencies:
install.packages('ade4')
install.packages('sna')
install.packages('Cairo')

And finally the installation of FunNet should work now:
install.packages('FunNet_1.00-12.tar.gz')
(to run this, make sure your R working directory is where you downloaded the file, otherwise adapt the path of course)

And voilà, congratulations, you now have FunNet, and it should work ^^

Last but not least though, the user manual. I haven’t managed to figure out how to build the help PDF so far, however something worked nice for me on Windows (yeah my setup is Windows on my workstation, Linux on my servers): you can just go to the folder where the package (aka “library”) got installed on Linux (if you don’t install it as root, it should tell you during the install and this should be under something like ~/R/x86_64-pc-linux-gnu-library/[version]/FunNet), then download the whole FunNet folder and put this into your R library folder on Windows. That won’t make you able to run FunNet (probably not to load the package either), however if you use RStudio you’ll be able to browse the help files from there. You’re welcome ;)

Posted in R (R-project).


How to create global variables in Titanium

The first and obvious way to create a global variable is to initialize it straight from the root in app.js. The usual

var myGlobalVar1 = 'this';

when it is placed out of any brackets.
I actually saw a seemingly official sample application with a comment in app.js saying something along the lines “define your global variables here”. It seems like it should work great, and for me it did… until I implemented notifications using gcm.js.
For some reason, when a gcm.js notification is clicked to open the application, if the application wasn’t already running in the background it will crash because all global variables defined in app.js will be defined locally only (see for instance this post on Appcelerator Q&A). I’m not sure what happens, but my best bet is that somehow gcm.js or the functions it uses launch app.js as some kind of local object, so whatever is defined in it in this context is local and not global as expected.

Anyway, so I needed a more reliable way to create a global variable.
A number of options are suggested in the following posts:

Some involve adding includes at the beginning of every file, and then I wonder how a modification from one view might modify the value in another one. The method I found the most convincing is to attach your wanted global variable to an already existing, guaranteed global variable, for instance Ti.App. Apparently this isn’t a “recommended” way, but it’s a natural feature of JavaScript so should be fairly future-proof.

So, instead of

var myGlobalVar1 = 'this';

we’ll now use

Ti.App.myGlobalVar1 = 'this';

and voilà. The only problem now is that you variable names are quite longer. Personally I even use

Ti.App.myappGlobal={};
Ti.App.myappGlobal.myGlobalVar1 = 'this';

so that if by any chance Titanium decides to rename Ti.App I won’t have any issue to automatically replace all “Ti.App.myappGlobal” with something else.

Update (2014-12-16): sadly, apparently this trick doesn’t work to create global functions on iOS… FFFS

Update (2014-12-23): I finally found a workaround: if variables and/or functions are created in a separate file, which is then included into app.js using Ti.include(), then they are properly registered as global. The big problem with this solution is that Ti.include was deprecated in Titanium 3.3.0 so I’m afraid it might get removed in a not too distant future :s

Posted in programming.

Tagged with .


[R] Solving “unused arguments (length = 4, lambda = 0.5)” error in kernlab

I recently got this puzzling error from the kernlab package, in a script that used to work really nice before:

Error in laplacedot(length = 4, lambda = 0.5) : 
  unused arguments (length = 4, lambda = 0.5)

Switching method didn’t help, for instance with a radial basis kernel instead of the laplacian one:

Error in rbfdot(length = 4, lambda = 0.5) : 
  unused arguments (length = 4, lambda = 0.5)

Apparently someone asked that on Inside-R and Stackoverflow, but didn’t care to share their solution beyond “I figured out that it’s all because of the format xtrain and ytrain”.

Well I eventually figured that out too, it turns out xtrain must be a matrix, so the fix is as simple as changing this:
svm.kernlab.mdl = ksvm(Xtrain, as.factor(ytrain),kernel="laplacedot");
into this:
svm.kernlab.mdl = ksvm(as.matrix(Xtrain), as.factor(ytrain),kernel="laplacedot");
Of course, package maintainers could do the conversion themselves, or at least provide meaningful error messages…

I use this code in a classifier wrapper in R package mc-r, currently under development and accessible at Google Code and Bitbucket:
https://code.google.com/p/mc-r/
https://bitbucket.org/patheticcockroach/mc-r/src

Posted in R (R-project).