Roger Stringer   About ▾

I'm Roger Stringer: a father, writer, developer, consultant, chef, speaker. Founder of TheInterviewr.

Monthly Archives: June 2009


What I’ve been reading this week (June 30/2009)

 

Ok, I know I skipped a week for the list posts, wasn’t on purpose, was just really busy. Anyhow, without further adieu, here you go:

  1. Turn-By-Turn Directions with The Google Maps API

  2. How to Track Your Reputation or a Keyword in Multiple Resources via One Unified Feed

  3. 10 awesome things to do with cURL

  4. Forty-Three of The Best Free Windows Enhancements That You Should Know About | freewaregenius.com

  5. 9 Tips For Staying Sane While Working at Home With Distractions – FreelanceSwitch – The Freelance Blog

  6. Use Whatever Font You Please On WordPress

  7. 130 Creative Photos by Markku Landesmaki » AcidCow.com – videos, pictures, celebs, flash games

  8. Track Mouse Activities With JS And PHP: (smt)

  9. 45 Incredibly Useful Web Design Checklists and Questionnaires | Developer’s Toolbox | Smashing Magazine

  10. 53 Jquery Tutorials, Resources, Tips And Tricks: Ultimate Collection | 1stwebdesigner – Love In Design

  11. 15 Must Read Articles for CSS Beginners

  12. 30+ Useful Resources for Improving Your Photoshop Efficiency – Psdtuts+

  13. 45 Stylish and Creative Typographical Desktop Wallpapers : Speckyboy Design Magazine

  14. 30 Custom 404 Designs | SherifAbdou – The Design Blog

  15. An Event Apart: Boston – Retrospective | Gatorworks | Baton Rouge Web Design & Development

  16. 50 Free Resources That Will Improve Your Writing Skills | Developer’s Toolbox | Smashing Magazine

  17. 30 Exceptional Web Designs – Nettuts+

  18. 99 Amazing Widescreen Wallpapers To Spice Up Your Desktop | Showcases | instantShift

  19. Print Design Articles, Tutorials and Resources June 2009 – Creattica Daily

  20. The “Light” CMS Trend | CSS-Tricks

  21. Free Vector Doodles – Women’s Clothing & Fashion

  22. 7 Simple Tips for Effectively Marketing Your Blog on Twitter

  23. Highlighter — A MooTools Search & Highlight Plugin

  24. LBOI Design Blog » The Biggest Design Trend Predictions For 2010

  25. How to Draw A Realistic Vector Light Bulb From Scratch – Vectortuts+

  26. YouTube – Worlds Biggest Alarm Clock

  27. 12 Essential
    Rules to Follow When Designing a Logo | Webdesigner Depot

  28. 150+ killer SEO tips | Blog | Econsultancy

  29. 13 Free Content Management Systems other than WordPress | Coding Cow

  30. CSS3 . Info – All you ever needed to know about CSS3

  31. Kid Swaps iPod For Sony Walkman, Gets A Culture Shock

  32. Interview with the Founder of Envato, Collis Ta’eed – Psdtuts+

Filed Under: Links

~•~

Trying out ThemeForest…

 

Last week, ThemeForest introduced 2 new categories Javascript and PHP Scripts. I thought about it and figured why not, so I added 4 scripts to the marketplace (3 to PHP, 1 to javascript). feednews googlecharts other googlecharts2 So far, it’s been working out well, feedNews has sold quite a few copies, and the Shorter URL site and googlecharts plugin for PHP are doing decent as well. The new javascript google chart library has been picking up in sales, so far themeforest is working well for script sales.

Filed Under: Articles

~•~

Quick Function: Easy CSS Compression with PHP and mod_rewrite

 

I’m in the process of redoing some aspects of my food site, foodizu.com, it’s a slow process but one of the things I am addressing is speed. I looked into some CSS compression ideas, but I wanted one script that would read a CSS or a javascript file and automatically strip any white spaces out, and return a more compressed CSS file. First, we create a file called csszip.php:

ob_start ("ob_gzhandler");
if( isset($_REQUEST['file']) ){
    $file = $_REQUEST['file'];
    if( goodfile($file) ){
        $ext = end(explode(".", $file));
        switch($ext){
            case 'css':$contenttype = 'css';break;
            case 'js':$contenttype = 'javascript';break;
            default:die();break;
        }
        header('Content-type: text/'.$contenttype.'; charset: UTF-8');
        header ("cache-control: must-revalidate");
        $offset = 60 * 60;
        $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
        header ($expire);
        $data = file_get_contents($file);
        $data = compress($data);
        echo $data;
    }
}
exit;
function goodfile($file){
    $invalidChars=array("\",""",";",">","<",".php");
    $file=str_replace($invalidChars,"",$file);
    if( file_exists($file) ) return true;
    return false;
}
function compress($buffer) {
    $buffer = preg_replace('!/*[^*]**+([^/][^*]**+)*/!', '', $buffer);
    $buffer = str_replace(array("rn", "r", "n", "t", '  ', '    ', '    '), '', $buffer);
    return $buffer;
}

This file will take anything passed via the file argument and compress it. Next, we want to make this process automatic, so we open up .htaccess and add this line:

RewriteEngine On
RewriteRule ^(.*).css$ /csszip.php?file=$1.css [L]

Obviously, if you already have a RerwriteEngine On line, then you can leave it out and place the RewriteRule on the line directly below it. This will tell the website to compress any css file you attempt to load. You can also have this work on javascript files by adding:

RewriteRule ^(.*).js$ /csszip.php?file=$1.js [L]

This will load and compress any javascript file as well. This method works well for reducing your bandwidth usage and cutting back on page load time, which are always nice bonuses.

Filed Under: Code

~•~

What I’ve been reading this week (June 14/09)

 

  1. Coda Slider and more with jquery tools – In the Woods (Useful tips for the recently released jquery tools library)
  2. Mozilla Prism (prism is an interesting prototype application that lets users split web applications out of their browser and run them directly on their desktop.)
  3. Compender: Dynamic Facebook Buttons and Links for Blogger Templates – Redux (Good post for blogger users, pre-formatted facebook ‘share’ links. the picky blogger formatting will accept these easily)
  4. 15 benefits to working as a full time freelancer | Guerrilla Freelancing (Another excellent freelancing post for people thinking about freelancing, this one on a more positive note)
  5. 32 online tools that can help your tech freelancing career | View from the Cubicle | TechRepublic.com(More great webtools for freelancers)
  6. Tell Us Your WordPress Story and Win More Than $3000 Worth of Prizes | WPWebHost (Awesome Contest – Tell your WP story and win big!)
  7. Dailytonic – Your daily Inspiration in Architecture and Design (Freaking awesome architecture and design stuff here)
  8. Why Designers Should Learn How to Code (great read for designers.)
  9. jQuery Inline Form Validation Engine | Web Resources | WebAppers (cool jquery form validator)
  10. Secure Your Forms With Form Keys – Nettuts+ (excellent read for people who use forms a lot)
  11. 4 Nice way to Convert HTML to PDF Online | TutorialFeed (quick and easy ways to convert html to pdf)
  12. WordPress 2.8 Resources For Developers | W3Avenue (Awesome 2.8 Resources for WordPress)
  13. Symbols & Special Characters (Quick way to access a chart for special characters that can be used in Photoshop on Windows)
  14. Top 100 Mac Apps | Chris Pirillo (Awesome list of Mac apps!)
  15. Twitter Launches Verified Accounts (Cool! Get a verified account to ensure that you are the real YOU!)
  16. Outlaw Design Blog » My Experience with Passive Income (Excellent video with advice about Designers and Passive Income)
  17. 80 Creative Ways to Customize Your MacBook | Webdesigner Depot (Awesome Macbook Customizations!!)
  18. 13 Most Important Things to do When Changing the WordPress Theme  – Technically Personal! (Great reminder of things to do when changing wordpress themes)
  19. 15 Creatively Cut Business Cards | Web Design Ledger (SWEET Business Cards – Creatively Cut)
  20. High Resolution Photoshop Smoke Brush Set | Creative Nerds (Freaking awesome Smoke Brushes!!)
  21. ProofHQ Review | Inspiredology (Cool Review of a Design Collaboration web app)

Filed Under: Links

~•~

Quick Function: mysql_get_var: Another useful MySQL tip

 

I’m going to show you a small but useful function that is handy to keep in your toolbox today, it’s called mysql_get_var. This function lets you run a SQL query, and only return the variable you choose. Here’s the function:

function mysql_get_var($query,$y=0){
    $res = mysql_query($query);
    $row = mysql_fetch_array($res);
    mysql_free_result($res);
    $rec = $row[$y];
    return $rec;
}

Now, let’s talk about what it does. When you call this function, like for example here:

$name = mysql_get_var("SELECT name from people where email = '[email protected]'");

You will return the name field, so what gets returned will be “Roger” (if that was my name in the database). Now, you may notice that this function had a second argument called $y, this is so that you can choose which variable to return when your query has multiple fields:

$city = mysql_get_var("SELECT name,address,city from people where email = '[email protected]'",2);

In the example above, I told it to return the 2nd argument, which due to PHP starting off arrays with a 0, would actually be the 3rd argument, so it returns the city of the person selected. This function is only for returning 1 field from 1 row to a time, so if there are more rows, this wouldn’t be as useful, but it does work well for grabbing say a user’s name everytime they log in, or some similar function.

Filed Under: Code

~•~

FeedNews, stand-alone big brother to newsPage

 

Today I’m pleased to announce the release of FeedNews. FeedNews is a stand-alone pro version of newsPage. I’ve added a backend so you can set up topics and feeds for each topic, and you can also choose to make a feed display as a wide feed, this allows the display of thumbnails on feeds that have thumbnails included. You can specify feeds to display on the homepage, or let the script create an index of topics instead.

Topics are automatically handled as seperate pages, and you can also specify which topics will show feeds on the main page. Fully template driven, easy to maintain and change via the backend.

Each topic also features it’s own RSS feed, which takes the feeds for that topic and creates one unified feed to display on other sites. Other features to come soon include an ad system, and the ability to use google blog search to locate feeds. The script is for sale for $5.00, and includes updates and support.

View a Demo here View More info here

Filed Under: Articles

~•~

Some Posts I read today

 

I’m going to start a new tradition today of doing at least a once weekly post of links I came across in my RSS reader lately.

  1. No-Fuss Video Conferencing Using Tinychat (Simeple, no-download, no-login chatroom featuring audio/video support and desktop sharing)

  2. There is NO SUCH THING as a Social Media Marketer (Interesting article from snipe.)

  3. How the Web and the Weblog have changed Writing (how writing itself has changed because of the availability of the Web and the Weblog)

  4. 12 Eye Catching Top Brand Websites to Boost your Creative Approach (not about blogging but interesting to track design trends)

  5. Review: 31 Days to a Better Blog Workbook (the first review of my workbook that I came across)

  6. 10 WordPress Plugins Guaranteed to Save You Time (a couple that I’d not seen before)

  7. JQuery HowTo: jQuery Beginner tutorials (Beginner tutorials for jQuery!)

  8. JQuery HowTo: jQuery Twitter API plugin(Interesting jQuery Twitter API Plugin!)

  9. 30 Sites Every Freelancer Should Visit and Utilize | Freelance Folder

  10. 4 Ways To Ensure Your Article Will Never Go Viral. | Tremendous News!

  11. 10 Essential SQL Tips for Developers – Nettuts+ (GREAT SQL RESOURCE – Tips for Devs)

  12. jQuery AJAX Tabs with ThickBox enabled (Great jQuery Tabs with ThickBox tutorial)

  13. 20 Developers to Follow on Twitter(Awesome developers to follow on twitter!)

  14. 15 jQuery Plugins to enhance your HTML form elements (Excellent jQuery plugins to enhance your forms!)

  15. 30 Must-Have Tweaks For Your Mac | How-To | Smashing Magazine (Awesome tweaks for your Mac! SWEET!)

  16. 5 Clues to Determine Follower-Followee Twitter-Credibility « CarolAnnB – Insight, Philosophy, Social Media & More (are you worth following? read this to find out)

  17. Animated Navigation Bar Using jQuery | WebMuch (Quick and easy navigation bar using jQuery!)

  18. Liquidicity » 50 Ways to Become a Better Designer (Great ways to become a better designer!)

  19. WordPress and WordPress MU to Merge (sounds like a useful development)

  20. Top Ten Myths about Google Analytics (from the Google Analytics Blog)

  21. Five Ways to Speed Up Page Response Times (because slow loading web pages suck)

  22. The #1 Conversion Killer in Your Copy (And How to Beat It) (wisdom from Sonia Simone at CopyBlogger)

  23. Spoonfed SEO Guide For Blogger Users | cheth Studios (Quick and easy SEO guide for bloggers!!)

  24. 10 WordPress Tips to Make Your Blog Look Like a Website (just what the title says)

  25. 10 Golden Rules of Social Media (basics but good rules to work by)

  26. Gawker – Time Puts Twitter on Cover, at Vanguard of American Economy – twitter (Twitter makes Time cover! Kickass!) This list
    is long, and I’ll try to keep it at leat this long or longer every week, but I hope everyone enjoys reading them.

Filed Under: Links

~•~

Quick Function: Expanding our MYSQl class to include caching

 

Building on last week’s article about closing mysql connections, I wanted to pass on this further expanded class, that allows for caching on heavier queries. To start, create a folder in your main web directory called “_cache” Here is our file, save it as DbConn.php same as last time:

define('DBCACHE_PATH', realpath('.').'/_cache/');
class DbConn {
    public $host = "localhost";
    public $user = "";
    public $pass = "";
    public $DB  = "";
    public $conn;
    public function __construct($host,$user,$pass,$db) {
        $this->host = $host;
        $this->user = $user;
        $this->pass = $pass;
        $this->DB = $db;
        $this->conn = mysql_connect($this->host, $this->user, $this->pass) or die("Couldn't connection to $host");
        mysql_select_db($this->DB,$this->conn);
    }
    public function __destruct(){
        mysql_close($this->conn);
    }   
    public function query($sql,$cache=true,$cachetime = "" ){
        if(!$cachetime) $cachetime = (60*60*1);
        if( $cache ){
            $oCache = new DBCache($sql, $cachetime );
            if (!$oCache->Check()) {
                $res = $this->_query($sql);
                $oCache->Set($res);
            }
            $res = $oCache->Get();
        }else{
            $res = $this->_query($sql);
        }
        return $res;
    }
    public function nonquery($sql){
        $res = myquery($sql,$this->conn);
        mysql_free_result($res);
        return $results;
    }
    private function _query($sql){
        $results = array();
        $res = myquery($sql,$this->conn);
        while( $row = mysql_fetch_assoc($res) ){
            $results[] = $row;
        }
        mysql_free_result($res);
        return $results;
    }
}
class DBCache {
    public $sFile;
    public $sFileLock;
    public $iCacheTime;
    public $oCacheObject;
    function __construct($sKey, $iCacheTime) {
        $this->sFile = DBCACHE_PATH.md5($sKey).".txt";
        $this->sFileLock = "$this->sFile.lock";
        $iCacheTime >= 10 ? $this->iCacheTime = $iCacheTime : $this->iCacheTime = 10;
    }
    function Check() {
        $val = 0;
        if (file_exists($this->sFileLock)) return true;
        $val = (file_exists($this->sFile) && ($this->iCacheTime == -1 || time() - filemtime($this->sFile) <= $this->iCacheTime));
        if( !$val ){ if (file_exists($this->sFile)) { unlink($this->sFile); } }
        return $val;
    }
    function Reset(){ if (file_exists($this->sFile)) { unlink($this->sFile); } }
    function Exists() { return (file_exists($this->sFile) || file_exists($this->sFileLock)); }
    function Set($vContents) {
        if (!file_exists($this->sFileLock)) {
            if (file_exists($this->sFile)) { copy($this->sFile, $this->sFileLock); }
            $oFile = fopen($this->sFile, 'w');
            fwrite($oFile, serialize($vContents));
            fclose($oFile);
            if (file_exists($this->sFileLock)) {unlink($this->sFileLock);}
            return true;
        }       
        return false;
    }
    function Get() {
        if (file_exists($this->sFileLock)) {
            return unserialize(file_get_contents($this->sFileLock));
        } else {
            return unserialize(file_get_contents($this->sFile));
        }
    }
    function ReValidate() { touch($this->sFile); }
}

You may notice that we have a few new functions here this time. We still start same as we did last time:

$dbconn = new DbConn("localhost","mydbuser","mydbpass","mydbname");
define( "DBH", $dbconn->conn );

But now, we can use a few extra functions, namely query and nonquery. You use query like so:

$results = $dbconn->query("Select * from people",true,(60*60*2));

This will return an array containing the records from the people table and will also tell the class to cache it for 2 hours (60 minutes * 60 seconds * 2). This way, we are cleaning up our results, and storing them away. Especially useful for larger tables, that can be slower. Once you return results, you would loop through the array and display them:

$results = $dbconn->query("Select * from people",true,(60*60*2));
foreach($results as $row){
    echo $row['name'];
}

Now, if you decided not to do any caching, we would do this:

$results = $dbconn->query("Select * from people",false);
foreach($results as $row){
    echo $row['name'];
}

This will return the array of results, without doing any caching. The last function, is a function called nonquery, this function is used for executing queries that wouldn’t return results, like insert or update queries.

$dbconn->nonquery("update people set name='Roger' where name='Wayne';");

Anyhow, this may seem kind of long winded and probably not all that convenient, but when you start getting a larger site with more traffic and start to worry about server load, then knowing about caching your results can be a handy tool.

Filed Under: Code

~•~