Latest Solutions
See All Solutions
Every idea has problems, and every problem has a solutions.
These are solutions created while working on our ideas we thought
we'd share.
-
How to Make Simple Cross-Domain Ajax Requests With Responses
For Read It Later for the iPhone, I built a ‘Tap to Save’ bookmarklet for Mobile Safari. When using Tap to Save, instead of opening a link when clicked, the link is saved to a user’s reading list. This makes it easy to save a few links from a web page without having to open [...]
Tags: Ajax, javascript, php
-
Remember Just One Password That’s Unique For Every Site
Like anyone using the internet today, I have a lot of accounts that need passwords. Bank accounts, social networks, new startups I’m checking out, email accounts, blogs, forums, you name it. Though I keep unique passwords for important services (like servers and email accounts), it still is a pain to have to remember [...]
Tags: Lifehack, Passwords, Security
-
Comment to Email - Wordpress Plugin
The Comment to Email Wordpress Plugin allows you to reply to a comment and have your response be sent simultaneously to the commenter via email and posted as a regular comment in your comment section, killing two birds with one stone.
Tags: Plugin, Wordpress
-
Least/Greatest Common Mulitple (LCM,GCM) in PHP and Javascript
Simple script to find LCM or GCM of multiple numbers.
Tags: javascript, Math, php
-
Wordpress Plugin: Extra Comment Fields
This Wordpress plugin allows you to add additional fields for users to complete when submitting a comment. The extra data will be saved in the wp database and is retrieved when showing a post’s list of comments.
Tags: php, Plugins, Wordpress
-
One Pass Parent-Child Array Structure
A more elegant solution to retrieving a parent-child structure from a database.
Tags: Databases, Mysql, php
-
PNG Hover
Provides a drop-in solution to making PNG transparency work with rollover menus in IE6.
Tags: css, IE6, javascript
What I've Learned Recently
See All I've Learned
With every project and every day, you should learn something.
Here's what I've learned.
-
Override Wordpress Htaccess with Custom Rewrite Rules
I was working on a client project that used Wordpress as it’s main method for content management. In addition to Wordpress, it had a seperate admin/member area hosted on the same domain. In this member area I had implemented several uses of Mod Rewrite to make cleaner urls.
However, when Wordpress was installed it’s htaccess rules took over request, no matter what I had entered and in what order.
Here what my htaccess file looks like to allow other rewrite rules to run side by side with Wordpress:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/(file|member|photo) [NC] RewriteRule . /index.php [L] RewriteRule ^member/([0-9]+)/ /member_profile.php?m=$1 RewriteRule ^file/([0-9]+)/(.+)? /file.php?f=$1 RewriteRule ^photo/([^/]+)/([^/]+)/(.+)? /file.php?type=$1&ref_id=$2&photo=1 </IfModule>By adding the Rewrite Condition with Request URI, I’m able to add rules/folders that Wordpress should ignore. Make sure you use Request_URI and not Request_Filename. They provide two different results.
Tags: Htaccess, Mod Rewrite, web design, Wordpress
-
How to Block Email From a Specific Address on a Cpanel/WHM or Other Web Server Using Exim
While working on a client project that had a mass member email function, I needed a way to test the system exactly as it would run in production. This meant, when it ran, it would send emails to all of the members in the directory instead of a test email address. The only problem was I didn’t want to send test emails out to the thousands of members in the directory.
So I wanted a way have PHP still send the email out as it normally would but have the mail server (EXIM) kill it before it left the server.
Luckily this is very easy to do. With EXIM, you can setup filters that can perform a large number of tasks, like blocking message, or blind copying messages to other email addresses. In this case, I’m going to create a filter to cause an email coming from a specific sender to fail (the email address I use to send the email in PHP).
What you’ll want to do is find your System Filter File for EXIM. In WHM, you can find this file listed in your EXIM Configuration Editor about half way down the page.
Once you’ve located the file, log into SSH and edit the file.
pico /path/to/your/fileThen enter the following filter into the file and save it:
if first_delivery and ( ("$h_from:" contains "emailtoblock@mydomain.com") ) then fail endifIf you’d like a copy of the email sent to you after the message fails so you can make sure it is correctly formatted, just add one line:
if first_delivery and ( ("$h_from:" contains "emailtoblock@mydomain.com") ) then unseen deliver "youremail@yourdomain.com" fail endifI suggest you read up more about EXIM filtering for more advanced functions.
Where I Learned This: I found the solution the Imthiaz Blog and the Exim Documentation.
Tags: Cpanel, Email, Exim, Linux, php, WHM
-
Find the Files/Folders Taking Up the Most Space in Unix
If you’re logged into your server and trying to pin down what folders are taking up the most space on your hard drive, there are simple commands to compile an organized list.
First, to see the disk space usage of your drives and partition, run:
dfThis will output a list of all drives/partitions on your system, the size, usage and percent used.
If you’d like to see all of the folders in a particular directory sorted by their filesize use the du command.
du -ks ./* | sort -n
Tags: Linux, Unix
-
Quick Way to Help Optimize Mysql Databases
The Analyse procedure built into MySql can give you a wealth of information about your database tables, making it easy to find tables that can be tightened up.
If you query:
SELECT * FROM table_name PROCEDURE ANALYSE()You’ll get a result back with the minimum/maximum value, minimum/maximum length, number of empty or zero strings, number of nulls, the average value/length, the standard deviation, and a suggested optimal fieldtype for every row in the table.
Should be noted this isn’t very helpful unless you have active tables with a fair amount of data in them already.
Tags: Mysql, Optimization
-
Layer XUL Elements/Images/Backgrounds in Firefox 3 Extensions Using Stack

While working on the Read It Later Firefox Extension, I wanted a way to layer multiple background images on a toolbar button so I could create a nice looking notification indicator like on the iPhone. (Note I opt-ed later to use a simpler look, but this method might still be helpful for other applications).
In order to make this work you’ll need to familarize yourself with XBL and XUL Stacks. XBL allows you to essentially reconfigure how an XUL element works/looks.
In this case, we’ll use XBL to replace a normal ToolbarButton into a Stack Element.
So first you’ll need your toolbarbutton added to your XUL overlay:
<toolbarbutton id=”tButton” type=”menu-button” />Next we need to create the XBL Binding (complete the tutorial linked about XBL if you don’t know what XBL is):
<?xml version="1.0" encoding="UTF-8"?> <bindings xmlns="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <binding id="toolbarbutton" display="xul:menu" extends="chrome://global/content/bindings/button.xml#menu-button-base"> <resources> <stylesheet src="chrome://global/skin/toolbarbutton.css" /> </resources> <content> <xul:toolbarbutton class="buttonstack" anonid="button" flex="1" allowevents="true" xbl:inherits="disabled,crop,image,label,accesskey,command,align, dir,pack,orient,toolbarmode,buttonstyle,status,notifyNumber" /> </content> </binding> <binding id="buttonstack"> <content> <children> <xul:stack align="center" pack="center" xbl:inherits="allowevents"> <xul:image src="chrome://urextension/skin/buttonimage.png" /> <xul:image src="chrome://urextension/skin/number_circle.png" /> <xul:label value="" xbl:inherits="value=notifyNumber,allowevents" /> </xul:stack> </children> </content> </binding> </bindings>What we have here is 3 layers. The first is the main button icon (for example with the iphone button it’d be the rounded blue envelope button. The second is the image that’s behind the number (for example the red circle on the iphone button). And the last layer is the actual number you are using to show the notication of (in the iPhone’s case, it’s 3).
You will need to apply left/top attributes to the second and third layers to position the numbered circle where you’d like it. Follow the Stack tutorial (linked above) for more information about positioning the elements inside of a stack.
To change the number in the notification, simply change the attribute ‘notifyNumber’ on your toolbar button.
document.getElementById(’tButton’).setAttribute(’notifyNumber’, 3);If you look at the XBL code, make note of where ‘notifyNumber’ is inherited. This is how XBL knows to send the attribute down the chain. You can make the attribute anything or add other attributes as well.
Finally, you need to apply the bindings to your toolbar button. In your stylesheet add the following lines:
#tButton { -moz-binding: url("chrome://urextension/content/yourxblfile.xml#toolbarbutton"); } .buttonstack { -moz-binding: url("chrome://urextension/content/yourxblfile.xml#buttonstack"); }
Tags: extensions, Firefox, XBL, XUL
-
Replace Standard Menupop in XUL
I came across a time I needed to open a different element then a standard popup menu when clicking the dropdown selector on a toolbar button. I wanted to open a panel instead. To open a different element and hide the popup you can do something similar to this:
<toolbarbutton type=”menu-button”>
<menupopup onpopupshowing=”OpenOtherFunction();event.stopPropagation();return false;” />
</toolbarbutton>Update: You can do this much more efficiently using XBL Bindings. I highly recommend reading up on them.
Where I learned it: While working on the Read It Later Firefox Extension
Tags: extensions, Firefox, javascript, XUL
-
How To Disable ‘will not be installed because it does not provide secure updates’ Warning in Firefox 3
By default, Firefox 3 prevents users from installing any extensions that do not offer a secure connection for automatic updates. This prevents users from being victims of hijacked update URLs.
But for developers or people installing extensions they know they can trust, it is a pain.
Luckily it is easily disabled by:
- Enter ‘about:config’ into address bar, hit go
- Right click somewhere in the list of keys below. Select New->Boolean
- Enter ‘ extensions.checkUpdateSecurity ‘ as the name
- Select false as the value
- Reattempt installation of your plugin.
Ran into this problem when installing Extension Developer’s Extension while working on Read It Later.
Found the solution at MozillaZine (via Google)
Tags: Firefox
-
Flash Sees Text Inside <b> Tag as Seperate Font and Must Be Embedded
In flash, if text inside html tags like <b> or <i> is not appearing in your dynamic textfields, you need to embed the stylized font. Flash/Actionscript sees the text inside as a seperate font and therefore it also needs to be embedded.
For example, if you have a dynamic textfield with Arial. If you add a bold tag (<b>) around text inside the field, you will need to additionally embed Arial with bold turned on into your flash document.
I ran into this while working on flash graphs for Tail Report.
I found the answer in the Los Angeles Flash Users Group (via Google)
Tags: Actionscript, Flash, web design