Aftab Sultan

Talkin' Geek
Archive for April, 2010

April 25th, 2010

A whole word trim function

No Comments, code, PHP, Web development, by sultanaf.

Recently while upgrading the templates for this site to make it more mobile friendly, I decided to trim the post content on the front page to limit it to only show the first 10 or so words of the post. Obviously the substr function in PHP won’t work since it will simply cut off the string at x characters and possibly cut off words. To my knowledge no such function exists in PHP so I wrote a function of my own with regex goodness. Heres the code: 1234567891011121314151617181920212223/* This function will trim a string to x characters and truncate to the last whole word. str is the string to be trimmed x is the number of characters postfix is the string to append to the end of the trimmed function */ function trim_to_word($str, $x,  $postfix=’…’) { $str_len = strlen($str); if ($str_len > $x) { # Modify this line to customize the matching criteria $r = ‘/(.{‘ . $x . ‘}.*?)\b/’ preg_match($r, $str, $matches); # Trim the right side of the matched string and append the postfix return rtrim($matches[1]) . $postfix; } else { return $str; } }

April 22nd, 2010

[FIX] Another StarCraft 2 lag fix

3 Comments, starcraft 2, by sultanaf.

Aside from the previous fix I posted, I have another fix for the in-game lag in StarCraft 2. The lag could be caused by the GPU rendering the frames at max speed which might cause the video card to overheat and slow down the game. The following will help by telling StarCraft 2 to limit the behavior: Open My Documents\StarCraft II Beta\variables.txt using Notepad (or any other text editor) Add the following two lines to the file: Frameratecapglue=30 Frameratecap=60 Save the txt file and you’re done. The frameratecapglue variable controls menu screens framerates. The frameratecap controls the in-game framerate. I have chosen 60 as I am running this game on a laptop (60 is the max refresh rate for my monitor) but you can choose any number that fits your configuration.

April 17th, 2010

iPad in-dash project

No Comments, Audio, Cars, iPad, by sultanaf.

Regardless of what you think of Apple’s new iPad, I think this is a very cool project. A lot of the new cars already have a touch screen interface but for those who don’t I think this is a pretty good idea. With wireless syncing. the process of adding new songs can be simplified. With a decent GPS app combined with its big screen, this has a lot of potential. Of course if one wants to go hardcore, an OBDII scanner can be integrated to show useful information about the car like intake air temp, error codes, timing readings, etc. Keeping the cost aside, one potential problem I see with this is sun glare. Also the screen placement might be awkward and of course having a visible $500 iPad in a parked car is asking for trouble (it’s removable, so you can take it with you, I guess). Part 1: Part 2:

The Problem: I’ve been playing the long-awaited StarCraft 2 (Beta) recently and it doesn’t disappoint. I am running Windows 7 (64 bit) with an ATI Radeon HD 3400 video card. I ran into some complications while playing the game. Specifically, it would freeze in-game for a while and sometimes long enough for me to be dropped from the game. The Internet? At first I though it was my internet connection which was causing the lag. After some investigation, it turns out it wasn’t the internet connection (the game was also freezing during replays as well). The Video Card? Next I suspected the video card was over heating. I ran a temperature monitor with a CPU monitor while playing the game. It seems that under normal game play, the temperature was around 70 C. Once the game froze, the GPU temperature dropped and the CPU usage spiked to 100%. The CPU? After digging around a little bit, I came across a few threads on people having the same problem. They seemed to have fixed this problem by running the game on a single CPU core instead of the default multi-core setup. Specifically CPU 1 seems to be the magic core. I tried that but with no success. It was time to dig a little deeper. The Solution: The problem lies with Physx. StarCraft 2 comes with a version of Physx but with certain drivers, the latest version is required to run the game smoothly. Physx basically allows the game physics to be CPU powered rather than…

April 16th, 2010

Mobile version now available

No Comments, Mobile, by sultanaf.

I just upgraded the template to allow comfortable navigation of the site with smart phones. The theme is pretty simple right now but I’ll be updating it regularly with new features. You can check out the mobile version with a normal browser here.

I recently had a chance to work with JQuery for a web development course. JQuery totally changed the way I think about JavaScript. The best part is the ease by which you can make AJAX calls. For those starting out with JQuery, this cheatsheet is a must have! For those who missed the xkcd fun on April Fool’s, you can still access the page here. After spending some time messing around with it trying to find the easter eggs, I ended up looking at the source code (kind of cheating, I know lol). With the beginning of summer, this means one and one thing only: StarCraft II.