Saturday, December 27, 2014

Telegram (CLI) on Raspberry Pi

This post (in German) explains how to build Telegram Command Line Interface (CLI) client. I confirmed that those steps also works in my Raspberry Pi type B board, minus the Lua component. I had to disable Lua because I cannot get it to compile in my Raspberry Pi (running Raspbian). The compilation always failed because it doesn't have enough space in /tmp for the intermediate compilation result. Well, I don't have any need for Lua either.

Now, let's get down to the details. These are the steps (I'll repeat the steps in the linked article above for completeness sake):
  1. In order to make sure you have enough /tmp for the compilation, you can enlarge your /tmp as explained in this post (basically edit /etc/fstab and unmount, remount /tmp or reboot your Raspberry Pi to be sure).
  2. Install the needed libraries in your Raspbian:
    sudo apt-get install libreadline-dev libconfig-dev libssl-dev libevent-dev
    
    I leave all Lua-related stuff out because we don't need it.
  3. Next, let's clone Telegram CLI from github:
    [your_home_dir]: git clone --recursive https://github.com/vysheng/tg.git && cd tg
    
  4. Now, let's make a build directory in order not to clutter the source code with intermediate object files there.
    [your_home_dir]/tg: mkdir build && cd build
    
  5. Now carry out the compilation there. Remember to disable lua:
    [your_home_dir]/tg/build: ../configure --disable-liblua
    [your_home_dir]/tg/build: make
    
    Grab yourself some coffee to wait for the compilation to complete.
Once the compilation complete, you'll have Telegram CLI executable (named telegram-cli) in the tg/build/bin directory. Now, you can start using it. Just a hint: to end your telegram-cli session, type:
 /exit
In the current telegram-cli session. You can just type "/" then "TAB" to see the options available to you. It also confuse me how to quit when I first uses Telegram CLI ;-)

Thursday, May 29, 2014

Batch Encoding mp4 Videos to Wav (Audio CD format) in Windows

At times, you want to listen to your favorite tunes while driving in congested roads or for extended period of time between cities. The problem is, your car's audio only support Audio CD. This dictates you to convert your favorite tunes to Audio CD. Moreover, you don't have enough time to convert them one by one. Enter the "batch encoding" realm..
Simply put, batch encoding is the process of encoding multiple files in one go. To do that, we use shell script, or batch file in Windows. Because most of my favorite tunes are mp4 videos, my batch encoding script converts those mp4s into wav files. I used VLC to carry out the encoding and I'm using a powershell script to automate the encoding into batch encoding. This is the powershell script that I use:
$outputExtension = ".wav"
$bitrate = 128
$channels = 2

foreach($inputFile in get-childitem -Filter *.mp4)
{ 
  $outputFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputFile.FullName) + $outputExtension;
  $outputFileName = [System.IO.Path]::Combine($inputFile.DirectoryName, $outputFileName);
  
  echo "Output filename: $outputFileName" 
    
  $programFiles = ${env:ProgramFiles(x86)};
  echo "Program Files: $programFiles"
  
  if($programFiles -eq $null) { $programFiles = $env:ProgramFiles; }
  
  $processName = $programFiles + "\VideoLAN\VLC\vlc.exe"
  echo "processName: $processName"
  
  $processArgs = "-I dummy -vvv `"$($inputFile.FullName)`" --sout=#transcode{acodec=`"s16l`",ab=`"$bitrate`",`"channels=$channels`"}:standard{access=`"file`",mux=`"wav`",dst=`"$outputFileName`"} vlc://quit"

  echo "processArgs: $processArgs"
  
  start-process $processName $processArgs -wait

  }
It's not that complicated. It's a slightly modified script from VLC wiki (https://wiki.videolan.org/How_to_Batch_Encode/). There was one hiccup though because by default poweshell doesn't permit script execution. Therefore, I have to run powershell as administrator and then modify the execution policy to unrestricted like so:
Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

PS C:\Users\zzz> Set-ExecutionPolicy Unrestricted
Anyway, the powershell script above assumes that you placed all of the mp4 in the current directory (directory where the powershell script located). The batch encoding result will be located in the current directory as well.
Now, to create audio CD, you'll need the application to burn the wav files into audio CD. I'm using cdrecord in Linux to do this because for some reason, the only machine with CD/DVD writer that I have is running Linux. You can use your favorite CD authoring application to do this.

Happy Encoding!

Tuesday, May 20, 2014

AS400 Programming Tutorial

After searching the web for sometime on AS400 RPG-ILE tutorial, I found the most newbie friendly tutorial over at: http://www.letsas400.com/ile_rpg_iv/index.php. RPG-ILE is also known as RPG IV or RPG400. I'm not yet quite familiar with the AS400 hardware but it seems it's a Power machine. The OS400 on the other hand is a specific OS developed by IBM for the AS400 hardware.

IBM provides a more comprehensive tutorial in the ILE RPG Programmer's Guide. However, to save time, I prefer to read an overview on the language itself and the tutorial in the link above is just what I need to bootstrap learning the ILE RPG. I hope this post is of some use for those starting with ILE RPG on IBM Series i machines, like me. Happy coding :)

Monday, May 12, 2014

Preventing Pointer Aliasing in C (for Scientific Computing Optimization Purposes)

The issue of pointer aliasing in C for those working with Scientific Computing code is probably a familiar issue. Pointer aliasing happens when more than one pointer refers to the same or overlapping memory region. This hurts performance in Scientific Computing code written in C. Pointer aliasing is probably the biggest issue which hurts performance of Scientific Computing code written in C compared to those written in Fortran. However, as of C99 standard, pointer aliasing can be "disabled" via the __restrict__ keyword. Most mainline C/C++ compilers supports this keyword. These are the relevant links for various mainline compilers/toolchains: