Conditional logic in functions

When defining a class method in ruby, you can put conditional logic around the function declaration. This allows you to define separate methods based on your environment.

Example:

if VERBOSE
def trace(message)
puts message
end
else
def trace(message)
print “.”
end
end

mysql wordpress site url change

Mysql statement for changing site url:

UPDATE {table_prefix}wp_options SET option_value = replace(option_value, ‘http://oldlocation’, ‘http://newlocation’) WHERE option_name = ‘home’ OR option_name = ’siteurl’;

Model.find_each

If you’re recursively looping through all your active record models, using Model.find_each is more efficient than Model.all.each. This incrementally polls the database without requiring the entire result set to load into memory.

Injecting backup databases

Here’s a command for inserting .sql files into a new database

mysql -u root -p database_name < db.sql

Finding your adobe serial numbers

I recently upgraded my computer to a macbook pro and realized that I didn’t record which of my company’s serial numbers I had used. I definitely didn’t want to duplicate our licenses forcing me to retrieve the serial number I had entered 6 months ago.

In Mac OSX, I found the serial number located in: Users > Shared > Adobe > ISO-19770 in a file called “Creative Suite 4 Design Standard-DesignSuiteStandard-CS4-Mac-GM-en_US.swtag”. The file wasn’t immediately recognized by any application but can be opened by any text editor. Scroll all the way to the bottom of the file, and you’ll see:


xxxxxxxxxxxxxxxx

Voila….. your current serial number.

Quick function for moving a sprite to the highest depth

private function moveToHighestDepth(displayObject:*):void{
      var curParent = displayObject.parent;
      curParent.removeChild(displayObject);
      curParent.addChild(displayObject);
 }

Flash NetStream request headers

For the past few weeks I’ve been experimenting with different ways of serving up flv’s through different servers (ie…. nginx with installed streaming module). However, we wanted to see how S3 would deal with our need for streaming video. S3 does not support the ability to change a get param into a request header for doing byte offsets. Why is this important?… typically, flvs served up by youtube and other services allow requests to pass in the start point of the stream. This allows a user to fast-forward past the download buffer to any section of a video. The servers are returning pieces of the video file.
I always wondered why this was such a big deal requiring specific modules to be compiled into nginx until I started playing around with http headers directly. So….. here’s the deal. S3 (a service of amazon), allows requesting byte offsets through HTTP Headers. This is great, but alas…. Adobe has let me down. HTTP Headers cannot be implemented through the NetStream Class even though the documentation says otherwise. The HTTP Headers supported by the netstream class are proprietary and only work with Flash Communication Server. This is completely ridiculous.
This also manifests in a couple other ways. You may have noticed that NetStream documentation shows an event attached to videos: NetStream.Play.Complete . I expected this event to be called when the video finished playing…. but nothing happened. After a little digging, it turns out that NetStream.Play.Complete is only available if you’re serving up videos from Flash Communication Server.
Flash video is one of the most frustrating things to deal with because of their closed source pos http request that’s clearly broken. Anywho… I feel like this is a pretty serious issue that needs to be fixed. Why can we use HTTP headers to request data, but not to request a stream? It just doesn’t make any sense.

Reset lost admin password in wordpress

Good quick tip on how to reset an admin password in wordpress.

http://www.corey-m.com/blog/?p=325

Wordpress and sphinx search

Looking into different options for better searching in wordpress. Currently wordpress uses a simplistic database query search that doesn’t allow much flexibility. This solution doesn’t scale well either. In all the rails projects I’ve been working on, Sphinx search has been pretty solid for finding related documents, and handling all our search functions away from our user facing servers. Indexing and memory usage are extremely efficient keeping our server costs low. This is fantastic.

While RoR is our preferred development framework, every once in awhile, we’ll slap together a wordpress site and I haven’t seen anyone try to implement sphinx as a plugin partially because it requires a bit more tinkering. However, recently I came across the following plugin that seems to provide a wordpress interface to the sphinx service. https://launchpad.net/wp-sphinx-plugin/+download

It looks promising and seems to autoconfigure the indexes for you including title, Posts, Pages and Comments. I didn’t see anything in readme about indexing tags which might be an issue. I’m also going to see if it includes functionality for providing field weights for preventing false positives.

Conventions

class names in css should be noun-adjectives.

Wrong:

<div class=”medium-icon-sprite”></div>

Correct:

<div class=”icon-medium-sprite”></div>

Icon is a noun followed by two descriptive adjectives.

Place header tags outside of links:

wrong:

<a href=”#”><h2>Title</h2></a>

correct:

<h2><a href=”#”>Title</a><h2>