Messing with Perl


sub zipper {
my ($left, $right) = @_;
my @larr = @{$left};
my $lsize = @larr;

my @rarr = @{$right};
my $rsize = @rarr;

if ($lsize != $rsize) {

die "Array sizes are inequal.";

}



my @AoAr;

for (my $i = 0; $i < $lsize; $i++) {
push @AoAr, ($larr[$i], $rarr[$i]), "n";
}

return @AoAr;

}

Earlier I decided to make a zipper subroutine in Perl. So far it works. Results:


$VAR1 = 'Pat';
$VAR2 = '1';
$VAR3 = '
';
$VAR4 = 'Sean';
$VAR5 = '2';
$VAR6 = '
';
$VAR7 = 'Dante';
$VAR8 = '3';
$VAR9 = '
';
$VAR10 = 'Dustin';
$VAR11 = '4';
$VAR12 = '
';

I also devised a dot product using two maps:


my @dotproduct = map {my $z = $_; map {$z . ' ' . $_}
@surnames} @names;

Results:


$VAR1 = 'Pat 1';
$VAR2 = 'Pat 2';
$VAR3 = 'Pat 3';
$VAR4 = 'Pat 4';
$VAR5 = 'Sean 1';
$VAR6 = 'Sean 2';
$VAR7 = 'Sean 3';
$VAR8 = 'Sean 4';
$VAR9 = 'Dante 1';
$VAR10 = 'Dante 2';
$VAR11 = 'Dante 3';
$VAR12 = 'Dante 4';
$VAR13 = 'Dustin 1';
$VAR14 = 'Dustin 2';
$VAR15 = 'Dustin 3';
$VAR16 = 'Dustin 4';

Another fine example of bad programming. Now here are some things I should have learned way earlier:

  • Lists are not the same as arrays. Arrays are filled with scalars. Lists have objects of some sort.
  • Lists don’t really have a scalar context. It resolves to their last element.
  • Changing from an array reference to an array is way too clunky. Is there a better way?

How to Run Minecraft Forge on Ubuntu Client and Server

What I’m using as a client

  • Ubuntu 12.04 (Precise)
  • Minecraft Client 1.3.2
  • Minecraft Forge 4.2.5.303 (Link here)

Client steps

  1. Create a backup copy of the installed copy of ~/.minecraft/bin/minecraft.jar
  2. Create a temporary directory “mc”
  3. Copy your installed copy of minecraft at ~/.minecraft/bin/minecraft.jar to mc
  4. cd inside mc, then run jar -xf minecraft.jar
  5. rm minecraft.jar
  6. nautilus ..
  7. Open the minecraft forge file 
  8. Extract all the minecraft forge files into mc, they will overwrite files
  9. Run jar -cf minecraft.jar .
  10. nautilus .
  11. Open minecraft.jar and delete META-INF/ now
  12. mv minecraft.jar ~/minecraft/bin/minecraft.jar
  13. Start minecraft from your minecraft loader (confusingly also named minecraft.jar)
  14. If you receive a pop-up saying something like, “FML needs to setup your environment,” then all is well.
  15. Put mods into the generated ~/.minecraft/mods directory.

Server steps

  1. Create a backup copy of the installed minecraft_server.jar
  2. Copy the minecraft_server.jar locally into a temporary directory “mc”
  3. Make sure its empty from the client jar.
  4.  jar -xf minecraft_server.jar
  5. rm minecraft_server.jar
  6. nautilus ..
  7. Open the minecraft forge file
  8. Extract all the minecraft forge files into mc, they will overwrite files
  9. Now, you will keep the META-INF/manifest
  10. jar -cmf META-INF/MANIFEST.MF minecraft_server.jar
  11. Put the minecraft_server.jar back onto your server and copy it over your installed minecraft_server.jar. It’s a good idea to do a cksum on your local computer and on the server to make sure nothing was lost in transfer.
  12. You should be able to run your server as normal. Run it once, then put your mods in the generated mods/ directory.

A Fork in the Road

Lately I’ve been trying to find a career related field that I can work in while in college. Mostly, that means perusing job listings for junior developers within a fifty mile radius when I ought to be working at my present job. 🙂

Most of my work has been mere dabbling, and the realization that I have programming commitment issues makes my skinny portfolio a glaring problem.
I’m stuck between desktop or server applications and back-end web design. What should I do? How do I choose when I actually have no preference?
I have the most experience in Java SE and PHP. Maybe I’ll pick up a little Java EE or JSP with Apache Tomcat.

Update: I’ve decided to take the advice from the experts over at Stack Overflow and finally just program at my own whim. I focus on my future career, sure; however, I do not believe I should limit myself based on what recruiters, bosses, clients and others want from me. I’ll write in PHP when I feel like it. I’ll write in Java when I feel like it.

In order to cure my aimless programming, I’ve decided to build a small portfolio. I’ve come to the realization that it doesn’t matter what I make as long as I make it. In the future, the management can determine what I make for pay. For myself, the best code has been created in order to scratch an itch.

How can a stupid matrix help me?

Pursuing a degree in Computer Science is much different from learning to program as a hobby.

Now, I’m forced into revisiting math.

Oh yes, my best enemy, Mathematics.

I can point fingers at everyone else all day, but it won’t solve my problems.

Let’s look at at least one practical mathematics application.

What is a matrix?
          A matrix is simply a series of numbers in a rectangular form. By itself, it seems like a very useless way of representing a group of numbers. However, there is nothing in advanced mathematics that is immediately useful like matrices, as you will soon learn!

Here is an example of a matrix:

What is an augmented, coefficient matrix?
         A coefficient matrix is simply a matrix whose numbers represent coefficients of variables. Consider the following:

x sub 1 through 4 can represent any number.

         It’s not necessarily important to us because they are placeholders. Instead, we take the coefficient of each placeholder and place it into a matrix. The coefficients are significant because they are known. We can find simpler, equivalent coefficients to create simpler, equivalent equations for our problems.

         An augmented, coefficient matrix sounds complicated but is really very simple. An augmented matrix means that it is in fact an equation. The vertical line next to the 0 represents the equals sign in the original problem. We will omit this in the future.

This is too much mathematical jargon for me, so you just be tired by now. Let’s look at a real application to make this practical.

How do you balance a chemical equation with an augmented, coefficient matrix?
         Here’s a simple, unbalanced chemical equation for you:

Identify the rows and columns
              In our case, we will use vectors at first to represent the chemical equation. Each column will represent a part of the chemical equation, whether it is reagent or product is of no concern to us. Each row will represent how many of each atom there is in that particular part of the chemical equation.

              Let’s translate this chemical equation into a series of vectors.

Note that these two equations are equivalent. However, the second one is the most useful to us for finding a solution. It’s necessary to move the products to the left, producing a vector of zeroes on the right.

You’ll quickly realize that -1 and -3 represents that there are 1 Fe atoms and 3 Cl atoms in that part of the chemical equation. It is negative, because it is a product.


Plug in the values
              Using your handy dandy calculator, enter the following matrix:

Bring to Reduced Row Echelon Form (RREF)
              Use matrix operations to bring the former matrix to RREF:

Present the solution as a balanced equation
              So, what the hell does this solution mean? We’ll need to do some additional processing to make this useful. Remember that this is a coefficient matrix and that the coefficients are ignorant of what they are multiplied by.

              The first row means: 1×1 + 0x2 – 1×3 = 0. We want to find out what x1 is (or the coefficient for Fe). Solving for x1 means x1 = 0 – 0x2 – 1×3. Or, x1 = -1×3.

Completing this for the rest of the coefficients produces the following:

Notice that I made x3 = -2, which is the smallest number that makes the other coefficients whole numbers.

We can finally write the solution as:

Wow, that was tougher than it needed to be
              Maybe for now. However, you will find that longer equations are easier to solve via this method. Here’s an example done for you:



Using Matrices for Network Flow Diagrams
          Ever wanted to find out the rate of flow of traffic in an intersection? Here’s a nifty way! 


  
Understand what’s going on here? No? Good, me neither. Wait, nope. Looks like we have a simple intersection, A, of two one way streets. 

In the North direction, we have a variable going South.

In the West, we have a constant, 10, going East. 

West and South lead outwards, with one a constant and the other a variable.

Write a row for every intersection with the in and the out flows separated. The in and the out will always equal one another in this type of system. 


You must solve for the constants, essentially. You always want the constants on the right. After writing the resultant linear equation as a matrix, you can see that it is already in RREF. After identifying the free variables (x2) and describing the non-free variables (x1) with the free variables and the constants (x1 = 10 + x2), you have the general flow pattern of the system.


In otherwords, if we observe 30 people come through x2, then x1 must equal 40.


Like the chemistry problem, this can get a lot more complicated.


Here’s some additional examples!





Problem-Solving with Matrices in Java
This class will RREF a matrix. It is on Rosetta Code as well. This requires Apache Commons 2.2. It’s a simple install.


Under Construction, ladies and gents 🙂 I’ll be building more.


Some Extras
For anyone interested, here’s the LaTeX file I used to create the above images.


Why Learn to Program?

Programming has been my hobby since I was age 14. It’s been a part of my life for a long time now, and I don’t regret it one bit. I think most people find programming to be a laborious or boring topic. Why? They don’t understand how intricate and beautiful it is to create a piece of software, like something they use almost every day.

The sense of success after making a well-developed program is unparalleled for me. I feel like I’ve built something timeless, an idea or a method that anyone using a computer could benefit from in my situation.

Trying to explain why a computer program is beautiful is like trying to describe how a computer generated flower is in many ways much more incredible than an actual flower. By making it so intuitively realistic, it is a feat in itself to reflect what we know is real.

I feel bad for the programmers who learned only in the classroom how to perform their trade. The rigorous deadlines and fast pace of an academic environment don’t really make programming seem like a fun and fascinating puzzle which only gets more complex as your expectations rise. Programming as a hobby means programming for its own sake, because it is enjoyable, and having this tool means something more.

A programmer should make at least one program that they themselves use.

First Post!

I’ll use this blog as the donkey to my King Midas. You, my fair reader, have stumbled across the finest in a collection of bad programming and bad programming tips.

Enjoy!