Entries Comments



Category: Coding


Logins with mod_rewrite, Cookies, and Javascript Redux

10 December, 2008 (22:44) | Coding, Web | By: benjamin

A while back I posted a simple solution for restricting website access in a situation where HTTP basic authentication couldn’t be used.

Not much more to the story, but I did make a few tweaks to my sample code. The mod_rewrite rule and javascript have been a tiny bit improved, so now after a successful login, it will try to redirect you to where you intended to go. (Previously, it always sent the user to /) 

Also, in the comments I made it MUCH clearer that this is NOT intended to be a secure solution, just a simple way to keep Google and random people out of things. Anyone with a basic knowledge of HTML/Javascript/Cookies (or less than basic) could read the source and figure out how to create the “secure” cookie, and BAM they’re in like Flynn.

WordPressMU Plugin Commander

7 December, 2008 (23:56) | Coding, Web | By: benjamin

I’m solidly impressed with the WPMU Plugin Commander. One thing that seemed odd to me about WPMU was that I either enable users to have plugin control, or NO ONE (not even the site admin) has the ability to enabled/disable plugins (without a lot of hacking).

This plugin provides a control panel where I can globally enable/disable plugins, set plugins to be auto-enabled for new blogs, and give users the ability to enable/disable only selected plugins.

The perfect scenario is, I want to auto-anable Akismet for my users, so they get spam filtering on comments. Also, I want them to have the ability to try out other various plugins, but don’t want them able to turn off Aksimet.

I’ll echo the sentiments of others I read when discovering Plugin Commander, “this functionality should be in WPMU core!”

WordPress Regenerate Thumbnail Plugin

7 December, 2008 (22:57) | Coding | By: benjamin

I was literally sitting down to write a plugin that did this, when I stumbled across Viper007’s Regenerate Thumbnail plugin.

I could still write my own version, but eh, what’s the point. :) Seems to work great!

Use vi key bindings in bash

3 December, 2008 (22:29) | Coding, Linux, Mac | By: benjamin

A long time ago I used ksh with vi key bindings, and life was good.

Then I moved on to bash, but for some reason, I never investigated using vi key bindings. I simply lived with the defaults (which, for the record, are emacs-like key bindings).

So, just the other day I said to myself, “Self, I want to use vi key bindings in bash. I want to again experience the joy of traversing and editing my command line in COMMAND MODE. I want the speed and the power of my precious vi (well, I use vim) at my finger tips. And I NO LONGER want to waste time holding arrow keys or to think about using emacs-like commands.”

So, I fired up google.com; low and behold I stumbled onto this little post about using vi key bindings in bash and zsh. So sweet!

In a nutshell, the bash command to enable vi mode is:

set -o vi

This can be set in your .bashrc file, and if it doesn’t pickup when you start a new terminal session, add something like this to your .profile or .bash_profile:

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

With vi mode enabled, you’ll start your bash session in insert mode, so things should behave as normal. But, to turn on the power, just hit the ESC key to enter COMMAND MODE. :) Now all your vi commands are availble. Move to end of line with “$”, beginning of line with “^”, delete a word with “dw”, etc.

Enjoy!

A Project Idea: iPhoto to Wordpress [gallery] Export

22 October, 2008 (22:52) | Coding, Mac | By: benjamin

I’ve been spending some time getting my son’s blog setup. In doing so, I discovered that as of Wordpress 2.5, there is built-in [ gallery ] functionality.  Though it isn’t full featured, it’s pretty nice, and perfectly integrated with Wordpress, since, well, it IS Wordpress.

Currently the process to put photos into a gallery is:

  1. Choose photos in iPhoto
  2. Export chosen files to disk
  3. Create new Wordpress post
  4. Add media via Wordpress uploader

This isn’t too bad, especially for a geek who’s used to lots of arcane workarounds to accomplish simple goals. But… for my wife or others who don’t want the hassle, this is basically annoying.

So I have this idea to create an iPhoto export plugin which will upload directly into Wordpress!

Roadblocks to completion:

  1. Time and Commitment (typical)
  2. Objective-C (don’t know it)
  3. Cocoa (don’t know it)
  4. X-Code (don’t know it)
  5. Non-Javascript/Java development on Mac OS X (new to me)

So… this is going to be a slightly ambitions undertaking… but I’m excited about it! I’ll be learning a bunch of new stuff. It’ll take more time than I’d like, but I expect it to be a rewarding process. At some point, I’ll be able to create a “project” home for this bad boy, and make it available to all!

If anyone has pointers on OS X development, I’m all ears. :-)

Good Post on Using Ant for Solid Build Process

20 June, 2008 (14:35) | Coding | By: benjamin

I use Ant for my Java projects. It’s a great and powerfule build too. However, there’s always more than can be done to improve the quality of the build process.

I found this nice article that gives some good examples of a complete build process with Ant: dev, test, prod, etc.

Investigating OpenID

27 May, 2008 (09:02) | Coding, Networks, Web | By: benjamin

Aaron (one of my co-workers), recently posted a link about OpenID. I’ve given OpenID only cursory glances over the last year, but the Coding Horror link in Aaron’s post had a comment to this Google Video where Simon Willison gives a Google Tech Talk on The Implications of OpenID. The video is nearly a year old, but to date, it’s done more to convince me to get on the OpenID bandwagon than anything else.

Logins with mod_rewrite + Cookies + JavaScript

28 February, 2008 (21:05) | Coding, Web | By: benjamin

I recently had an odd situation come up, though it’s not incredibly hard to imagine. I needed to create a staging web server, identical to production, but it should live on a different hostname (eg, staging.holyarmy.org, instead of www.holyarmy.org). The content should not accessible to the public, nor to search engines. This isn’t really so much a privacy or security issue as it is a convenience and customer service issue. If search engines somehow picked up on our staging site (and they would, given it’s full of SEO triggering info, google analytics scripts and the like) then our search information could become poisoned with the staging URL. Also bad would be if a customer found the staging site and posted information to the wrong place. I’ve actually seen both of these happen in the past when measures were not in place to prevent it.

Read more »

Fixing Binary File Corruption from Ant Copies

31 October, 2007 (20:44) | Coding | By: benjamin

So there I was, poking around in some java / j2ee code, trying to learn how it all works. I did some testing on a Linux server and realized, something is broken. It seemed something was corrupting ALL the Jar files in WEB-INF/lib/.

A co-worker guessed that the token filtering Ant was doing might be the culprit. He was right. It seems Ant has issues with detecting whether files are binary or not, given that it uses a Reader class which runs the files through a character decoder. This is specifically a problem on Unix systems since they commonly use UTF8 character set, and in that case Ant hasn’t a clue if its looking at UTF8 text or binary data.

So, I used a trick suggested in the Ant docs:

Another trick is to change the LANG environment variable from something like “us.utf8″ to “us”.

On the Linux box, this meant we had a default character set of en_US.UTF-8 and it needed to be en_US. In this case we already had a bash shell script that runs ant, so adding a line export LANG=en_US to that script before Ant ran solved the problem.

Reference:
http://ant.apache.org/manual/CoreTasks/copy.html#encoding