Just A Small Guideline

Feel free to browse the site. Don't be afraid to leave comments, they're supportive.
Please follow me on Twitter @ehldmnt and retweet my posts.

Tuesday, March 26, 2013

5. Reasons For Why You Should Learn the Terminal (CLI)

I've argued this with my girlfriend, time and time again. "Why do I have to learn the command line? I'm fine, I can do everything without it," she says before something breaks. I honestly sometimes shake my head and sigh when I hear those types of things. I can understand being impatient, but that doesn't mean that you should neglect learning a tool that is apart of your system. You didn't neglect learning how to use an internet browser right? I mean, you managed to get on the computer somehow, don't tell me you didn't have to at least try a few times to learn how to use the windows and your mouse.

I'm here, arguing five of my best reasons for learning the CLI, A.K.A. Command Line Interface.

5. If you don't like being patient, then you should hurry up and learn it then. This logic makes sense, because with Linux, if you don't know what you're doing you're more likely to spend more time with a problem if something breaks. Failing to Google for answers, nagging someone else who knows what they're doing for help, or even just being a little help-vampire all over the boards. In fact, you might become so frustrated that you abandon Linux and Unix operating systems altogether to settle for an even slower, buggier Windows.
 The reason why open-source is better than closed-source is because if something breaks on your open-source system, you're more likely to find lots of documentation, lots of help, and maybe even lots of other people with the same problem as you're having which actually urges developers to work faster to fix the bug. In addition to that statement, sometimes, with Arch [I don't know about the other Distro communities], you'll see that users will band together and use their accumulated knowledge to solve problems that they have with their systems. Even though sometimes it can be a bit rough out there, it's not so much impoliteness as it's just getting to the point.


4. People don't always want to have to solve your problems for you. I mean, the hacker mind-set is that problems can be fun and that everything is broken and needs fixing, but that doesn't mean that they want to help you with the same problem that many other people, somewhere on the internet, have already learned because you're too stubborn to learn something as basic as "tar -jxvf *.tar.bz2". Mind you, it's not bad to ask questions and to seek answers from someone else, but it's bad to actively seek someone to just magically pop up and give you the answer instead of reading a small bit of Documentation all the time. It doesn't work that way, and it isn't fair to those around you.


3. Your system will have less bloat because you'll have apps that won't require a GUI wrapper to function. This is another perfectly logical reason for why you should learn to use the CLI. For example, my girlfriend will go as far as to go to YouTube to find a song, get a Firefox plugin, and then use the plugin and have it download and convert the file to mp3 [of all things] for her.She could have accomplished the searching with three, very simple commands and would have more time to do whatever she wanted while it downloaded in the background, reducing the occasional lag in her system.
Try this, open up a file manager, and open up something like xterm, and then tell me how much of a delay you feel. To see a tutorial on how to navigate and see your files in the CLI, check out my developing tutorial series.


2. Once you learn, you're hooked. The both cool and weird thing about using the terminal is that it becomes a habit of a kind that you won't want to break. Another personal experience that I had while learning the command line, was that once I had gotten my new computer, Windows had become too painful of an experience for me to want to keep for any extended period of time. I just had to get virtual-box and say good riddance! It came to me that I had to literally click on the explorer icon each time in order to navigate my folders. I couldn't change most of the colours to something darker for my light sensitive eyes, and there wasn't even a keyboard shortcut! So I had to feel like a retard every time I pressed ^T (Ctrl-T) and didn't get anything at all! It was so annoying that I wiped my drive and threw Arch on there as soon as was possible, and I didn't even have a dedicated internet connection which just goes to show how much I despise the Windows operating system.
But back on track, after a while, the terminal becomes less of a "hindrance" and more of a tool. Yes, there are times where using the file manager is faster than using the terminal but that depends on from who's point of view, whether or not you can touch type, how fast you type, and how many things you actually keep on your computer. When clutter collects and you need to sort it, a wild card [or asterisk(*)] to get all of your image files into your pictures folder is always a good thing. Want to run programs in the background? Throw a little bit of ampersand(&) spice up in there! The possibilities are limitless, and once you learn commands like sed and grep, you'll be well on your way to proficiency.


1. Self-Sufficiency is a good thing. To be self-sufficient is a big part of being independent and is a greater step towards grown and personal, mental, enrichment. Though there is happiness in ignorance, if that is what you wanted then you should have stayed with Windows, or OSX and just not have even bothered coming this far. It's like going to get water, filling up the buckets, only to walk half way and leave the buckets behind. It just doesn't make sense and isn't the way things were meant to be done. There are commands for a reason, sure there are a lot to memorize, but the only way you're going to do that is by doing it. Not complaining about the difficulty of the feat, not whining about a lack of skill, and certainly not by whining to others about problems that occurred and acting like it is their problem that something on your system broke and you weren't competent enough to fix it.

Buliding A Simple Game In Python3

In order to have a better understanding of the program that I am writing, I've decided that I would write a dead simple tutorial series on how to make a small game in Python. Links to all of my places of reference will take place as I find them.

Step 1: Setting up the script

There are two ways we can write this script.
-- As as executable. [Optional]
-- As a script to import into the interpreter so that we can update it as we go along. [Recommended, but also optional]

The first way is as such:

#!/usr/bin/python3

def function():
...


The second way:



def function():
...


And then simply execute it in the shell like so:

[~]> python3 script.py
Or Import it into the Python3 interpreter like so:
[~]> python3
>>>> import script
>>>>
Now, onto the actual coding..

#-- Say Game Title --#
print("---------------------------------------")
print("\nWelcome to \"Dineros\"\n")
print("---------------------------------------")
#-- Defining Global Variables --#
x_pos = 0
y_pos = 0

#-- Event Functions --#

#N/A

#-- Shitty Functions that don't really work --#

#def wall():
#    global x_pos, y_pos
#    if x_pos >= 10 and y_pos >= 10:
#        print("You hit a wall.")
#        x_pos = 10 and y_pos = 10
#    if x_pos <= -10 and y_pos <= -10:
#        print("You hit a wall.")
#        x_pos = -10 and y_pos = -10


#-- Main Game Function --#

# Define the function "move"
def move():
    # Refer to the variables we made earlier, not ones made locally.
    global x_pos, y_pos
    # Create an array of words that will be later used.
    where = ("\nWhere would you like to go?",
    "\nYou can go\n(N)orth, (S)outh, \n(E)ast, or (W)est.\n",
    "Or you can find out (wh)ere you are.\n")
    # Print objects from that array in the order as we need it to. We'll improve this later.
    print(where[0])
    print(where[1])
    print(where[2])
    # Create a prompt by which people know they are to type. 
    dir = input('> ')
    # If you put in capital or lower case n
    if dir == "N" or dir == "n":
        # Then the global y_pos will have 1 added to it.
        y_pos += y_pos + 1
    elif dir == "S" or dir == "s":
        y_pos += y_pos - 1
    elif dir == "E" or dir == "E":
        x_pos += x_pos + 1
    elif dir == "W" or dir == "W":
        x_pos += x_pos - 1
    elif dir == "wh" or dir == "WH" or dir == "Wh" or dir == "wH":
        print("You are at %d x, and %d y,\n" % (x_pos, y_pos))
    #If you didn't type any of the things above, then it will ask you to choose a direction.
    else:
        print("\nChoose a Direction.")
        exit
        return(dir)

#-- Conclusion Var. --#

# The variable that defines how it all ends.
ending = 1

#-- Game Running --#
# The condition for as long as this game is running
while ending == 1:
# The function we defined earlier
    move()
# The places to be when this is all complete [temporary]
    if x_pos == 1 and y_pos == 1:
# The thing that stops the loop and ends the game.
        ending += ending + 1 


The program is far from complete, but this is a good start to our character being able to move. Load it up and try it for yourself!

Initialization Method 1:

[~]> ./script.py


Initialization Method 2:

[~]> python3 script.py


Initialization Method 3 [OPTIONAL]:

[~]> python3
>>>import script

The Linux Command Line Interface -- System Navigation Tutorial [Part 1]

The linux terminal is a tool that can very easily simplify a lot of different tasks.

I'll be going over 3 system navigation tools, as well as the linux file system, though you'll need to open the terminal first.

Like so:


The key-bindings, distro-to-distro might be different. But on ubuntu it is ctrl+alt+T, the keybinding in awesomewm is actually mod4 + enter [Windowskey-Enter], and that is distro wide.

The Linux File System


The linux file system is a bit like an up-side down tree. It is universal in every linux distro.

A bit like this:


A bit more embedded details:

It is a hierarchy system of directories or "folders" as a windows user might term it. Though it doesn't have a C:\ for the top of all folders inside of the computer, instead, it has / [pronounced root but don't be confused by /root or the root user folder]. When people say "root" they're referring to what is known a "super user" or the highest system administrator imaginable on the system which is why protecting the root password is important. Dot files [.foo, .bar for example] are hidden files that can only be seen by using a specific option with a command. Options change the basic function or behaviour of the command in and of itself as we'll soon learn.

Click here to learn more about the linux file system.

Linux Commands


Commands in the CLI that come with bash, typically work like this:

[COMMAND] [OPTIONS] [ARGUMENTS]

For example:
ls -a /usr/bin

This will show all folders and all dot folders [like .foo] inside of the /usr/bin folder. Options will usually always have a dash (-) in front of them unless it is explicitly told as otherwise. You can use more than one option in a fashion such as:

ls -a -t /usr/bin

This will show all of the things inside of the folder according to their modification date. But that's not all. You can also combine options to form a "super option".

ls -at /usr/bin

 
ls


This is one of the most useful commands that you'll ever use. "ls" stands for List, which means to list all of the files in the directory. Try it out for yourself like in the image below.


This command is useful because it enables us to see what is inside any folder at any given time that the prompt is available and as a result allows us to see what is inside our system. You can use ls to not only see what is inside the current folder, but others as well.


And as you can see from this image, you not only can do one at a time, but more than one if you add them to your "arguments". An example of an option or two thrown in for fun:



cd

The letters "cd" are an abbreviation of the words "Change Directory". Let's say we had a folder called "books" in the home folder. Then all you have to do is type:




And you'd be in the "books" directory. That's all there is to it.

pwd

You know how to get to a folder, and how to see what's inside, but let's say you don't know where in the file-system you are? "pwd" is the answer. To implement it, do:




It'll print the full path in the system, which is pretty useful when you don't know where you are exactly.

Man Pages


To learn more about any command we learned above, and it's optionn, all you'd have to do is type "man [COMMAND]". That's all there is to it.

If there are any questions or criticism, feel free to comment.

Awesome WM Set up.

This is why I love awesome:


Sunday, March 24, 2013

Troubles With Learning Modules Python(2) -- Figured out.

In my last post, I had trouble figuring out why the Fibonacci Series wouldn't print. Then suddenly, after spending a bit of time studying and reviewing knowledge that I had acquired, I realized that the issue was in fact the line 6.

# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while b < n:
        print b,
        a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result 
 
Something as simple as this:
 
 
# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while b < n:
        print(b),
        a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result 
 
That pretty much solved everything for me.
 
Update:  Mon Mar 25 21:47:07

I realized that the issue was with the shell using python 3 instead of python 2. 
Python 2 still uses the print function in the way that I'm used to, python 3 does not.

Troubles With Learning Modules Python(2) -- Figured out.

In my last post, I had trouble figuring out why the Fibonacci Series wouldn't print. Then suddenly, after spending a bit of time studying and reviewing knowledge that I had acquired, I realized that the issue was in fact the line 6.

# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while b < n:
        print b,
        a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result 
 
Something as simple as this:
 
 
# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while b < n:
        print(b),
        a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result 
 
That pretty much solved everything for me. 

Harddrive Failure & The Troubles that Come With It

So, my last hard-drive failed, so I paid $20 to retrieve my old one and popped it in. I figured "It should work just fine if I just pacman -Syu." It had an older version of arch from like two months ago and everything. Then I realized that I had forgotten that it was a 32-bit harddrive! I had to pop the Archlinux CD into the computer and then update everything that was known on the system, as well as uncomment the multilib repository. But even then, that didn't stop the system from being buggy, so I just formatted the root partition and keep the home folder and all of my files. So now, my personal computer has become the project of the weekend. I hope I can get it done in time for some school work.

Trouble with Learning Modules in Python (2)

So, I was reading directly from the python Documentation, and on this page they present a code that actually creates the Fibonacci series:

# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while b < n:
        print b,
        a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result
 
 
This code has worked before, but this is the first time I've ever run into problems with it on the python
 interpreter.
I've actually typed it in manually at first, and then attempted to utilize this code, and got this error:
 
[python_prac_mod]> python 
Python 3.3.0 (default, Dec 22 2012, 21:02:07) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fibo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./fibo.py", line 6
    print b,
          ^
SyntaxError: invalid syntax
>>> 

Strange as hell. I even tried copy pasting the python code into the file and then saving it. 
That didn't work either. And despite my limited knowledge of python programming, I feel that this error is not
quite accurate. Oh, well, I'll have to look up another tutorial or something.

Friday, March 22, 2013

Frustration: AwesomeWM & My Use of Dvorak

Seeing as I have this lovely devotion to the DVORAK keyboard layout (to the extent that I literally rearranged the entire keyboard, upside down keys and all, specifically to facilitate this need), I tend to get extremely frustrated by what seems to be a bug in Awesomewm.

At first, it was just a minor annoyance, and then gradually it became a bit more than a nuisance as I literally have to reach into my 3 - 5 years of qwerty knowledge in order to remember what which key was supposed to be. Mind you, I've memorized the Qwerty and Dvorak style because there are those times in school where I have no choice but to use it.

This is all besides the point,

Which is that awesomewm is a great Window Manager but it doesn't seem to keep to anything I tell it to, which is extremely frustrating when I have to type Mod4 + R. I've looked into Xorg on the archwiki, amongst other things in the AwesomeWiki, but it seems that the only thing that ever solves it is restarting awesome after typing in "setkbmap dvorak" into a terminal. Thankfully, I have zsh, and that helped me through a lot of the worries because once I find the "s" on the keyboard (Which is right next to a for those that are wondering, where it used to be on Qwerty), I just had to press the up arrow key and found what I wanted.

If I find a solution for this, I'll write up a tutorial.