Sunday, June 24, 2012

12 - Hour clock in Awesome WM

Awesome Window Manager comes with a widget called "Text Clock" that displays the time in a text box in the upper right-hand corner of the screen. It is in 24-hour format instead of 12, which can cause some confusion for users used to the standard 12-hour time.  Your options are to live with it, or change it. If you want a Day,date, hours:minute:second: am/pm format, look at the end of this post.

Option one- Living with it
I found a neat trick to convert 24-hour time into 12-hour time. Take 13:00, for instance. Subtract 2 from the second number and get the second number of 12-hour time. (3-2=1, so it is 1:00). At 23:00 you get "1" again, meaning that it is 11 O' clock. This method uses too many brain cycles, so I decided to get lazy and just change the source of the script.

Option two - Taking Action
Use this command: sudo gedit /usr/share/awesome/lib/awful/widget/textclock.lua
where gedit is any text editor. This is the source code for the clock widget. Make a backup of the real one. I was a ninny and didn't do this. The two important lines are lines 22 and 23: format and timeout. Format uses the strftime function to display the time. Some important things to note: %H is 24-hour hours and %l is 12-hour time with a whitespace instead of a 0 in the first digit in 1-digit times. (For instance 9:42 would by 9:42, not 09:42). All you need to change is %H to %l.


Now, you are faced with a decision. By default this resets itself every 60 seconds. If you use %S (seconds), you need to change this setting to "1". (5 is also commonly used, but it's a pain if you log in on a non-multiple of 5). This way the clock will reset every second.


The two lines for me look like this:

%p should be the only unfamiliar one. This means am or pm (great for any basement dweller with odd sleeping habits!).

You will not notice changes right away. Restart awesome. If you did something wrong the text clock may not be there. Just use your old source in place of the one you edited. This is the advantage of always keeping a backup.

Here is the FULL source of my script. This is what it outputs:


---------------------------------------------------------------------------
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2009 Julien Danjou
-- @release v3.4.11
---------------------------------------------------------------------------


local setmetatable = setmetatable
local os = os
local capi = { widget = widget,
               timer = timer }


--- Text clock widget.
module("awful.widget.textclock")


--- Create a textclock widget. It draws the time it is in a textbox.
-- @param args Standard arguments for textbox widget.
-- @param format The time format. Default is " %a %b %d, %H:%M ".
-- @param timeout How often update the time. Default is 60.
-- @return A textbox widget.
function new(args, format, timeout)
    local args = args or {}
    local format =  " %a %b %d, %l:%M:%S %p "
    local timeout = 1
    args.type = "textbox"
    local w = capi.widget(args)
    local timer = capi.timer { timeout = timeout }
    w.text = os.date(format)
    timer:add_signal("timeout", function() w.text = os.date(format) end)
    timer:start()
    return w
end


setmetatable(_M, { __call = function(_, ...) return new(...) end })


-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80


You can replace your script with this and it will give you the output I showed you above.

Sunday, June 17, 2012

Living in the Command Line

Some people, usually extreme power users, server owners, and hobbyists choose to use the command line as their primary means of communicating with their computer. Richard Stallman has said that he finds that graphics "distract" him. The command line's learning curve is high since you must know about the command you are issuing, and because a lot of applications are now being developed with their front AND backends using GTK or QT. This article will teach you how to block everything else out, and use the command line for daily life.

Tty's
Tty's are separate logins. You may not know it, but you have 7 open right now if you are using a Linux box. To enter a tty, do this: alt+ctrl+a number 1-6. When you do alt+ctrl+7 from any tty, you will re-enter graphics. Some prefer to use a tty instead of a terminal. Each has a login prompt, where you enter your user name. Then, your password. Don't be surprised if your num lock key is turned off or if you do not see the characters of a pssword being typed. It does this for your safety.

Now that you are in a tty, there are a few things to learn about everyday usage.

Editing Text
To edit text from the command line, you can use GNU Emacs or VIM if either are installed. Otherwise, you will have to use vi, which is usually installed by default on any distribution. Each of the programs have different commands that they use. This can also be used to edit music, movies, and pictures.

Browsing the internet
yes, you can browse the internet from the command line! Download nad install something called links2, which is a textual web browser. From the command line, use the commnad links www.website.com. In links2, you can hit "g" on a non-input area to go to a different website. Sites like Google will work correctly. However, some that use Flash and some that use Javascript will not. Of course, no pictures will be available in this way.

Watching Movies
Wait, you can watch movies from the command line? Yes! You can watch movies in the command line. Download and install mplayer2 (sudo apt-get install mplayer2), then use (mplayer /home/user/movie). This will use the ncurses library to make colored letters to let you watch your video. On X, you can use this and it will create a window to show it in.

Send Email
http://www.simplehelp.net/2008/12/01/how-to-send-email-from-the-linux-command-line/
This works for some people, but my ISP doesn't allow this to happen. Instead, I have to use smtp, which is a bit harder.
http://tombuntu.com/index.php/2008/10/21/sending-email-from-your-system-with-ssmtp/
That explains this in-depth.

Move files
cd changes your directory. ls lists directories. mv moves a file. You can also rename files with mv. To make files, use mkdir. To remove them, use rm.

Kill Processes
Sometimes a process will run long in a tty. When this happens, log into another tty and issue ps -aux
This will list processes and ID's. Then, you can use (kill (ID NUMBER)) (Example: kill 23)

KILL, KILL, KILL
This is a very popular way to remove everything on your computer. Do NOT fall for this anywhere where it may tell you.
sudo rm -rf /
Do not use this command unless you absolutely want to


Tips
man describes a program.
The tab key will autocomplete a statement. I cannot put enough emphasize on how useful this is.

http://www.ubuntugeek.com/useful-and-fun-things-to-do-with-the-ubuntu-terminal.html
This website houses a bunch of cool information.

Everyday use of Awesome WM

I recently tried out awesome, and I was a huge fan of it. It provides the type of keyboard control that I sought since switching between the keyboard and the mouse is inefficient. Also, constant movement between the keyboard and mouse can wear one down after a long session of computing, so awesome window manager introduces a whole new level of comfort and laziness. The mouse still plays an important part in the usage, but it is a sidekick to the power of the key commands. The one thing that I noticed was that the window manager had a pretty high learning curve. I needed to take some physical notes on how to use it. I ran into a few problems, too, but I overcame them. Here is how I did that.

General Usage
Something that I used to use a whole bunch in XFCE was the session management that would start some programs as soon as I logged in. I liked Clementine, Thunderbird, and GNU emacs to start as soon as I began an XFCE session. In awesome this was a bit harder. I had to manually edit the rc.lua configuration file in /etc/xdg/awesome/rc.lua. I added this to the bottom:

-- Autorun programs
autorun = true
autorunApps = 
{ 
   "clementine",
   "thunderbird",
   "emacs",
}
if autorun then
   for app = 1, #autorunApps do
       awful.util.spawn(autorunApps[app])
   end
end
I did this in gedit with the command "gksudo gedit /etc/xdg/awesome/rc.lua". If this type of configuration scares you, Awesome may not be for you. Awesome is all about configuring the window manager to act just like you want it to with LUA. I do not know LUA, but I still find myself editing the configuration file quite often.

Everyday Things
When I first logged into Awesome, I struggled to find out how to even launch an application. Then I found out about the right-click menu. From there I launched a web browser and found out about win+r. This is the first of the key combinations that I learned. The super, or as it is sometimes called "win" key acts as a controller over the window manager. Win+r will open a prompt that says "run" at the top. Just type the name of a program you want. Important: The Run dialog supports tab completion, so you only need to type the first few letters and then tab.
To launch a terminal, Win+r does the trick. Launch as many terminals as you want. You will notice a weird arrangement of windows. This is because Awesome is a dynamic window manager, meaning it has quite a few layouts. I highly recommend the main-left tiling. To change what layout awesome uses, use win+space or the icon at the very top right side of the screen. The one that I use has the icon of two blocks on the left and 6 on the right. This will have one main window on the left and the rest stacked on the left side of the screen. To switch which window is the main one, focus another one by hovering over it with the mouse, using the window list at the top, or using win+j or win+k. Then, use win+ctrl+enter.
If you grow tired of a Window, minimize it with win+n. If you want the window window to maximize to the whole screen you can usually use win-m. An angelic figure will appear to the right of the maximized window on the window list.
If you used to use Unity, Gnome, XFCE, LXDE, or KDE you are probably familiar with the idea of Desktops or Workspaces. Awesome has tags that can be moved to with the mouse or Win+number 1-6 (win+6 would move to tag 6). These work in the same way.
Advanced
rc.lua can literally be edited to do anything that a Window manager can. Here are some important parts of the config:
Line 55: Change which layouts are moved through with Win-Space
Line 219: Some keybindings
Awesome can be themed quite easily. At the top of rc.lua, add beautiful.init("path_to_theme_file")

Annoyances
I haven't come across many. One is controlling the sound. I was able to do this with a custom keybinding, but for a while I used a terminal with alsamixer in it. On "The Linux Action Show", one of the people stated that they would log out, log into XFCE to change the volume, and log back into Awesome. This is really not necessary.
Advantages
This is the fastest WM I have ever used. It boots in about 3 seconds (literally) and is great with working with text. I have heard that it has AMAZING multiple monitor support with their 9 tags, but I cannot confirm this as I only use one. The thing window border makes great use of screen real estate.

Saturday, June 16, 2012

Awesome wm Versus Dynamic wm - The Showdown

Awesome and DWM are both Dynamic Window Managers, in fact, that's what dwm stands for. A dynamic window manager can both tile and float (both of these can also monocle). Tiling windows means that screen estate is taken up completely, making use of every pixel. Floating window managers have resizable windows, and moncling window managers only allow one window to take up the screen at one time. Here is a showdown between Awesome and Dynamic:

Configurability
I made that word up, but it is a very important thing to consider when you're talking about window managers. How extensive theme support is, what widgets are available, and how easy it is to change settings all take play a huge role in what a user will choose for themselves in a window manager.

   Dynamic
Dwm is written in <2000 lines of C. In fact, it is capped at 2000. It will never extend past this out of principle. To configure it, one must first edit the source code directly and recompile it. This is quite a burden, but it means that the entire window manager can be customized. You will want to customize it, too, because the default does not supply the user with some things they may want, like a system tray or even a clock.

   Awesome
Awesome has a file called "rc.lua" in /etc/xdg/awesome/rc.lua. This uses the lua programming language to take full control over some awesome settings. I do not know lua, but it was very easy for me to edit this file because of the parameter names. Changes here will be applied on the next login. ALWAYS keep a backup, because sometimes awesome refuses to start if there is a mistake, even if it is as small as a missing bracket.

Defaults
Default settings are important for the type of person that wants their window manager to work for them right out of there box. Tiling window managers are for hobbyists and power users, but somebody that just wants to boost productivity could be looking into them and functionality right out of the box could be really helpful for them.

    Dynamic
Dynamic has a whole set of useful keybindings by default, and they are pretty easy to learn if you take some physical notes. It integrates well with system defaults, like the default terminal for alt+shift+enter (launch terminal). It comes with 9 "tags" (workspaces for ex-unity users). There is one title bar that I felt could have used some work by default. There is no clock, no system tray, and an unnecessary advertisement for the version number of dwm. The learning curve is also a bit high, so don't expect to be able to use your mouse to launch anything. Using the keyboard will become easier as you learn, however. Unimportant: dwm will use your default desktop background.

    Awesome
Awesome comes with some helpful tools by default. There is a physical button on the top bar to change the mode. It has quite a few modes, some of which I disabled in rc.lua because of how useless they seemed. Modes can be switched from the keyboard or the mouse in the top right corner, near the default clock, date, and system tray. The clock is in 24-hour format by default, so if this is not your preferred way of tracking time it will take some getting used to. Awesome also has 9 tags. It comes with a window list on the top bar as well as an application launching button on the top right. The keybindings are very similar to that of dwm, but they use the mod4 (windows symbol, sometimes called "super") key instead of alt.

Extra information
Dwm didn't want to play nice with awn or tint2. Windows would ignore their modifications to the width of the screen and go past it. I found this pretty annoying since it did not include a window list. With a tiling window manager, it would be pretty redundant, but I had to give up a good friend named awn when I switched. Awesome works fine with both. Both of these window managers are BLAZINGLY (another made up word) fast. I have used both xfce and lxde, but both of these stomped on them in comparison.

Startup applications require configuration in both window managers, but this is far easier in awesome.

The Verdict
[opinion]
From about 5 hours of using each of the window managers, I would definitely, without a doubt, recommend Awesome to anybody looking to use a tiling window manager. It can act a bit buggy at times when moving windows by a mouse, but that is just a very minor inconvenience. It is set up very well to use a configuration file and to have some sane defaults. Dwm shoots itself in its own knee by forcing themselves to keep the project under 2000 lines of code, so awesome prospers as a result. I did feel that dwm documentation was pretty good.[/opinion]

Friday, June 8, 2012

About Coding Standards - C++

Whenever you write an article or an essay, you are conforming to language standards. Some are required, and other are preference. Using a semicolon is required. Choosing whether or not to split the sentence into two instead of conjoining them with a semicolon, however, is just your own opinion. You do it to fit in with a crowd. Some believe that the use of thee semicolon in the English language shows mastery and intelligence, but others may think that it is reckless for whatever reason. Coding standards are similar to this.

When you write a program you are, in essence, writing a very technical essay detailing how to do a specific task. This essay, like in the English language, have preferences you can choose from. You can choose to write a program like this:
int num1=0;int num2=0;for(int i=0;i<10;i++)cout<<num1+num2<<endl;
That could also be written like this:

int num1=0;
int num2=0;

for(int i=0; i<10; i++)
    cout << num1+num2 << endl;

This is exactly the first jumble of code, but more readable. We used a formatting style to make this example more readable than the first. We all know that the semicolon (in programming) should always be at the end of the line (except for the exception of initialization within loops). This is a major standard. What are some of the minor ones, though?

Group Types
I am the type of person that puts all of the variables at the top of a function. Some prefer to make them when they are needed, but I like seeing everything that this function will do before it does it, like an outline. I group variables based on their types,  and I encourage others to do so as well. They should also be related in function, so all numerical types come before text types.When you run out of a certain type, it is good practice to include a line of whitespace. I group pointers by being a pointer, not type.

int num1 =  0;
int num2 =  0;

double d1= 0;
double d2= 0;

char c1     = 'a';

char *pc1 =&c1;

This raises another very minor point. I put "*" near the variable name instead of anywhere else. This way, you can clearly see that it is a pointer.

Indent a space
Within nested loops, I indent one space for each level. Also, I ALWAYS put a bracket, even if it is a one-line loop. I begin the bracket on the same line as the loop and each on its own line, sometimes with comments.

for(;;){
 for(;;){
  for(;;){
   for(;;){
              }//END for
            }//END for
          }//END for
        } //END for

Operator Aligning
Whenever I get input with cin and use cout to output it, I always align the "<<" and ">>"'s. Sometimes I do this with semicolons, equal signs, and comments, but this is not always the case. This is more obvious if a block of code is designed for one task. After blocks of code, make a line of whitespace.

cout << "Enter Item: ";
cin    >> item                 ;
cout << item <<endl   ;

Putting it all together
Here is what a sample program should look like:

#include <iostream>
using namespace std;
int main(){

 int num1=0;
 int num2=0;

 char char='a'

 for(int index=0; index < 10; index++){
  int inlineInt       ;
  inlineInt=index;

  cout << "Enter a whole number: "<<endl;
  cin    >> inlineInt                                             ;
  cout << endl                                                      ;
 }//END for
}

There are many different coding standards out there. K&R, GNU, and Java are just a few. Over the course of your work you will develop your own style. What I have shown you today is my preferred style. You can adopt it if you wish, but it would be a more rewarding experience to write a few programs and see which works best for you. Lazy people and beginners do not follow any sort of standard, and that makes the code very unpleasant to see and work with later on just as much as not commenting it does.

Thursday, June 7, 2012

Your own Programming language - SCT

This is an article that gives a tutorial on redefining C++ syntax with SCT. The documentation is pretty straightforward, but this will show step-by-step how to make your own language in a few easy steps. Disclaimer: This is not really a programming language. You are just redefining some syntax here. If you TRULY want a programming language you should look into compiler design.

1) Download SCT
SCT is my own free product and I have it hosted here on Github. If you are on a debian-based system you can install the .deb (you may get a standard compliance warning if you use the Ubuntu software center. It's Okay to install this file. If you don't believe me, look at the source on Github). Otherwise, you will have to download the executable file ( in bin) and run it directly.

2) Make a langdefines.ldf
This is a type of file that holds a language. The syntax is old_new. You can use "$" for commenting, but not on its own line. For instance:
old_new$oldnew$
oldnew would not become part of this line. Here is how you could set it up to work with a hello world application for C++.

#include_import
std_txt
<<_<--
cout_say
endl_eol

3) Make a code file
You can now make a code file. It is just a normal text file that adheres to the langdefines rules. However, you can include strings that the langdefines does not know; they will just not be translated. In fact, this is the only way to get some characters into code.

import <iostream>
using namespace txt;
int main(){
say <-- "Hi!" <--eol;

Of course, this is an overly simplistic example. Langdefines can contain up to 10,000 lines.

4) Run sct
You should run "sct" from the command line (if you used the .deb) or just run the executable. Here is what to do at each prompt:

What is the total file path to the language definition file?
$ /home/yourname/example.ldf


this one is pretty self explanatory. Where is your langdefines?



Would you like the langdefines automatically ordered? y or n
$ y
This one causes some confusion. Before I explain what this does, take an example.
You have a langdefines that reroutes || to or like this: ||_or. However, below it you have this: for_door. This will become "do||" in the code, causing a massive error. Ordering the langdefines by line size helps to prevent this. Ordering is not foolproof, however. Comments are DELIBERATELY COUNTED. If you want a particular line to be longer than the other for this reason, it is a good way to do it. Be careful with comments for this reason.

Are you using a Noran Make File? y/n
$ n
A Noran Make File is like a make file, but it specifies a list of files to translate at one time. The syntax is infile_outfile_magichar for every line. infile is the code, outfile is the output filepath, and magichar is what character you used for translation comments. Translation comments allow strings that you KNOW will be translated be preserved. In our above example, you could save "door" by doing $door$ and using $ as your magichar. $ is the standard.

If you did not use a Noran Make File, this is what the rest of the program will be:
 What is the total file path to the code?
$ /home/yourname/excode
This is where your code is located.

What is the file path to the output file?
$ /home/yourname/whatever.cpp

Finally, this is where to put the translated code.


If you would like to easily call this form other programs, it can run in argument mode, but it does not support iterative compiling.


Congratulations. You have now redefined C++ syntax and converted code that you wrote in your own custom language into runnable C++.

PS: Here is what my language looks like:

import <iostream>
use nspace std;
number program() (*
itl(number index is 0; index lthen 10; index`incra`)
say <-- "$Hello world, Iteration $"<--index<--eol;
mail 0;
*)


Wednesday, June 6, 2012

What is ipv6 day?

Ipv6 is the next generation of IP addresses. Like going from 3g to 4g on cellular phones, there will be a slight increase in efficiency of data transfer. This is not the main goal of ipv6.

We are currently using ipv4, which uses 32 bit addresses. Due to the limited amount of spaces provided by ipv4, we are literally running out. ipv6 uses a 128-bit address, making the number of addresses that can be assigned much larger than ipv4 could ever dream of assigning. This will end the need for network  address translation, which was a hack thrown in to conserve space.

Ipv6 day is a worldwide release of the new protocol. Companies such as Google, Facebook, and Cisco will permanently give their users access to ipv6. This is a large step forward for ipv6, which is actually quite an old protocol (almost 13 years). The ipv6 will run alongside ipv4, so those stuck with ipv4 can still use the site's services.

Last year, there was a test of the protocol. It worked well, so the companies that participated began preparing for the final release of ipv6. This year, many companies are permanently dishing out ipv6 access.

http://ipv6-test.com/
This website will test to see if you truly have ipv6 enabled. If you don't it could be the fault of your internet service provider, of which many do not offer ipv6 yet. The Internet Society is urging people to contact their ISPs and recommend that they implement ipv6 as soon as possible.

Ipv6 may be a few more months or years away, depending on which internet service provider and type of computer you use. If you use Windows, you will need to upgrade beyond Windows 2000. The latest 3 versions of OS X are compatible. All versions of current Linux and BSD operating systems have ipv6 as they are commonly used for networking.

Saturday, June 2, 2012

How to make a website (Linux)

The internet is a hard subject to grasp if you do not understand networking. All it is is a system of servers connected by an internet service provider, which give you access to all of these servers. There is nothing special about a server, either. It is just a computer like the one you are using. You too can set up a website to use locally and over the internet. Here is how to do it in any variant of Gnu/Linux that has Apache and Kompozer (optional).

This article assumes that you have no knowledge of HTML (The Hypertext Markup Language), which is what websites are technically written in. Instead we will use a program called kompozer that is generates HTML similar to how blogger does.

Run these two commands to get started:

sudo apt-get install apache2
sudo apt-get install kompozer

The first command installs the server software and the second installs kompozer, the editor we will be using. After you install apache2, a directory named "www" will be created in /var. This is where you will place the file named "index.html".

You can link to other pages from the main one by making a link with the name of a file in /var/www or any other file on the computer.

Write the Webpage
 Run kompozer with root privileges. (sudo kompozer). You are going to be saving the file in /var/www which is a protected directory by default. Now, all you have to do is... write. Kompozer has all of the tools you will need to make your basic web page. Add text, links, bold text, italicized text, pictures, or whatever you need. If you need mroe power you can edit the HTML directly from the "source" tab if you must. When you are done writing your web page, save it.

The first dialog that will come up will ask you for a title. Name it whatever you want the name of this page to be. This will appear in tabs and on some window lists. Hit okay, and save it as "index.html" in /var/www.

Viewing
You now have a website available on your machine to the world wide web and to your local network. Find your ip address by typing

ifconfig

into the terminal. The wlan address is your IP address. Your local network can access the webpage from this address. To view it from anywhere in the world, you need to port forward your router. To do so, look up your router's manual on port forwarding. My router has an "advanced" dialog at 192.168.0.1, so that may be a good place to start looking. After the forwarding has been set up, you can go to http://your_public_ip to see your website. Typing "ip" into a google search will show you your public IP to use.

Open Source Development Model

Many people do not understand what the term "Free" (in the sense of libre) means to the fullest of its power when it relates to software. Many confuse it with free as in free beer, or "gratis" as Linux creator Linus Torvalds calls it. This is an in-depth comparison between the two terms and how it relates to software.

Common misconceptions
Whenever I bring up the subject of open-source software with somebody who does not write code, they always use the same argument. "So, what? You don't think that people should be rewarded for what they do?" In fact, this is why many people associate open-source supporters with the communist party. However, this is not the case. Projects where a lot of the code is open-source (such as OS X or Android) still generate tons of cash. Advertising also draws a huge monetary gain for open-source developers.  In all revisions of the GNU GPL selling free software is strongly encouraged, showing that it can and is done.

Simply releasing the code does not make a program free (in the definition of the Free Software Foundation). To be free it must be licensed under a license that stops it from becoming proprietary in the future. In my "travels" I met a man that was a fan of the BSD license, boasting that it was even more free than the GNU GPL. However, the project he was referencing was not original. Had it been a few years later that he decided to maintain the project, it may have already become depracted by a proprietary variant.

Unlimited Potential
The difference in the development models of proprietary and open source development is described in "The Cathedral and the Bazaar". They differ in one key area: who writes the code.

In a closed-source development model, a developer or team of developers work on one copy of a product and release it to the public. Only they can monitor the code and they are wholly responsible for fixing bugs and making the code more efficient. This costs man hours, and it is why a lot of payed programs are proprietary.

On the other hand, Open Source development happens in a much more community-esque fashion. An author or team of authors conceives a product and begin development, and either immediately or at a point where the barebones functionality has been met they release it to the public under a free license. Up to this point the style this happens is much like a closed-source model, but the magic of open source occurs at the next step. Any hobbyist or paid programmer (some companies actually pay developers to write free code) in the world (if it is hosted on the internet) can write bug fixes and new features for the program. They can also host their own variant of the program if they feel their addition changes the functionality or aesthetics too much.

The Downside
The weakness of the Open Source model is the same as its strength: anyone can see the source. Crackers, malaware authors, or anyone wishing to break a system can analyze the code, find the weaknesses, and write exploits for them. However, whenever a gap is released it is usually spotted and squashed within weeks.