Sunday, December 1, 2013

Ubuntu software installation

apt-get moo
So, you've decided to install Ubuntu.  Good for you.  Now let's install some software.

Installing pre-compiled packages in Ubuntu is actually pretty straightforward, but finding your software can be confusing.  Let's say you wanted to install Chromium, Google Chrome's open-source equivalent.  Do some research and check if the software is available for Ubuntu.

If it is, open up the terminal and type apt-cache search chromium (or apt-cache search packagename).  This searches your local repository cache for packages related to the search query.  You should see a package called chromium-browser.  That's the name of the package we need to install.  
Do you see it?

To install a package, type sudo apt-get install packagename, or in our case, sudo apt-get install chromium-browser.  You need to type the package name as it appears in the apt-cache results.

If you want to install another package, I recommend gnome-games.  If you want to listen to MP3 files or watch DVDs or something, you should check out the Ubuntu page on Restricted Formats and install the package they recommend.

Sunday, November 24, 2013

Java is OK

The typical entrenched C++ developer when asked about Java
I'm sure you've heard the alarmist headlines.  The intertubes are clogged with articles titled things like "Java is Insecure and Awful, It’s Time to Disable It", "Homeland Security warns to disable Java amid zero-day flaw", or "Uninstall Java Now!".  This modern day witch hunt is entirely groundless.  Java is not, as some may have you believe, inherently insecure.  Java's only long-standing security hole is that its users refuse to update to the latest version and instead insist on sticking with software that came out in 2006!  I'm here to say "relax! Java is OK".

C++ developers decrying Java as insecure is a paragon of hypocrisy.  Because Java doesn't permit access to memory management or pointers, a whole class of bugs and security flaws are rendered impossible.  For example, let's say we have an int array called arr that is 5 ints long.  In C++, it's perfectly legal for us to reference the value arr[-1] (http://ideone.com/JFrEnm), but in Java such a silly statement is automatically decried as an exception (http://ideone.com/Ah1kLn).  The reason is that Java abstracts away the subscript operator (the "hard brackets" []) as a function call that fetches the given index from the internal array implementation, whereas the C++ subscript operator performs simple pointer arithmetic.  In C++, arr[3] is identical to *(arr + 3) (http://ideone.com/JFrEnm).  The second statement evaluates the address that the arr pointer refers to and adds 3 to it, then dereferences (gets the value at) the new memory location.  So in C++, arr[-1] just refers to the value held one unit before the address that arr points to.  It's crazy that this is allowed, because THERE IS NO WAY TO KNOW what is held at a memory location beyond the bounds of the array!  If this is ever used in real code it's a bug or a hack.  Even if out-of-bounds values weren't permitted with the bracket notation, C++ programmers could get around this by doing pointer arithmetic, but there's simply no way to do this in Java.

"If you have Java installed and want to ensure that your system is secure, Oracle strongly recommends that you upgrade to the most recent release."

Similarly, Java throws an exception if one attempts to use a null (uninitialized) pointer (http://ideone.com/dr8enx), but it's perfectly legal to do so in C++.  Furthermore, "dangling pointers" are almost impossible to create in Java but are commonplace in C++.  Memory leaks are nearly as rare in Java because of the almighty garbage collector.  I can't think of a way to create a buffer overflow in Java (that is, I think if an unchecked buffer overflow occurred the program would just stop), which covers a wide variety of holes (please feel free to correct me on this).

Lucifer, the quinteſſential demonic being
Pseudo-pundits would have you believe that if you use Java your daughters will start dancing naked in the woods, engage in ſinful behaviors and conſort with ye demonic beaſts.  This madly anti-Java mindset is likely fueled by ignorance, and is evocative of the misguided Reverend Parris from Arthur Miller's The Crucible.  Those unfamiliar with Java denounce it as riddled with security holes because they do not believe themselves capable of learning a new language.  Like Parris, if they fear they are losing control of a situation, they spout wild and unfounded accusations to prevent their own inadequacy from coming to light.

The largest Java security vulnerability is the fact that most users are running Java SE 6, which is no longer supported by Oracle (see http://en.wikipedia.org/wiki/Java_version_history).   You can't blame Oracle for pulling support from a version of Java that came out in 2006!  People, you need to update your freakin' Java!  The update dialogs are annoying for a reason.  Later versions of Java are well supported and actively developed by the good people at Oracle.  From the Oracle website: "If you have Java installed and want to ensure that your system is secure, Oracle strongly recommends that you upgrade to the most recent release."

Anyone looks like a witch with a carrot on their nose
Java's critics may try as much as they like to pin the update carrot on Duke's almost immaculate nose, but truly skilled programmers will see through their fallacious argument and simply update their Java versions rather than join in on the witch hunt.  I urge you, as John Proctor urged the people of Salem in the Crucible, to see through the lies.  In the meantime, though, it wouldn't hurt to update Java.
Evil Witch or
Versatile programming language?

Wednesday, October 30, 2013

My github projects

I've been working on some github projects lately.  You should check them out at http://github.com/macsj200.

Sunday, October 27, 2013

Pan-American Stirrings

Good ol' Che

Ernesto "Che" Guevara was a dreamer.  An Argentine medical student turned revolutionary, he saw a better life for the once-great, now-downtrodden indigenous Latin American peoples.  In his politically-tinted autobiography, "The Motorcycle Diaries", Che offers a poignant firsthand account of the plight of his fellow Latin Americans.  Accompanied by a fellow medical student, Alberto Granado, Che traveled through the many countries of South America and was metamorphosed by the things he saw.  "The Motorcycle Diaries" is an account of that journey.

"The Motorcycle Diaries" is an impressively purposed book. Che wrote and published this autobiography to instil Pan-American communist sentiments in his fellow Mestizos.  Che believed the only way to achieve equality was to have a people's revolution; he explains this in "The Motorcycle Diaries".  He wrote this book to promote his ideals and to unite Latin America.  

This book was released during a time of turmoil in Latin America; political ideologies were being formed and implemented faster than the common man could keep up with, so Che published this book as a manifesto for the average Peruvian, Bolivian or Mexican.  Che wrote this using vernacular ("che" is Argentinian slang) language and Latin American idioms.  The fact that the original copy was written in Spanish makes it abundantly obvious that Che wrote this for downtrodden Spanish-speaking Latin Americans.  Che's style is an impressive one; he makes effective use of varied sentence structure and interesting vocabulary to keep the reader engaged, and he often mixes Spanish and English to create more accurate phrases or words.  Che's ability to subtly insert politics into his writings is a skill every political author should wish for.  Throughout the book, Che maintains an inflammatory if not revolutionary tone.  The point of this book was to make the plight of the common Latino abundantly clear, and to stir the reader to revolution. 

Over the last two weeks I read "The Motorcycle Diaries".  Overall, I enjoyed learning about 1950s Latin American culture and Che, but the book read more like a long description of scenery and social milieu than a story.  Therefore, I propose a new rating system: storypoints.

Storypoints are earned when a book effectively engages a reader through snappy dialog, interesting character development, nail-biting action scenes or various other storytelling devices.  A piece of writing that receives 0 storypoints is strictly informative or extremely boring.  Writing with 0 storypoints gets the Lorem Ipsum award (named after the famous boring and meaningless boilerplate text).  A literary creation that receives 10 storypoints earns the Maxwell's Worth Reading Award (shortened to Maxwell's).  A book that gets 20 storypoints is extremely riveting and earns the Harry Potter award.

Che's writings are, inherently, political, but he does not shove his agenda down the reader's throat.  Rather, he peppers his anecdotes with incisive political insights.  Che is ardently anti-establishment; he makes this clear through his bitter reprisals of Spanish conquistadors and the established ruling class.  Che uses carefully selected vocabulary to urge the reader to empathize with the "exploited" and "noble" native and hate the "idiotic" Spaniards that originally conquered Latin America, and the class that descended from them.

Che saw almost everything through a colonial lens.  He believed that all indigenous and mixed-race Latin American peoples were part of a larger "mestizo" class that had been beaten down and subjugated by foreign conquerors.  When describing the average Peruvian, Che regards them as a "once proud" race that was "defeated...by illiterate Spanish conquistadors".  Che makes his opinion of the Spaniards that first came to Latin America abundantly clear through his use of scathing adjectives like "idiotic", "banal", and "unfeeling" and by explicitly condemning them and all repressive authority figures.

"We constitute a single mestizo race, which from Mexico to the Magellan Straits bears notable ethnographic similarities.  And so, in an attempt to rid myself of the weight of small-minded provincialism, I propose a toast to Peru and to a United Latin America."


Alberto and Che in the movie adaptation
Che's anecdotes are interesting, sometimes dangerous and often comical.  Che described speeding through beautiful Latin American scenery with abundant clarity, earning him two storypoints, bringing him to a grand total of two so far.  He did describe a motorcycle crash (a few, actually), which would earn him storypoints except he glosses over the action and focuses more on "the beautiful gravel bend, by a little bubbling stream" that he fell on rather than the fall itself.  Because of the imagery there, I'll grudgingly give him another storypoint I suppose.  Che was an admirable elocutionist, and in his autobiography he offered many rousing speeches to the commoners, so he earns a storypoint there because said speeches are just so moving (see quote above).

Che and Alberto picked up various odd jobs to fund their passage through the South American continent.  During one of these jobs, Che worked for "a very strange person..whom [he] addressed with the utmost respect as Señora".  This "Señora" turned out to be a man.  Two storypoints for laughs.  Che also described how he and Alberto "executed a carefully calculated plan" to steal wine from their employers (another storypoint for attempted humor).

Che had a way of making the reader feel as though they are on his journey with him.  He described his intense hunger, cold and general discomfort in such a way as to make the reader empathize with his discomfort (a not entirely pleasant experience).  On a particularly unpleasant boat ride, he explained "the mosquitoes swarmed around us in clouds, worse than ever, as if taking their revenge on us for the fact that we would soon be out of their reach".  Because of this talent, I'll give him another three storypoints.


Monday, October 21, 2013

Python Intro Part Deux

Salutations!  If you're a returning reader, it's certainly nice to have you back.  If not, welcome!  You may want to look over the first portion of this tutorial.  This second portion will primarily cover Python function definitions.
A "function machine"
Functions are groups of instructions.  An example of a function in Plain English (tm) is "for each given value, double it".  The mathematical equivalent of this phrase is y = 2x.  In programming, we can define functions to do much more than simple math, but function notation in programming is based on mathematical notation so it is useful to reflect on this temporarily.  Now, let's get you defining some functions!

In Python, functions are defined by using the def keyword.  Here's an example of a simple function:
def double(n):
    return n * 2

double(5) returns 10

The above code saves the argument to the variable n and returns (spits out) n doubled.  So calling double(10) would spit out 20.  Functions can do more than math, however.  We can pass strings (a chain of characters) to functions and output data based on their values.  For example, let's define a greeting function:



def greet_user(username):
    print "Hello " + username + "!"
Let's try calling that function with a name:

greet_user("Max")

The above code will print Hello Max! to the console.  We can call functions with variables as well, not just with literals:
def chastise_child(childname):
    print "Stop that " + childname + "!"
first_child_name = "Freddy Mac"
second_child_name = "Fannie Mae"
third_child_name = "Barack"
chastise_child(second_child_name)
chastise_child(third_child_name)


The handy thing about functions is that you don't have to retype code every time you want to perform a similar action.  You might want to perform a complex operation on many different input values, and now you can with functions!

You can also define functions that take more than one input:
def multiply(first, second):
    return first * second
print multiply(5,10)
Inputs are separated by commas.  When passing values to a function with many parameters, order matters!  Consider this scenario:
def childinfo(name, eyecolor, age):
    return name+" has "+ eyecolor+" eyes and is "+age+" years old."
print childinfo(15, "John", "blue")
The output of that function call would be 15 had John eyes and is blue years old.  As you can see, getting the order of your parameters correct is imperative.

Sunday, October 13, 2013

Che's Challenges

Reading Che Guevara's translated autobiography has been an interesting experience so far.  It is quite evident that the author has some strong political thoughts and wishes for the reader to subscribe to his ideologies.  Che attempts to appear as though he is offering a fair and balanced point of view by self-critiquing, but when he reprises his ideology he uses phrases like "Were we too uncompromising...?".  He also recriminates supervisors and glorifies laborers.  On the oceanic leg of Che's journey he compares the "drunk captain" with "the sailors, who were the best".  Che obviously detests the "absurd idea of caste" and sympathizes with the plight of the honest, healthy, hardworking, average South American.

Che wrote this book to stir his fellow South Americans to action, or at least political consciousness.  The book is peppered with colloquialisms and Latin-American cultural idiosyncrasies that necessitate footnotes to clarify Che's metaphors or parables to outsiders.  Furthermore, the book was written solely in Spanish and only distributed to Latin Americans.  Che attempts to enlist the reader's emotions for his own cause by describing the plight of average Latin American workers, laborers and poor.  The author assumes the reader will empathize with Che's examples of the downtrodden worker because the reader is a downtrodden worker or lives in close proximity with one.  Che's message would not be nearly as powerful if he did not include these cultural familiarities with which the intended reader likely identified with.

Che is an expert in argumentation.  He subtly utilizes Ethos by offering a firsthand account of the corruption and classism of South America.  He offers a Bathos-ic appeal by describing how peaceful things were before governmental and societal exploitation of the common worker and illustrates a glorious future in which egalitarianism in all its glory is restored.  He uses Pathos by describing desperate situations that the reader might find himself or someone close to him in.  Peers are easier to empathize with than any other social group, and Che knows this.  Che obviously resents capitalism, governmental and societal corruption and despotism, and desperately wishes to overthrow the current system and install a more equal society.  Through effective argumentation and a compelling message, Che attempts to spur the common man into action and political revolution.


Saturday, September 21, 2013

Ender's Endeavours

In my experience, not everyone has a favorite book.  Sure, the general population has a generic, societally approved, run-of-the-mill book in the back of their mind for dinner parties or interviews, but hardly anyone has really connected with a book in the same way I have with Ender's Game by Orson Scott Card.  It is the ultimate example of overcoming adversity and rising to a challenge, it paints a vivid picture of its characters, and it offers a powerful message.  It is, quite honestly, the best book I have ever read.

Andrew "Ender" Wiggin, the protagonist, is unwanted by society.  He is a "thirdie", a third child, in an overpopulated not-too-distant future world that permits only two children per family.  He is horribly downtrodden in much the same way as modern-day minorities.  Outwardly meek and small for his age, he is constantly tortured physically and mentally by his peers and his psychotic-but-genius older brother.  In spite of his underdoggish appearance, he is recruited by the military to be a commander in a genocidal war against an alien race known as "the Buggers".  Training proves even worse than normal school.  The other cadets recognize his commanding brilliance and hate him for it.  After many fights and bouts of severe depression, he eventually convinces the entire military organization (fellow trainees included) through his remarkable tactical acumen that he has what it takes to save humanity from the alien menace.  When he is only ten years old he is given command of the military's interstellar fleet and destroys the Buggers' homeworld and is immediately rendered a hero, but he could never have done it without his family, instructors and supporters.

Ender was only able to conquer the enemy because of the people close to him, and this is made evident by how much attention Card gives to almost every character in the book.  Through the use of snappy dialogue, subplots, and sight into each character's mind, the reader becomes intimately familiar with Ender's immediate subordinates that double as friends, his siblings and his instructors.  A good piece of writing should make its readers care about not only the main character, but all of the characters around him; in Ender's Game the reader is moved to care about even Ender's psychotic older brother.  The secondary characters in the novel are astoundingly three-dimensional; it is obvious Card loved them just as much as he loved Ender.  The book is made intriguing because the reader empathizes so well for all of the characters, but the true power and universal message of the novel is revealed when this empathy is cast upon the race that Ender exterminated.

The Buggers are revealed to be simply different from humanity, and not evil at all.  Initial clashes between Humans and Buggers came about because Buggers communicate telepathically and have no concept of writing, speech or any other form of human communication.  Humans feared their nightmarish appearance and ascertained from their silence that they intended us harm; the Buggers drew a similar conclusion and total war was initiated.  Through a stroke of luck humanity defeated the Buggers, but always lived in fear that they would one day return, so we sent a fleet of starships to destroy the Bugger homeworld before this attack could be launched.  The Buggers never intended to attack again when they realized that Humans were sentient and did not deserve destruction, but humanity pressed onwards with no reflection on the nature of their enemies.  Thus an entire race was exterminated because of rash decisions and lack of empathy.  This lesson is applicable in every context, not just in fiction or even in war.  Empathy should always be used before aggression.

A truly great book should hold a timeless lesson, be intriguing and fast-paced, and should have an entire host of characters to care about rather than just one.  Ender's Game embodies all of these parameters and more.  It's underdog premise and sci-fi setting supply a page-turning and remarkably original plot, its characters could all have stories of their own and it teaches us to feel for others.  Ender's game is a masterpiece, and everyone should read it.

Friday, September 6, 2013

Intro to Java

A while ago, I wrote a series of Java tutorials.


To see the rest of the tutorials, navigate to https://drive.google.com/#folders/0B11WQbRQEj5FREllbmJoX2VGaEk.

Python Intro

repl.it
So you've finally decided you want to learn to program.  Or maybe you know how to program but you want to learn Python.  In either case, this tutorial is for you!  This is for complete Python beginners.



Python logo
Before you can write and use any Python, you need to find an application that will run your code.  For expediency's sake I will skip over installing and running Python natively; we'll use repl.it (a free online interpreter) instead.  This guide is written for Python 2, so if you have Python 3 installed just use repl.it.  Navigate to repl.it, click the languages button (the leftmost button in the top right corner of the screen) and set it to Python, then click anywhere in the area of the screen on the right side with the blue background.  Now let's write some code!

To start off, type:
print "Hello world!"
and press Enter.

You should see this:






You just added to a 41 year old tradition and wrote your first Python program!  Well done.
The "Hello World" example illustrates the usage of Python's print statement.  To print a string (a collection of zero or more characters delineated by quotation marks, like "Yolo swag", "hello", "5.24" or "D"), type print followed by the phrase you wish to print enclosed in quotation marks.  Here are some more examples of print:
print "Size matters not - Yoda"
print 42
print "It's a great day to be alive!"
Play around with the interpreter.  See what works and what doesn't.  Try printing numbers, fractions or punctuation.  Try using single quotation marks on strings.

Python (like every other good programming language) lets us save values to variables for later use.  Think of a variable like a box.  A box can hold books, toys or video games and a variable can hold strings, integers and doubles (plus much more).  To save a value to a variable, type a variable name followed by an equals sign (=) followed by the value you wish to save.  For example:
x = 42
Now the variable x holds the value 42.  We can verify this by printing x:
x = 42
print x
You can print variables in much the same way that you can print numbers or strings.  Try the above example, then play around with the interpreter.  Here are some more examples to help you get the hang of the syntax:
the_answer = 42
price = 1.95
userName = "macsj200"
x = price
elephant_name = "Dumbo"
Try setting x to a different string, or a number.  Try creating other variables.  Try setting x equal to another variable.  Try printing variables before you create them.  Use the print statement to see the results of your actions.

Python variables must start with a letter and be only one word, but other than that name then whatever you want.  It is a good idea to get into the habit of giving your variables meaningful names, like speed or priceOfIitem or number_of_cans instead of x or zs.  Food for thought: what is the difference between print x and print "x"?

Click here to go to Part 2

List Comprehensions in Python

Python logo
Why hello there fellow netizens!  It's good to finally have been forced to start a blog because I certainly have a lot to share with the world.  This post will serve to be a short expose on a wonderful feature of the Python programming language (named after the t.v. show "Monty Python's Flying Circus") called List Comprehensions.  It's essentially a severely under-appreciated extension of Python's famous lists.  Before we jump in to the rest of the post, I suggest you familiarize yourself with Python lists using my demo on repl.it or the official Python docs if you don't already know how they work or need a refresher.


Ok, now let's start comprehending some lists! Say we have a list, x_list, that contains [1, 2, 3] and we want y_list to contain the value of each element of x_list squared.  That is to say, we want y list to contain [1, 4, 9].  Python makes this a very easy task indeed.

We could do it the schmuck way with a for loop:
x_list = [1, 2, 3]
y_list = []
for n in x_list:
    y_list.append(n * n)
print y_list

But, of course, Python supplies us mortals with List Comprehensions (a delightfully abbreviated syntax):
x_list = [1, 2, 3]
y_list = [n * n for n in x_list]
print y_list

Both versions print [1, 4, 9], but the List Comprehensions version is indisputably more elegant.  One thing I fail to understand is why the developers decided to make "Comprehensions" plural, but such is life.