Saturday, November 10, 2007

A couple cool things Volume I

I have decided to post cool findings so in case anyone ever reads this maybe they can pick up a few cool pointers.

For loops are dead in PHP, let me show you why you will almost never need a for loop again.



for($i = 0; $i <= 10; $i++) {
echo $i . ' ';
}

vs

foreach(range(1,10) as $i) {
echo $i . ' ';
}


The for loop is ugly and convoluted, and while the foreach with a range probably uses more overhead its usually not a big deal in PHP as app processor usage is usually least of your concerns. We need to move on from C people c'mon...

If you didn't notice, I didn't close the PHP (?>). That's because you don't need to! There is absolutely no reason to close it, in fact, only bad things will happen if you close it, such as accidental whitespaces (which causes weird session errors). PHP will find the EOF and stop there, it won't cause any slowdown, and has no cons.


Another thing I noticed, is a lot of sites out there don't realize how cool the label tag in XHTML/HTML is. By simply adding a tag around an input type of radio or checkbox, it allows you to select the input by clicking the text within the label tag.

Let me give you an example.


Crappy site:

<input name="name" value="123" type="checkbox"> Check

Awesome site:

<label>
<input name="name" value="123" type="checkbox"> Check
</label>



Now, see it in action for yourself....

Crappy site:
Check

Awesome site:



They are very similar, except that on the awesome site, you can actually click the text "click here" and it will select the box, or obviously you can check the box the "old-fashioned" way.

Thats all for now, more cool code-tidbits to come.

Tuesday, April 24, 2007

What is the world coming to?

Yesterday AM I was routinely checking my online banking to check the status of things, when I notice a $500 ATM withdrawl in SF. I think for a second, then another... then I frantically try to figure out what the hell is going on. Coincidentally, the day of the withdrawl I just so happened to be in SF, but at the beach and I never used my card. I immediately got on the phone with BofA, they told me that someone was pulling money out from my account, duh. They tell me I should call my dad to see if he had lost his card, so I called him, nope still has his card, so I get BofA on the line again, and they put a hold on my account, phew, now I'm safe because there is a hold on my account..... nope.

I check my online banking again later in the day after I had went to the bank to change my pin, and notice another $500 missing from my account, ATM withdrawl, this time in Berkeley. Naturally, my mood shifts from phew to homicidal rage. So once again I'm on the line with BofA and I basically say "wtf", my account is supposed to be on hold, thus you cannot withdraw money? right? isnt that what a hold is?

Apparently, my card wasn't being used, but my Dads card was, and since our accounts are linked this person withdrew money from my account, not knowing the difference. The first Bank of America agent I spoke to NEVER at any point in our conversation mentioned that it wasn't even my card being used, holy crap that seems like a pretty vital piece of information, yet the 3rd person I talked to says it clearly stated that my card wasn't being used. WOW.

So roughly 2 nanoseconds later I am speed dialing my Pops to put a hold on his account, because apparently, putting a hold on my account doesn't prevent HIM with from taking money from my account, it only prevents ME from taking money from my account, and the person willingly put the hold on my account KNOWING that his card was being used and that someone would still be able to withdraw money from my account. OMG!!

In a rage, I'm on the phone with BofA for a final time explaining the situation to them, only to find out that I'm a moron for thinking a hold on my account protects me from others withdrawing from it, and I get a bunch of attitude from the rep because I'm a little bit frustrated that yet another withdrawl was made. I am in disbelief that I trust my money to people so incompetent.

bg Bank of America

Tuesday, April 17, 2007

Parsing Digg's RSS Feeds

I thought someone might find this useful, but when you are trying to pull an RSS feed via something like PHP, it simply won't work on its own. For instance, if you try to do something along the lines of it will give you an error, yet when you go to your browser and pull up the feed everything is gravy, ftw!?

So after an hour or so of googling and finding nothing because I had nowhere to start, I decided to pull up telnet and give it a shot the old fashioned way :)

telnet digg.com 80;
get / http/1.1 \n\n

Nada!!

so... ok...

telnet digg.com 80;
Host: Digg.com
get / http/1.1 \n\n

Still nothing!

Finally, I try

telnet digg.com 80;
Host: whatever.com
Referer: something.net
User-agent: some browser
get / http/1.1 \n\n

Zoip!

Wala, one of these is the magic one, through process of elimination, I find the are requiring a referrer. Weird... so... how do you fix this in PHP you ask? Simple...

ini_set('user_agent', 'Anything here');

Well, there you have it, your one line fix for parsing Digg.

Monday, April 16, 2007

Putting down the wrench

Well, every man has a moment in his life where he realizes he needs to stop doing something, I think for now at least, I'm done working on cars, and I'm going to put my efforts towards more worthwhile endeavors.. most importantly the person leasing the garage has let me out of my lease, with a big catch, but thats ok...

Whats important is that now I will have more time to work on things like random projects (long, evil laugh...) =P and do things like writing blogs, woohoo.

Thursday, March 29, 2007

Anti-Windows Rant #1

I hate to be a complainer, but I just have to let people in on what I had to deal with this past weekend, I wasted yet another weekend of my life because engineers at Microsoft didn’t take the time to do a very few simple things that would have made my life easier.

My cousin calls me friday afternoon, to meet up… we hang out yada yada, then we get back home and he asks me to take a look at his laptop… its running slow (big shocker…), I fire up the laptop only to see 14 icons in the taskbar with basically every POS software that can come with your computer and possibly some spyware in there too… Naturally, I disable all his startup stuff, reboot and bam, system registry hive is corruped… after banging my head on the table for an hour in regret of agreeing to work on a windows machine, I try recovery console… I get prompted for a login, crap… reset the password… the new password doesnt work, can’t recover the computer because i can’t log in… okay.. reinstall xp home, his key “works” but when it starts up it forces activation without the nifty 30 day trial period… I go to activate, the screen is blank, activation mysteriously just doesn’t work, no reason why, just fails… Ok, great, can’t change the key because i can’t login, so i have to reinstall with another key, this key also “works” but now I find that key has reached its maximum activation limit.

Wonderful, so I proceed to very annoyed for another hour while I install XP Pro Corporate with my work license just so I can get the crap off of the computer, great everything works, no activation required… am I the only person who find it strange that a company who makes money because of piracy is working so hard to make sure I can’t use this computer…weird… anyway on to Sub-rant about Toshiba’s Support…

So now I go to the Toshiba support website, downloaded the drivers for the laptop, and only 1 of the drivers actually works. You have to understand this is after 5 hours of trying to simply get data off of the laptop, I am practically at my limit… So I have to go and download drivers from the manufacturer (1 of which also didn’t work) only to have a different registry hive corrupted 3 days later causing my cousin to lose more data. One would assume the hard drive is failing, but it showed no signs of it other than random things dying, and it passed all the tests I ran on it…

The lesson learned here is not how crappy Windows or Microsoft is, but moreso that I’ve wasted so many hours of my life dealing with these types of problems, so many precious hours of my life have been spent dealing with issues that shouldnt need to be dealt with. From now on I will go out of my way to aviod dealing with any Microsoft products, be it a mouse, and O/S or really-crappy-defective-non-standard-insecure browser

Sunday, March 4, 2007

Actual web designing?

Wow, I never would have though, but I am actually seeing that I can do _some_ web designing after doing quite a bit of div/cssish kind of stuff for the last 4 months at work, yikes I almost seem like I know what I’m doing… yeah, I said almost =P

In other news, I have officially showed two others the light into the world of Apple. My friend Jason decided to get a Macbook, and my Pops jumped on the bandwagon with an iMac, wise choices guys.