CheckBoxer for Google Chrome
CheckBoxer is an extension I wrote for Google Chrome. Based on the CheckBoxMate plugin for Firefox by nrlz, it does ... well.. exactly the same thing: you draw a rectangle around the check boxes you want to toggle on or off. Magic.
Here it is in action:
As you can see, it has selected all of the check boxes within the selected area. No need to hold any other buttons as it only works when you've dragged over the starting checkbox.
Click here to check it out.
CheckBoxMate for Greasemonkey
Ever had to check off a bunch of checkboxes one by one? It's a grueling and tedious process, especially when you have to do more than .. say .. five. Never fear! That's why nrlz came up with CheckBoxMate.
What Is CheckBoxMate? This script allows you to check multiple checkboxes just by drawing a box around them.
It doesn't get any more elegant than that and it's one of those tools you don't use every day but when you need it, it's a godsend. The trouble is, it doesn't seem to work at all (without tweaking) with Firefox 3.6+. That's where Greasemonkey comes in.
In a desperate attempt at making my precious CheckBoxMate work with my updated Firefox script, I decided to look under the hood to see if I could figure out the solution to the issue. After an hour of poking and prodding, I was able to troubleshoot and fix the problem using the Add-on's javascript in Greasemonkey (pretty handy way to diagnose Add-on problems in general, actually).
Summary: CheckBoxMate stopped working, so I jammed it into Greasemonkey, fixed it and released it on userscripts.org.
I'm currently using CheckBoxMate for Greasemonkey with Firefox 3.6.3 on Mac OS X 10.6.3 with absolutely zero problems.
P.S. I've done all of this essentially without nrlz's permission at all, so if he tells me to take this down, I will.
*** UPDATE***
I've tested this on my Windows 7 box at work (Firefox 3.6.3) and it works perfectly. Please let me know if you have any issues.
ShareThis Sucks for Greasemonkey
After becoming repeatedly annoyed at how the ShareThis button would pop up and just stay there at any hint of a mouseover/hover, I wrote this short Greasemonkey script to banish ShareThis from my sight:
And here's a link directly to the file:
Enjoy!
-Scott
Reddit Tabbed Links
Put simply, I was just tired of shift+clicking the links on Reddit, so I made a Greasemonkey script that does it for all the main links and comment links:
Here's the direct link to the script:
Enjoy.
MemcacheD + PHP + MySQL = Dream Team
When using development frameworks like CakePHP, Zend or even Smarty, I always took their ability to cache data for granted. After all, I hadn't built all of my applications using frameworks and those that were lacking didn't seem to be hurting too badly. It just seemed like a bonus for using their environments and while I was very aware of the fact that caching reduces stress on the database, I hadn't really built anything that was in dire need of caching as a means of improving overall functionality.
Once I started learning about memcached, I actually started to think about my non-frameworked applications and whether there were any noticeable lags. It wasn't long before I had thought of a few glaringly obvious examples where (mem)caching could be used to significantly improve performance. But before I go into those examples, here is a brief explanation of what memcached does for you (taken directly from memcached.org):
What is Memcached?
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.
So first on my list was Blogflare.com, with its MySQL-based statistical cruncher running on regular intervals and its PHP-based image tickers, the load on the database was strained on a very regular basis. I noticed if I just adjusted the simple database calls to push updates to memcached and then check memcached for data before I even touch the database, performance significantly increased on the front-end. Additionally, this same improvement was helpful in terms of serving out ticker images that are normally database-driven. With these two simple changes, load on the database dropped enough to make scaling much less of a pain. This is relevant, too, as the site has grown steadily over the past few months and shows no signs of stopping.
The next item on the list is one I can't actually link you to but an application that I've built for the University's Art School to handle finance planning and reporting for graduate students. After a few moments of thinking about its structure I realized the database is very read-heavy, particularly in the reporting area. Reports are generated from stored procedures and perform some pretty heavy calculations on each student's data in order to provide administrators with a very accurate picture of spending and planned spending. Updating the database calls for insert/update/delete methods to perform calls to memcached first proved to be ENORMOUSLY effective at speeding up use of the database. While this helps to reduce load on the server, the most important factor in this case was how much better the overall user experience was. Lagginess became intermittent rather than constant.
When I was researching memcached and wondering about how such a thing would scale, I found a clipping from this article entitled How to Dramatically Speed Up Your Web Application: An Introduction to memcached very helpful-
No doubt if you took Computer Science in school you were cautioned of the temptation to abuse caches because there is a law of diminishing returns in regards to the size of your cache: the larger your cache gets the more costly it is retrieve and store information within it. Memcache however is not heavily constrained in this way, because the cache at large is made up of lots of little caches. This allows memcached to be much more responsive even when the cache itself begins to reach sizes that might be really inefficient in other circumstances.
So this little bit managed to assuage my fears and give me the confidence to jump right in and start testing it with my lesser-applications. The results, even this early, have been astounding and I can now see how they are a very vital part of modern web application development.
Use jQuery to Tally Forms
Recently, I had the task of creating a simple form to be submitted to a specific department member here on campus. I felt this was a great opportunity to utilize jQuery and to see just how simple I could make adding new fields, since I wanted the form to be somewhat dynamic (adding/removing of inputs and such).
After trying a few methods here and there, I was able to utilize a few jQuery functions and a nice plugin (jquery-formatcurrency) to make everything work as desired.
Here is what I came up with:
$(document).ready(function(){ var total = 0; $('.currency').blur(function() { total = 0; $('.add').each(function(i,obj){ total += $(obj).val()*1; }); $('.subtract').each(function(i,obj){ total -= $(obj).val()*1; }); $('#total').val(total); $('.currency').formatCurrency({symbol:''}); }); });
What's neat about this method is that it handles everything on the blur (loss of focus) of any element with the 'currency' class applied. That means it won't do anything to the field while a person is typing in it -- annoying for some people -- it waits until the user moves on to the next field or away from the field altogether.
The really cool part of what happens first is the mathematical operation. Notice the similarity between the following methods:
$('.add').each(function(i,obj){ total += $(obj).val()*1; }); $('.subtract').each(function(i,obj){ total -= $(obj).val()*1; });
The first method looks at all elements with the 'add' class applied. The .each jQuery function cycles through each matched element and feeds two variables to the attached function: an incremented index and the object reference itself. This makes a tally extremely simple as jQuery will automagically cycle through all the elements you want to either add or subtract based on what class you have applied. The same applies to both classes and, of course, can be extended if you want to do more complex mathematics or formatting to your fields.
After these methods run, the total variable now holds the correct sum for all fields properly classed either 'add' or 'subtract.' This can now be applied to the input field with an id of 'total':
$('#total').val(total);
This will set the 'total' input field's value to the sum of the fields.
Lastly, it will format all fields to currency using the formatCurrency function:
$('.currency').formatCurrency({symbol:''});
Notice I specify here that I do not want any currency symbol (e.g. '$') as I specify that outside the field itself to display to the user.
Again, all of this happens every time a field gets updated and loses focus. So yes, it's magic.
SweetDate.org
| Language: | PHP w/ Smarty |
| Database: | MySQL |
| Javascript: | jQuery |
Sweet Date is a very straight-forward dating service web site. People sign up, browse and find people that interest them, and they can either send them an instant message or they can send them a message using the site's built-in mailing system.
As far as the look goes, I chose blue because I think it looks great and because I thought I'd try adhering to some standards for emotional targetting this time (e.g. Color Wheel Pro / Blue). Additionally, I'm taking my time with the feel of the site as I don't want it to have a "thrown-together" appearance. Instead, I want people to know intuitively how to use the web site and where to go if they need help.
The reason I'm able to pay attention to these elements is because I'm using Smarty Templating Engine again, which makes development go a lot faster. Now I can focus on jQuery and Photoshop.
While I'm very aware that dating web sites are a dime-a-dozen these days, I've always wanted to build one for several reasons:
- Ads pay reasonably well
- The structure is reasonably simple
- I need more large-scale web sites on my resume
Although at the moment, the web site is currently being built, the basic frame is in place with the look & feel largely intact. Once registration is open, feel free to open an account but the site will be largely in beta until I feel it is relatively complete.
Compress PHP Output And Save On Bandwidth!
We all love web pages that load super fast and as Google pushes us to "make the web faster," we must heed the call.
In my search for ways to increase efficiency while decreasing page load times and bandwidth output, I happened upon the wonderful world of Zlib compression. This compression type uses gzip to compress the output of your files and feed them to the browser.
How cool is that?
While it might sound like it would be an impossible task, it's really as simple as doing two things-
Step 1. Make sure your PHP server has the zlib extension
All you have to do is create a file called something like phpinfo.php on your server and put the following code inside:
<?php phpinfo(); ?>
Once it loads, just find 'zlib' and check to see whether it's there and whether it's enabled. If not, you need to either enable it yourself or ask your server admin to do it.
Step 2. Pop in the code!
Put the following code at the very top of any pages you want compressed, or (preferably) in your header file for the entire site-
<?php
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '1');
?>
OR if that doesn't work for you, you can try this-
<?php
ob_start('ob_gzhandler');
?>
...that's it!
Now try reloading your page.
If everything went right, you should notice an improvement in load time and where you'll notice it most is in your bandwidth usage at the end of the month.
I tested the before and after on Sitdiary.net and the file got compressed by over 3X every time! In other words, I'm going to cut my bandwidth usage down by 2/3 on all PHP files.
*** UPDATE ***
On my Wordpress blogs, I've been testing this out on the index.php and it seems I'm getting upwards of 75% compression rates!



