Tuesday, May 29, 2012

Setting up and FTP server in Linux

This tutorial is for Gnu/Linux operating systems. Windows users can use the filezilla server: http://filezilla-project.org/download.php?type=server

A server is the name given to a piece of hardware running software that allows it to interact with client computers. All websites run on servers. This is a tutorial that uses a set of tools to configure a special type of server that uses FTP, the File Transfer Protocol. This is used for the transfer of files between computers. It is similar to what cloud storage services such as Dropbox or Skydrive offer.

The tools
To get the server running we will be using gadmin-proftpd. This is a GTK+ frontend to proftpd, the command line tool. Download it from sudo apt-get install gadmin-proftpd. Run it and enter the root password. The next few sections will describe each tab you need to fill in.

You need to fill in some of these blank fields. For Server Address use the inet addr from wlan of the ifconfig output in the terminal. The server name can be anything. Admin email should be your real email address. Skip down to where it says "signed certificate settings". You should fill this information in and use the "Apply" button to make a new certificate. Failure to complete this step of the setup process is what causes most errors with gadmin-proftpd.

Users is the last tab you should have to fill out.  Fill in the username and password as you want them. Others will need to fill in this information, so make it reasonable. Go to the bottom and click "Add Directory". You should make a directory in /var/www called ftp (it can be called whatever you want it to be) that will act as this new user's directory. This will become the root ftp directory for that user (kind of like / for a normal user). If you want full access over a machine, make this "/".  Click "New User". This user will now be created.

 At the top of the application, click "Activate". The server will then be running. To access the server, go to your browser and type: "ftp://[your ip]" where [your ip] is you full ip address. To add directories and upload data you will need a program like bareftp, (sudo apt-get install bareftp) filezilla (which doesn't play nice with proftpd servers), or a windows program like coreftpd.

This is a local server only. You can make it point to the internet in your router settings. Your router setup (the ip address of your router, sometimes should have some type of "advanced" dialog where you can set up your server. FTP runs on port 21, so you would need to fill in the protocol, port, and IP address wherever the dialog may ask for it. If it asks for a name like our D-link router does, fill it in with the name of your computer. Now, when you visit your external ip address (find this with "ip" on google) using the ftp protocol it will go to your server.

You can also use a no-ip.com host (which are free) to avoid the need to remember the ip address of the server.

Saturday, May 26, 2012

SCT - A custom language code translator

I have been hard at work working on a translator. At last, it has been complete. The translator is a very lightweight program that analyzes a file and a dictionary to translate them between user specified languages. This means that every user on the planet can have their own custom programming language and still be able to convert it into C++. Here is how it works:

 SCT - The translator
Specific Code Translator, SCT for short, analyzes two files. One is called a langdefines. The other is the code written in the language specified in the langdefines file. Here is how it works:

Every langdefines file has this syntax: old_new. So, if we wanted to specify the keyword "void" being "nothing" in a new language the syntax would be: void_nothing in the langdefines. Commenting and newlines are not yet supported in the langdefines file, but support for both are coming in future updates.Whitespace is readable.

Then, the translator will pick apart the langdefines and parse each individual side into two separate arrays. After setup, translation happens.

The translator will read a code file specified by the user as well as reading in the output file and a magichar. More about those two later, though.

The translator will replace new strings with old strings, thus converting it back into the language on the left. However, this is very specific, which is why Specific is the first word of the program. What may seem like design flaws are actually features to enable maximum usage of the translator.

The translator will replace EVERY string matching in the arrays. To avoid things like cout << "torch" from becoming cout << "t||rch" you have to use the sensitive strings feature. Sensitive strings in the code are not parsed, which gives them safety. Output, comments, variable names, etc. should all go in sensitive strings. You use a magichar to specify a sensitive string. The sensitive string goes in between two magichars specified at run time, like so: cout << "$torch$"
Neither torch nor the "$"s will appear in the code.

You can use this program in a number of ways, including fixing massive spelling mistakes in documents, creating a custom syntax for a programming language, or for just showing off to your friends your new language. The way SCT works allows for "inline" coding, meaning that if you were to use it to add some pizazz to C++'s syntax you could still use C++ if you wanted to.

Future Plans
There are a few more plans in store for the program. I want to make reverse translation easier than messing with the code directly and I want to improve the syntax of the langdefines file.

The necessary files are all at my github. My custom langdefines is for a language I call NRSL. Some people that I have asked have Really hated the syntax, so go ahead and judge for yourself.

Thursday, May 10, 2012

C++ - Understanding Pointers

Pointers are a shockingly complex yet very simple thing to master in C++. The idea of a pointer is easy for most, yet the implementation can be a bit tricky for some.

Below is a quick example showcasing pointers. Comments are lingual representations of each line.

int x = 10; //Initialize integer x to 10.
int *px=&x; //Point variable px to the memory address (&) of x.

cout << px <<endl;/*Output the value of px, which is the numeral string representing the memory address of x.*/

cout << *px<<endl;/*Output the value of what px is pointing to.*/

int **ppx=&px;/*Initialize pointer ppx to point at the memory address of px, the pointer of x.*/

cout << *ppx<<endl;/*Output the contents of what ppx holds, which is the memory address of x.*/

cout << **ppx<<endl;/*Output the value of what the pointer this pointer points to is pointing at*/

**ppx+=1;/*The chain of pointers as displayed in the comment above happens and assigns variable x to 1. This is the same as *px=1; and x=1;*/

So, as you can see, pointers are a somewhat confusing concept. Your next question may be "Why even use them?" Well, the answer is: you shouldn't. Only use pointers in situations when they are required by the language or for a considerable performance gain, such as function parameters. This is called passing by reference since you give the reference to a variable's memory address rather than the value of the variable itself. This means that functions do not have to work with copies. You can make functions look like they take value rather than reference by doing something like this:

void doStuff(int &param){}  
This passes by reference because of the "&" operator, which returns the memory address of the parameter rather than the parameter itself. Now, the function can be called exactly like it were pass by value, like so:


 Pointers are not useless. They are extremely useful since you can have multiple pointers pointing to the same variable and even pointers pointing to other pointers. This comes in especially handy with multithreading.

Tuesday, May 1, 2012

Comparison of Media Players - Gnu/Linux

Media players are applications that handle the playing of audio and/or video. (In this comparison the listening of music will be the only factor, not how well/if these applications can play video.)
There is wide debate over which media player is superior, and this will list some of the pros and cons of each media player. Of course a lot of information is left out and of course there are a lot more than are listed, but this article will point a media player-hopper in the correct direction.

1. Clementine
 First off, I will state that Clementine is the application that I have used as of late for playing music. Playing music is what its specialty is. However, using Clementine to play a sound file would be overkill. It does a great job of saving your playlists for later listening and includes utilities for mass file renaming and organization.

Clementine can stream music from the internet and sync with devices. Common media player characteristics are included, such as shuffling and looping.

One of the selling points of Clementine is the ability to destroy the main window and have it reduce to the notification icon. From there you can control the volume, pause, play, move to next track, move to previous track, mute, love, ban, quit, or show the main window again. Clementine also integrates into the Ubuntu sound menu.

2. Amarok
  Amarok, the music player commonly paired with KDE due to the use of Qt, is the media player I had used before switching to Clementine. A very unique feature to Amarok that I had never seen before was the automatic fetching of information from wikipedia about the song and the fetching of lyrics. Of course, once the information was fetched it was cached and it does not rely on fetching to function properly. Amarok also integrates with your portable devices and will ask you before it begins to unlock them if they are locked, which can be troublesome if it misidentifies something to be a device.

Amarok is also capable of working without the existence of the main window. It will fall back to a notification icon with previous, pause, play, and next options as well as the option to show the main window.

3. VLC Media Player

VLC is a popular music player that is very good at what it does. It specializes in streaming but can also be used as a general purpose music player. If I have files that I do not want in my common playlist I use VLC since it does not save playlist information through usages. VLC does not excel with audio playback, but is rather used a video streaming/viewing application.

VLC, like Amarok and Clementine, has a notification icon but it cannot live without the main window. VLC has a very good equalizer

4. mplayer
 Mplayer has arguably the largest learning curve out of any of the media players. It does not come with a graphical frontend, so it must be run from the command line. It cannot remember playlists, you must make a playlist and start the application with the playlist as one of the arguments.

Mplayer has frontends available for it, like SMPlayer. Mplayer by itself does not work with the mouse, so you must memorize the keyboard commands to use it. Some find mplayer to be the best way to listen to audio since you can run it without a window or notification icon at all if you so please.

Interestingly enough, mplayer can play videos very well and is my video player of choice.

5. Rhythmbox
Rhythmbox is the default music player in Ubuntu 12.04. Banshee's absence has given Rhythmbox the opportunity to expand. Rhythmbox is now the official applications for the Ubuntu music store. Like Amarok and Clementine, Rhythmbox syncs to devices with arguably the most accuracy of the bunch. Rhythmbox does not have a notification icon and cannot live without keeping the main window open, so controlling the window may seem a bit bulky at first who are used to being able to kill the main window or control the flow of music through a notification icon.

6. DeadBeef
No, this media player is not built of mutilated cow. What it IS built with is C and GTK (I assume it is C, anyway.) The GTK dependency makes it lighter than a media player like Clementine that has Qt bindings. If you use a Gnome, XFCE, LXDE, *box, or Unity desktop environment; the download will only be about 5 MiB.

The Media player does not offer much in the way of customization or organization like Clementine, but it does get the job done like a media player should. It can import / export playlists, list statistics about the current playlist, and most importantly live without the main window and run as a daemon from the system tray. If you want to use Clementine without the elevated RAM usage and superfluous features, DeadBeef is the media player for you.
Honorable mentions
I did not include the following popular media players:

Banshee: Rhythmbox does nearly the same thing as Banshee.

XBMC: "VIM is a text editor; Emacs is an Operating System" is my favorite quote regarding text editors. XBMC is the Emacs of text editors. It is its very own ecosystem and would not be practical to use for multitasking. This is definitely the choice for a user wanting a heavily media-centric computing experience.

Conclusion (opinion)
I cannot call the conclusion fact since all of these media players do exactly what they are supposed to: play media. I just feel that Clementine has the best functionality. It can run in the background or have the main window; it doesn't matter to Clementine. It also does everything that Amarok can do like sync devices, fetch data, and live without a main window, so the presence of those features somewhat invalidates Amarok.

Bear in mind this opinion is only based in audio, and for video mplayer is my choice. I have no justification for this and VLC does just a good as job as mplayer.