BriCode Thoughts from Brian Holt

17Sep/110

Javascript pop-up won’t reopen or refocus when I click on the link.

This one is a bit of a tricky one, especially if you are not primarily a Javascript developer and not intimately familiar with its inner workings. The issue arrises when you create a Javascript pop-up window, close it, and then try to open it again. Or when you create a pop-up focus on something else, and the click on the link trying to refocus on the same window and nothing happens. At least for me, this was a pretty big "What the hell?" kind of moment because I have lots of pop-up windows with Javascript and never have had a problem before. What changed?

17Sep/111

My First Open Source Project Released… googlePop.

This week I released my first bit of open source code. It's an open source Hello World project to print Hello Worlds across the... world. No, I'm just kidding. It is a bit of code I wrote at work to pop up a window with a Google Map. It accepts latitude, longitude, and a string as parameters. The string is displayed on a blue banner on the bottom of the map. It's fairly simple code but I figured it could be useful to others. It is released under the MIT License meaning feel free to use, abuse, and mangle my code in any fashion you see fit for whatever project, commercial or otherwise. Feel free to ask me any questions you may have about it, but I think it is pretty straightforward. The code is written in HTML, CSS, PHP, and Javascript using the Google Maps V3 Javascript API. You can find it here on GitHub:

googlePop

If you do use it, it would be cool to know where it ends up. Leave it a comment or send an email to gpop at bricode period com. Happy coding.

30Aug/110

PHP sizeof() or count() not working on my string to return the length!

Quick PHP tip here. I spent a half hour trying to figure this out and I figure someone else must be seeing something similar. sizeof() and count() only work (as you would expect them to work, anyway) on arrays. If you use it on a string, it will return 1 because it views a string as an array of one string in that context. The function you are actually searching for is strlen() like in C. Hope that saves someone some time.

21Aug/110

Free Stanford Online Courses: Databases, Artificial Intelligence, and Machine Learning

Stanford CS

I am becoming convinced day by day that Stanford is the greatest institution of higher education in the world. Rarely do I hear anything negative about the school and often do I hear things that are very positive. I am thoroughly impressed with their apparent to educate the world.

15Jul/101

My Frustration with BYU

With a title like this, I imagine most people expect me to post something about the Honor Code or some other draconian rule. To be honest: the Honor Code almost never interferes with what I'm doing anyway. I've actually come to appreciate it. The only way it really affects me in an (arguably) adversely manner is that it forces me to shave before I go to the testing center or to play intramural sports. Other than that, it doesn't interfere with anything. On the flip-side, it means all of your professors inherently trust you. For my computer science final, my teacher just handed us the paper and told us not to cheat and let us turn it any time that week. He just told us to remember the Honor Code and  that was that. I can't see that happening at many universities. In that respect, I love the Honor Code.

11Feb/103

Java Checkstyle saying “Expression can be simplified”

Okay, seriously, can we be any more vague? That's like erecting a building only to have you client tell you that you should simplify it. I won't repeat the phrases I uttered after I saw that was the error that Checkstyle was giving me. The description given by the Checkstyle website isn't much better either. So what are you really suppose to do then? What does it all mean?

The part of code I got on was:

while (scan.hasNext() && found == false) {

I figured it must mean that Checkstyle doesn't like the && or || operators and so I worked to remedy that only to no avail. Turns out the that Checkstyle isn't a fan of using the == operator in conjunction with boolean variables.

In plain English: don't use
if(blnVar == false)
if(blnVar == true)
but instead use
if(!blnVar)
if(blnVar)

That will clear up the Checkstyle error. Personally, I find the "correct" results to be more confusing, if anything. I think it's a rather arbitrary, but such is the life of a CS student.

9Feb/101

Java Checkstyle Covariant Equals Method Fix?

If some of you are as unfortunate as I am, your work or university forces you to use a script called Checkstyle that checks your code to see if it was "programmed well." While the script can provide valuable insight on how you clean up your code, it also often causes you to rewrite code that works perfectly well to only be more verbose than it needs to be.

One mishap I have encountered recently is the error "Covariant equals method" and it goes on to say that you're overwriting the equals method without providing and adequate hashCode method. The description from the sourceforge site is equally confusing

Checkstyle's Confusing Description

It seemed finicky at first because it didn't cite at first (when I had written the equals method) but it then it came up and would not go away. For those of facing similar issues, I offer the two solutions I found.

Solution 1:

The reason I got this error in the first place is because I had written an equals method in a parent class and then in again in a child class. The combination of the two, even though still functional, caused Checkstyle to go crazy. I solved the problem by just deleting the equals method in the child class and used only the one the parent class. You could do vice versa.

Solution 2:

If it is expedient to you to keep both equals methods in the parent and in the child class, all you need to do is to write a working hashCode method in the parent class. You could likely do it in the child class as well, but I have not tried that. A really easy way to make a working hashCode method is simply to use the one that Eclipse will make. Go to Source>Generate hashCode() and equals(). Worked like a charm for me.