April 2010 - Posts

Once in a while we just discover simple things that fascinates us. Just accidentally discovered this while in the Facebook chat window press SHIFT + ENTER and you'll be able to enter a "new line". Useful if you're trying to make use of your creative side. :)

Posted by lamia | 1 comment(s)
Filed under:

Not sure where the saying "good coders code, great coders reuse" came from but I sure been doing a lot of copy-pasting throughout my 4+ year career. Web apps, mobile, games, blogger code,  etc. All stuff that I've been doing, I've always been doing a lot of copy-pasting code. Yes, copy-pasting is code reuse. In fact, I rarely really encounter code reuse in object oriented programming... Unless I'm using a framework, I rarely even really extended a class and "reused" anything from that class. Well... I've been able to apply the reuse of default behavior more in games than in web projects.

I notice that even when this is put to practice, there was a struggle trying to maintain different version of jar files or assemblies throughout a distributed development team. Even static methods used for utility classes are duplicated across the entire codebase. The only real thing being reused is the functionality. If I wrote a class method that writes something to a file, chances are I've also only looked that up on the internet and "re-used" somebody else's code.

Posted by lamia | 2 comment(s)

For students who would usually be taught C as their first programming language, a shift to Java could quickly make a confusion as they are crossing the boundaries between procedural and Object Oriented Programming. Both operators can be used in Java, in fact the second one is not called an operator but a method.

 

==

This is called the "Equal to" operator and is used to compare "primitive" types or check if you have equal object references(or do they refer to the same object in the heap). There are 8 primitive types in Java and you can usually identify them

byte, short, int, long, float, double, boolean, char

 

When used with Strings, one might assume that  you are making a comparison with the String values, but no. We mentioned above that "Equal to" operator checks for object references when used with objects.

 

So let's assume the following code:

 

1
2
3
4
5
6
        String s1 = "STRING ME";
        String s2 = "STRING ME";

        System.out.println("s1: " + s1);
        System.out.println("s2: " + s2);
        System.out.println("s1 == s2 is " + (s1 == s2));

This would output:

s1: STRING ME
s2: STRING ME
s1 == s2 is true

 

Why? The JVM does some optimization step with Strings(i.e the Strings get "pooled"). Basically, the JVM makes you point to the same Object reference that is pooled in the heap.

 

Let's make some modification with the Strings

 

1
2
3
4
5
6
        s1 += "2";
        s2 += "2";

        System.out.println("s1: " + s1);
        System.out.println("s2: " + s2);
        System.out.println("s1 == s2 is " + (s1 == s2));

 

The output is now:

s1: STRING ME2
s2: STRING ME2
s1 == s2 is false

 

Why? Because Strings are "immutable", new Object references are actually created. The String was not actually modified, it is a new String object. They are now different object references.

 

Now, what most of us usually want is "OBJECT EQUALITY", and that's what the next thing is for

 

equals()

All objects can use and override the equals() method. Any instance of a class you use or created automatically inherits this method. Without overriding, you use the default implementation of the Object class which is not very helpful. This works differently when used with the java.lang.String class as it does some character comparisons. You cannot override this method in String because String is a final class and cannot be extended.

 

Using a similar set of code, let's try to make modifications with the Equal To operator, for the String references to use the equals() method.

1
2
3
4
5
6
7
8
9
10
11
12
13
        String s1 = "STRING ME";
        String s2 = "STRING ME";

        System.out.println("s1: " + s1);
        System.out.println("s2: " + s2);
        System.out.println("s1 == s2 is " + (s1.equals(s2) ) );

        s1 += "2";
        s2 += "2";

        System.out.println("s1: " + s1);
        System.out.println("s2: " + s2);
        System.out.println("s1 == s2 is " + (s1.equals(s2) ) );

 

This will now both evaluate to true.

 

Again, when using Strings in Java, think of you're after equal object reference or object equality.

 

 

References:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/opsummary.html

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

Posted by lamia | 1 comment(s)

Alright. So aside for some video tutorials I agreed to make with Keith, I decided to pickup some beginner, intermidate, or advanced questions I could find in any tech/programming forums and post the solution back here. Well, I'm getting a bit rusty after all...

I'll be focusing mainly, still with Java. But I'm currently gaining interest with android since it's basically available more available to me, looks like Java (or is Java).

Posted by lamia | with no comments
Filed under: , ,

Alright, first off... The whole point of this post is to share how I resolved the "Masking" issue.

I have reserved a domain, everypesocounts.com and had a blogger account. Problem was, I could forward from my .com to my blogger blog by forwarding and masking the URL, but the URL kept being the same even when you click on a hyperlink.  I found it more effective to use the GoDaddy support help since I'm hosted with them. It's probably faster than anything else you could find in google.

 

Now, following the steps mentioned here, just read carefully and you'll be successful.

 

Keys to Success

- Park Your Doman

- Forward (permanently), and use the complete URL(ie. www.everypesocounts.blogspot.com)

- Add CNET entry OR if already existing, edit www entry (www.everypesocounts.com)

- configure blogger to use your custom domain, remember that www is a subdomain that must be specified. You can't just use everypesocounts.com

Posted by lamia | with no comments

Just discovered this trick today...

1. Say, you launched the command line by typing cmd in run

2. Try moving to the C:\Program Files directory, that would point you now to...

C:\Program Files>

3. Now type,

exporer .

C:\Program Files>Explorer .

This will launch Windows Explorer in the current directory you are in, in the command line.

Might get useful to some people. :)

Posted by lamia | with no comments
Filed under:

Or show Content when there is only one post. I've been fiddling with Blogger for a while now and studying how to code using the bloger tags. This took me a few weeks to figure out but finally, I guess I'm getting more comfortable with it.

<b:if cond='data:numPosts == 1'>

<!-- PUT CONTENT HERE -->

</b:if>

 

How is this used? This is used for example, you want to show a facebook "share this" content and only want to show that particular link or button when inside a blog post

 

To do that, you do it like this... Put this inside the

      <!--Share of Facebook-->
      <b:if cond='data:numPosts == 1'>

      <div>
&lt;a name=&quot;fb_share&quot; type=&quot;button_count&quot; expr:href=&quot;http://www.facebook.com/sharer.php?u=data:post.url&amp;t=testtitle&quot;&gt;Share&lt;/a&gt;
&lt;script src=&quot;http://static.ak.fbcdn.net/connect.php/js/FB.Share&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
      </div>

      </b:if>
      <!--Share of Facebook-->

 

The <script> tags were actually converted so they would fit into blogger.

 

See it in action here (the facebook share button):  http://game-rumble.blogspot.com/2010/04/transformers-online-game.html

Posted by lamia | with no comments

This is for those who are dying to put google ads on their blog here (like myself). This is not a hack and I think Keith would agree that this is legitimate. Hopefully, this would allow you to focus on your blogging. :)

 

Let's start...

 

(Drums Roll)

 

1. Go to this URL, click "Add to your webpage" and fill up the

Client id - Also known as pubid, it looks like pub-123456789014327

Slot # - The ad slot, each ad you create has a unique ad slot , looks like #1234567890

 

2. Choose the ad format, specify the height and width and click Get the Code

3. Copy the code that is shown on the textbox below the screen

 

4. Now go to you blog and click on the control panel, navigate through your themes and the part where you can add a component. Choose "Google Component", click add then copy and paste the code  you got from google gadgets there. Save your template and... Voila!

 

 

**Note: I'm not sure about the security of this gadget. All I know is that it works.


I was tempted to make my own version but figured it would take a while to study how the code is made. You can view source in the gadget page to see how it's made. I hope I get enthusiastic enough to create one just for the community.

 

By the way, thanks to Joner Cyrre Worm, the author of the component.

 

HTH!

Posted by lamia | with no comments