Category Archives: Programming

Controlling cursor position in PHP CLI applications (and others)

I realized that this is still a frequently asked question on forums – how do I move the cursor in my PHP console application? The simplest way to do it in Unix based systems is to echo the terminal control escape sequence. This will work for any application or script capable of printing to the terminal.
For example, to move the cursor up 2 lines you would do:

echo "\033[2A";

So, if you want to create a simple counter:

for ($i = 1; $i < 11; $i++) {
    echo "$i\n";
    echo "\033[1A";

For the full list of the terminal control codes (escape sequences) for cursor and other features, like color – refer to this link:

If you need more comprehensive solution – take a look at ncurses library:

Android Synthesizer

My second take on Android SDK with NetBeans as a development platform.
A completely uncompleted sound synthesizer.
So far you can generate sinusoidal, triangular, sawtooth and square waveforms and mix them together.
You can play the sounds using little touch keyboard and switch across couple of octaves.
I think I should have used Java's piped streams to interconnect the components of the synth, so you can go ahead and improve it.
The nice part about the synthesis part is that I optimized it by basically generating one period of subaudible frequency
every time the waveform is altered and then just selecting every n-th sample, depending on frequency.
Saves a lot of CPU cycles.

Click here to download