Search Field Text Without a Submit Button

March 19th, 2010

If you are trying to implement a search field in your website but do not plan on having a submit button (relying on the user to click enter), you’re going to want to put instructions somewhere.

In my case, I decided to populate the box it self with the words “Type and press enter to search”.

1
<input type="text" name="q" value="Type and press enter to search." id="searchfield" />

Unfortunately, this left the user with the task of manually deleting the text in the box before searching. Adding a tiny bit of javascript to your HTML element will automatically remove the text when the user clicks on it and if the user doesn’t enter anything it will add the text back when the user clicks away.

1
2
3
<input type="text" name="q" value="Type and press enter to search." id="searchfield"
onfocus="if ( this.value=='Type and press enter to search.' ) { this.value = ''; }"
onblur="if ( this.value=='' ) { this.value = 'Type and press enter to search.'; }" />

Hopefully it works for you all, I have only tested it in Firefox and Safari on a Mac.

Sending Google Reader Items to Pinboard

September 8th, 2009

I just started using Pinboard as an alternative to my previous use of Delicious and Instapaper.

One cool thing that I was able to work out (that I had trouble with using Instapaper) is using the new Send To feature in Google Reader, I can now send links directly to Pinboard as unread items or bookmarks.

The Pinboard blog has basic instructions for sending as bookmarks:

Go to Settings, and then the “Send To” tab. Click the “Create Custom Link” and enter the following:

Name: Pinboard

Url: http://pinboard.in/add?url=${url}&title=${title}

Icon Url: http://pinboard.in/favicon.ico

But to send it as an unread item just requires changing the URL to:

http://pinboard.in/add?later=yes&noui=yes&jump=close&url=${url}&title=${title}

If you’re a Pinboard user, enjoy!

One-way MySQL DB Syncing for Dummies

June 3rd, 2009

To ease my development while on the move, I have local development copies of my websites running on my MacBook Pro. This has always worked pretty well for me, as content for my websites was created, predominantly, by myself, and when new content was created at a single site I could sync that database manually and get an up to date local content set.

With my recent efforts into lifestreaming, this is no longer the case. My content now comes in whenever I post content on any website. I’m a fairly frequent user of the internet services that feed my lifestream (Twitter, Delicious, Flickr, etc), and keeping the content on my local version up to date was turned into a troublesome task, forcing manual, tedious syncing each time I went to work.

Without further explanation, here are the steps I took to make a one line MySQL database syncing command. There may be better ways to do this and if you know them, please comment.

1. Setup a MySQL “dump” user. Mine is cleverly named “dump” and is passwordless, although if you are more security conscious than I am, you can add a password of your choosing. On the server, log into mysql and issue this GRANT statement from a user with the proper permissions.

1
GRANT SELECT, LOCK TABLES ON `dbname_remote`.* TO 'dump'@'localhost';

2. Create a bash alias
~/.bashrc :

1
ALIAS clone_lifestream='ssh -q -t hostname "mysqldump -u dump dbname_remote" | mysql -u root dbname_local'

Notes: For this example, you need to replace a few things.

  1. dbname = the remote database name
  2. hostname = the remote hostname
  3. dbname_local = the local database name
  4. clone_lifestream = the name of the alias, can be anything.

Hashtag and Username Linking in Twitter Apps

May 12th, 2009

Are you trying to add automatic hashtag and username hot linking in your PHP twitter app?

I just tried to do this with my amdavidson.me lifestreaming site. It’s just two nested regular expressions. If there’s some problem with nested preg_replace functions, or if any regular expression geniuses have better ideas, feel free to comment.

But if not, here’s a little code for you, should make things super easy. It assumes your tweet variable is $tweet, replace with whatever you’d need.

1
2
3
4
5
echo preg_replace('/\#([a-zA-Z0-9_]{1,15})?/',
"<a href=\"http://hashtags.org/tag/$1\">#$1</a>",
preg_replace('/\@([a-zA-Z0-9_]{1,15})?/',
"<a href=\"http://twitter.com/$1\">@$1</a>",
$tweet));

Minimalism Revisited

May 4th, 2009

Well, this site just got more tweaking today to make the theme feel a bit more “andr3w”. I’m pretty comfortable with it now, it will certainly still change, but I don’t think it will be all that much.

The theme that I based my theme on is called Minimalism and it was done by Christian Geneahr. In turn it was based on the classic Kubrick, a theme so widely used and appreciated, I would call it the “Pappy” of all Wordpress themes.

With Kubrick’s fine lineage, Christian was able to make quite a nice minimalist theme. It just needed a couple more refinements for me to feel totally comfortable with it and now that my changes are somewhat stable, it’s time for me to do my GPL duty.

So, without further adieu: Minimalism-Revisited.

Length Errors in Apache Bench

May 4th, 2009

Are you seeing errors for content length in your Apache Bench tests of your webserver?

I had a hell of a time wondering what was going wrong with my webserver under load and finally found the answer here.

Turns out that Apache Bench takes the first pulled request and compares the length to all subsequent requests. Makes sense for a purely static page, but when you have a random image cropping up, you’re sure to see at least a couple bits difference in length.

So if you’re serving straight, hand coded HTML, enjoy the feeling of knowing that you’re getting the same length content each and every time… but if you’re like the rest of us (and anyone who would actually be using Apache Bench) feel free to rage that there’s no command line switch to turn off that silly notification.

Updated .mailfilter for Courier Maildrop and SpamAssassin

April 26th, 2009

My spam count has exploded in the last few days, so I made a decision to adjust my filtering a little more.

Previously, all messages that got more than 5 points in SpamAssassin tests were flagged and sent to my .Spam folder. This got to be a bit of an issue as I still check there to make sure that no emails are miscategorized… Call me crazy, but I’m a bit anal when it comes to that stuff. (I missed an interview because of Gmail’s filters, but that’s a story for another day).

For the last few days, I’ve been reviewing the spam counts for both the more cleverly hidden spam and the less-than-clever spam. I’ve come to realize that while the odds are low that any real emails will get marked as spam if they do they’ll definitely get a score less than 10. So to combat the large amount of spam that’s now coming through, emails with greater than 10 points will now be sent directly to the trash.

Here’s what I put in my .mailfilter file for courier-maildrop:

1
2
3
4
5
6
7
8
9
if ( /^X-Spam-Level: \*\*\*\*\*\*\*\*\*.*$/ )
{
exit
}

if ( /X-Spam-Flag/ )
{
to "$DEFAULT.Spam"
}

This way, anything that gets more than won’t even be delivered, and all other emails that get a spam flag (greater than 5 points) get sent to spam, then the rest of my filters are processed.

Tested the email with the GTUBE and with a normal message and it seems to work, but we’ll see if I wake up in the morning and all my email has been dumped in the trash can.

Sweetcron Stream Updating Cron Job

April 20th, 2009

So the Sweetcron documentation isn’t altogether clear on what you should put in cron for it to update automatically, rather than slowing down a user every 30 minutes.

It’s fairly intuitive, but for those missing this logical step, do the following.

Change the setting in the admin panel from psuedo-cron to true-cron, and take note of the URL.

Then put the following in your crontab file (easily accessed with ‘crontab -e’ on a debian machine):

1
*/5 * * * * curl http://your/true-cron/url

You can change the 5 to be the number of minutes between updates that you want, and you’ll definitely want to change the URL to the one listed in your Sweetcron’s admin page.

Lifestreaming via Sweetcron

April 20th, 2009

Had a Tumblr setup for a while at amdavidson.me but I already have a webserver and didn’t like dealing with another host.

So I searched around a bit and Sweetcron came up as a viable alternative for an aggregator for all my internet activities. It’s a pretty cool little app, very lightweight and seems to be pretty extensible, if I get around to it.

Anyways, check it out, it has a good summary of all the useless stuff that I do on the internet, all three of the blogs, my twitter account, my delicious bookmarks, and my flickr pictures. One stop shopping.

Site Redesign

April 13th, 2009

Changed up the site a little. More to come, wanna try my hand at making the typography interesting.

I just thought the old design was a little over done, so thanks to the awesome theming capability of Wordpress… Here’s a new one.