Wednesday, January 1, 2014

Happy New Years! - 2014 Resolutions and Reflections on last year. How the blog got its title. - Wait I am a human?!

At almost a year since I started this little pet blog on a whim in stack overflow's Android chat room I was looking for a place to keep all my notes on programming so I was trying to think up a clever name for a blog. Someone noted to me to look into things I like when coding. Well I love coffee and I always talked about how I "Run on coffee and live on ramen." So runs on coffee was made.

I have come so far in this last year time...
I have taken my hits as well...

A few months ago I had to go back and spruce up some of my old android code for a review and my old code is atrocious all things considered. Like learning any language its just that learning. In programming instead of learning where to put your comma's you learn were to make methods to be called upon later.
On the whole I feel I have gotten better but all the same I have so much more to learn. Oh well life is a learning experience in and of itself.

I found love - I used to think it would just walk through the door and make itself known when it felt the time was right. Well I was right to a degree I met a wonderful girl last year named +Samantha Howell and she has been the core focus of my personal life for the last 9 months (On the 12th) Thanks for sticking it out with me so far Babe!

I have met so many new people this last year... One who I would like to note in this mix is +John Blanton+John Spartan and I started a small tech show on Youtube called "The local host show" However that fell through when John's iMac died on him. We are however working on reformatting and bringing the show back to life. #lhs2k14

+John Spartan has been a motivating factor in my life for somewhere around 2.5 - 3 years now. Although his work and so on takes him away from us at random points in time. I remember spending whole nights on Team Speak with him Murphy and Oddball joking laughing and having a good time while occasionally shooting around on Medal of Honor Allied Assault.

I should also take this time to mention another good friend of mine on the internet +Leslie Griffith who has helped me through more issues than I can count (My computer might be able to but I cant) Leslie thank you for being there.

Last year seemed like it was one hit after another. My family  and I agree that in terms of crap-tastical years known to us 2k13 takes the cake. While some good came of it there was allot of pain involved... Between dealing with eviction and getting stripped down to the bare bones of what I needed to keep on me it was rough. Thankfully I have a roof over my head and food to eat. So I bounced back and got an upgrade to my WiFi in the process. Granted my bed is still on the floor and I have no privacy since my "Bedroom" is in one corner of the basement. But there is good to it as well: I now have a second computer hooked up to a 32 inch flat screen on my dresser. Nothing like watching Walking Dead from the comfort of my bed. As well I also have a nice little electric fireplace next to my bed. I cant say it helps warm anything up but it does help make a nice glow to fall asleep to.

Resolutions:

  1. Get better with coding
  2. Get certified for coding - Android / Java
  3. Try to bring back LHS
  4. Generally be a better person.
  5. Try to be more positive.


So we take the good and the bad and we just say "Lets just live life..." And so I am closing out 2k13 with this... Life got uprooted... We adjusted and moved on... We came back while saying
We will not go quietly into the night,
we will not give up without a fight...
The aliens are here...
They drank all our beer,
and they traveled much faster than light!!"
- Wait no... That was the ending of the alternate speech from independence day.

Inref:

I would like to end it by saying this:
To all of my friends and family I would like to wish you all a happy new year and may the best come to you.

-Alex







Monday, December 16, 2013

[NEWS] "OK Google" has been released for google chrome desktop. - After a good while of absence (9 months?!)

Yeah that is right kids, now you can feel like Tony Stark while running google searches!

Hope you all enjoy using this feature while its not as useful as the android version. I suspect soon we will be able to push reminders from the desktop to the tablet / phone interface soon enough!

- I would like to note that soon I will be getting back to writing Java;Notes and Likely make a corresponding Youtube series about it. A few things have changed since I started writing this last year. Mostly just IDE stuff. I am now proudly using IntelliJ IDEA for an IDE. I am in love with this IDE as it makes things flow MUCH better that eclipse or even netbeans. Not to mention Google is porting over to a custom version built just for android.

So, I am back!
-Alx

PS: Time to work on twitter integration!

Wednesday, March 27, 2013

Java;Notes - 14.) Formatting Output

In Java the best way to format an outcome in terms of numbers is to use the "printf" function So it would look something like this:

  1. System.out.printf("Hello %s, next year you will be %d", name, age);
This is the conversion chart for printf:

Here is the Flag chart for printf: 
Note: You can use multiple flags with printf so long as all negatives are enclosed in parenthesis.

Telling date and time:
Since we are experimenting with printf we can also use it to print out the date and time like so:
  1. System.out.printf("%tc", newDate());
Here is a helpful chart for Date Conversions under printf:



One last graph for printf format specifiers syntax layout:



Java;Notes - 13.) Input and Output

Made simple, Input is the act of gathering data from users. As well output is displaying that data. To do this with a terminal is really really simple:

Getting Input(Johny5) and Giving Output:
In order to get input we use a thing called a Scanner which basically takes input from the system and stores it into a scanner variable Here is how to use it:

  1. import Scanner
  2. Scanner input = new Scanner(System.in)
  3. System.out.print(What would you like to output: ") // This causes the cursor to show on this line
  4. String inStr = input.nextLine();
  5. System.out.println(inStr);
Here is the above example in use:

Java;Notes - 12.) Fun with Strings

As you have seen in some of my programs the use of Strings is nothing new. It really helps to be able to use them to make things make more sense. As was a great example two posts ago about rounding numbers either up or down. Had I not added the strings explaining what each output was and had I not shown the code the numbers would have just been numbers. Big whoop anyone can print out numbers its as simple as:

  1. int x = 4;
  2. System.out.println(x);
Or if your really lazy:
  1. System.out.println("3.14159");
Not the last one was a string that was created in the moment. The kinds of strings we are going to be reviewing now are likely a mix of the above and the kinds of strings that hold their own variables and meanings.

To make a static string all you need to do is either of the following:
  • String e = ""; // this will create an empty string which can be useful if you want to input something.
  • String greeting = "Hello!";
Call out the function (String)<Variable> = {Meaning}
Creating strings is not a hard concept to grasp... however what comes next might take a little brain work.

Substrings:
A substring is basically using one already made string to make another one using the characters provided in the main string. Like so:
  • String greeting = "Hello!";
  • String s = greeting.substring(0, 3) 
This will output all of the characters used from point 0(h) through point 3(l) so when you:
  • System.out.println(s);
You will get an output of "Hel"

String Concatenation: 
String concatenation is another simple one. Think of it as "Adding Strings" so the syntax looks like:
  • variable = string1 + string2;
A proper looking code example would be:
  1. int age = 13;
  2. String rank = "PG";
  3. String rating = rank + age;
This should print out "PG13"

The Typical use of the above made string is one I have used before in my calculator:
  • System.out.println("The answer is: " + answer);
Strings are Immutable:
In basic principle java provides no ways to change a given character in a string. However to do this is rather simple. Take our greeting string from before if you wanted to change the "Hel" into "Help" you would simply concatenate a "p" onto the end of it so it would look something like:
  1. greeting = greeting.substring(0, 3) + "p";
In java you can not change a given string once it is made. However using the previous method you can reference a variable and generate a new string from it. It is for this reason that it is called Immutable. However as inefficient as this might seem the new string made has one great advantage. It is shared. Meaning the value of "greeting" goes two ways now.

Testing Strings for Equality:
You can test strings for equality just like you can test numbers. Use the equals method like so:
  • s.equals(t);
This will return true if the strings "s" and "t" are equal and false if they are not.
Note: "s" and "t" can be string variables or string constants. for example:
  • "Hello".equals(greeting);
To test if two strings are the same except for the upper / lowercase first letter you can do the following:
  • "Hello".equalsIgnoreCase("hello");
Empty and Null Strings:
The empty string "" is a string lenght of "0", You can test this by calling either of these two methods:
  • if (str.lenght() == 0)
  • if (str.equals(""))
An empty string holds a value of 0 however if if has no value associated with it it can hold a "null" value to test null you simply:

  • if (str == null)
Sometimes its good to see if a string is neither null or empty to do so you simply do the following:
  • if (str != null && str.lenght() != 0)
Note: you need to test if a string is null before doing the above or else you will get an error for your output.

Code Points and Code Units:

A code unit is defined simply as the number of letters in a unicode UTF-16 strings of numbers and letters to find out how many code points a string has you do the following:
  1. Make a string: String hello = "This is a string, how are you?";
  2. Make an int with the value assigned to it: int numLetters = hello.lenght();
  3. print it out: System.out.println(numLetters); //In this case it will print out 30
To get the true output of the length you must do this:
  • int cpCount = greeting.codePointCount(0, greeting.lenght());
To see what an individual character in a string is do the following:
  • s.charAt(n); // where as n = the position in the string you want to see.
In the case of s.length() you start at -1 So in practicality it would look like:
  1. char first = greeting.charAt(0); //Displays character #1: H
  2. char last = greeting.charAt(4); // Displays character #4: o
  3. System.out.println(first , last);
To get an indexed code point do the following:
  1. int index = greeting.offsetByCodePoints(0, i);
  2. int cp = greeting.codePointAt(index);
  3. System.out.println(index);
 So why is it important to know Code Points? Say you have a character that you dont know the meaning of if you want to know what it is you can use CodePoints to learn what it is.

Viewing Forward:
  1. String sentence = "This is a basic sentence sequence using letters and spaces in unicode!";
  2. int i = 0;
  3. int cp = sentence.codePointAt(i);
  4. System.out.println("\n" + sentence);
  5. if (Character.isSupplementaryCodePoint(cp)) i += 2;
  6. else i++;
  7. System.out.println(i);
Viewing reverse:

  1. String sentence = "This is a basic sentence sequence using letters and spaces in unicode!";
  2. int i = 0;
  3. int cp = sentence.codePointAt(i);
  4. System.out.println("\n" + sentence);
  5. i--;
  6. if (Character.isSurrogate(sentence.chatAt(i))) i-- ;
  7. else i--;
  8. System.out.println(i);
Here is an image of the output for all of this code:

All of the code in this section can be found: Here!




ADDENDUM: String Builder!
I failed to mention String Builder. String builder is a good tool to use if you need to get parts of a file to be placed in a program and it is really simple to use. Here is the basic outline:

  1. Stringbuilder builder = new Stringbuilder();
  2. builder.append(ch); //Appends a single character
  3. builder.append(str); // Appends a string
  4. String completedString = builder.toString(); // Finallizes and puts it in a nice neat string to print out later!




Tuesday, March 26, 2013

Java;Notes - 11.) Java Enumeration

In java there are many ways to set up a variable to mean something. However setting up some variables can be tedious and give way to issues later on down the line. This is where Enumeration seems to come into play.
Enumeration can be defined as a way to make a custom static variable but in most cases it is a string of variables that will have certain meanings.

Say for instance you are looking to organize your clothing by Size. Instead of it being a set of characters or numbers why not make it an enumeration like so:

enum Size (SMALL,  MEDIUM, LARGE, X-LARGE);
Then you will be able to declare variables of this type such as:
Size s = Size.MEDIUM 

In the end enumeration serves as a wonderful way to keep things organized and give another level of customization.

Java;Notes - 10.) Java Parenthesis and Operator Hierarchy

Just like in math Java has a certain order in which things must be done. Remember the phrase from algebra: "Do whats in parenthesis first" the same rule almost applies to Java only its more or less relative to how the code is formatted and how the program will read it. Here is another nice little chart to look at that explains the following:



Basically what this means is that: a && b || c would actually in code be along the lines of: (a && b) || c and so on down the line.