avocado shake (dot) net

journal

How to watermark images on the command line

The command: composite

The key options:

  • -dissolve <0-100>
  • -gravity <north|south|east|west|northwest|northeast|southwest|southeast>

Full command:

composite -dissolve 80 -gravity southeast watermark.png orig-image.jpg new-image.jpg more details

Throttle aggressively (especially the statistics module) to survive the Digg effect

Wise Bread has been very popular on Digg the last few weeks. Every time we get Dugg, the server crawls. We've been making incremental tweaks, but today, we found a tweak that relieved all the pressure at once:

Throttle the statistics module!

It's been said before, but we didn't do it in order to preserve the list of popular today/all-time articles in the sidebar. Everything else we throttled. For previous Diggings, that level of throttling along with making the popular article a static file was just enough to make the site load very slowly. (That's better than when we were getting WSOD or 503 unavailables.)

Today when the number of anonymous users online stayed high (around 1800) for a couple of hours (and the site was unresponsive), we knew more stuff had to go. As soon as we throttled statistics, search and comments, the load on the server dropped to zero. We ended up unthrottling comments and the load was still acceptable, so we'll keep that on. But definitely no more statistics during high load conditions.

Bottom line: If you want your content (at least the article) to be read during a Digging, throttle aggressively. Throw out everything except the article itself if you have to!

Use module_invoke() instead of calling the function directly

If you want to call a function from another module, use the module_invoke() hook instead of calling the function directly.

I ran into a situation where we had to throttled the statistics module. Errors started being thrown to the page because I was calling statistics_get() in my theme. Here's the code:

      if ( module_exists('statistics') && user_access('view post access counter') ) {
        $statistics = statistics_get($node->nid);
        if ($statistics) {
          $mylinks[] = format_plural($statistics['totalcount'], '1 read total', '@count reads total');
          $mylinks[] = format_plural($statistics['daycount'], '1 read today', '@count reads today');
        }
      }

We were getting into trouble with the statistics_get() call in the second line. As you can see, even though we check for the existence of the module first with module_exists('statistics'), it didn't cover the case when the statistics module is enabled but throttled.

By using module_invoke() instead, this block won't throw errors even if the referred module is disabled or throttled.

To construct a module_invoke() call, simply make the 1st argument the name of the module, the 2nd the part of the function name after modulename_ (called the "hook" in Drupal speak), and the remaining arguments are what should be passed on to the function.

So this: statistics_get($node->nid)

Becomes this: module_invoke('statistics', 'get', $node->nid)

Back to my real world example. My above code that threw errors when statistics was throttled works perfectly fine after changing it to this:

      if ( module_exists('statistics') && user_access('view post access counter') ) {
        $statistics = module_invoke('statistics', 'get', $node->nid);
        if ($statistics) {
          $mylinks[] = format_plural($statistics['totalcount'], '1 read total', '@count reads total');
  

Hunkering down

What happens when you're preparing for the next major phase of your company? When you're building the foundation and infrastructure necessary to carry you through the long uphill battle towards profitability? You hunker down. Suddenly your world is much smaller and nothing outside this little sphere of concentration matters.

Your social life all but disappears. And other "normal people" things get dropped too. The Netflix sits on the dining table for weeks, you miss out on awesome apartments because your head's not in the game, and you live on frozen burritos and caffeine.

I love it.

On a somewhat related note, I may have to try this 28-hr day routine (xkcd.com). It sounds perfect for me.

How to disable TinyMCE per fields in Drupal

There is a theme() function in the Drupal tinymce module that lets you (the admin/webmaster) turn off the rich text editor on a field by field basis.

Basic steps to disable TinyMCE in a specific Drupal form field:

  1. Look in your modules/tinymce/tinymce.module file.
  2. Search for "theme_tinymce_theme".
  3. Copy the entire function to your theme's template.php file.
  4. Rename the function from theme_tinymce_theme() to yourthemename_tinymce_theme(). (Substitute "yourthemename" for your theme's name.)
  5. Add a line to the switch($textarea_name){} block that specifies the name of the textarea you would like to exclude. Use the existing examples as a guide.

I wanted to disable the RTE for a custom plain text field in the node edit form. The field's name is "field-teaser-0-value". This is the line I added (marked with "KA") with some surrounding logic: (The fully modified theme that I put into my template.php is at the end of the post.)

 

function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
switch ($textarea_name) {
case 'field-teaser-0-value': // KA: blog teaser (we want plain text only)
unset($init);
break;
}
}

 

To find the name of the field in question, load the form in your browser. Check the source code. Look for the name="" attribute for your field. That's the string you insert into the theme function.

Tip! For CCK (content) fields where the name is something like "field_teaser[0][value]", you need to replace the non-alphanumeric characters with a dash. So the $textarea_name variable for this field is actually written as "field-teaser-0-value".

Here's the final customized theme function I placed in my theme's template.php file. My theme is called "avocadoshake" and my comments are marked with a "KA".

Drupal learning curve

This is Dries' approximation of the Drupal learning curve. I think it's a pretty accurate visual representation of walking the Drupal path.

I'm just starting to cross into the "I kick ass" level. Woo!

Drupal definitely had a tough starting curve, but the D5 release went a looong way towards fixing that. The proof is in the explosion of drupal.org nodes and the number of modules that have since been released. Drupal is crossing into upper echelons of CMSes.

 

WB to D5

Just finished upgrading WB to Drupal 5. Now the fun of building it out begins.

Facebook

I guess the Facebook revolution has caught up with me. Recently a bunch of old friends started adding me to their Facebook friends' list. That got me back on the site to browse these lists and I started adding friends myself. Once I added one, I needed to add more. It's like an arms race.

What? My friends have 50 friends while I only have 5?? Unacceptable! I need to add more....

This follows right in line with how I interact with social networking sites like Facebook, MySpace, LinkedIn, even Friendster. Check em out, ignore, add a bunch of people, then ignore forever.

First impressions - I create a bare bones profile and make it restrictive. I don't want/need more spam from yet-another-upstart social site. I add a few people, probably the same ones that made me aware of FaceMyLinkedFriendster. Ignore profile for months.

Second impressions - My second encounter with a social site is when some random friends find me online. This usually leads to a rash of friends requests as my profile is added from friend-to-friend. I guess this would be the viral nature of social networking in action. After 2 or 3 of these new friends requests, my interest in the site is piqued again. Usually the interest revolves a sick need to gather virtual friends. Adding friends to my profile becomes a mini-game in my head. How many "friends" can I find via my virtual circle? During this phase I'll also beef up my profile by making it more open, adding more details about me, etc. I might even add a few widgets or what-not just to play with the platform a bit more.

Then....

Nothing - I'm not a big social networking guy. I have a trail of long abandoned profiles from Friendster to MySpace. Usually, nothing much comes of these social networking profiles. Sometimes I'll rekindle an acquaintance and start some email conversation. That's cool. Most of the time, the profile just wilt and get abandoned.

The one social networking site that might have personal value to me is LinkedIn. They don't ask for very much and there isn't anything to really keep you on the site, so I actually feel like I'm keeping up with what is expected of me. With the other sites, I feel like if I'm not constantly on the site adding friends, leaving comments on walls, adding cute widgets, etc that I'm not a valuable member of the community. And I wouldn't be. The point of Facebook, MySpace and Friendster was to keep you on the site, increasing their pageviews and thus their revenues. With LinkedIn, the focus is on building a professional network. And pros don't expect (or have the time) to socialize virtually.

On LinkedIn, I feel like a member of the community just for having a profile. On FaceMyFriendster, I feel like an outside because I only have a profile.

Tracking time

I need to improve my productivity. Tannaz suggests using a kitchen timer. I like that idea so I bought this kitchen timer. 10 bucks at Amazon.

Bourne midweek

Watching movies on a midweek afternoon is all that it's cracked up to be. And more. The lack of a crowd is awesome.

Granted, it wasn't as awesome as the last time I did it 7 years ago when my boss took a few of us to watch Pitch Black. I was just starting out then and thought it was the coolest thing in the world. Never happened again though.

I went to see The Bourne Ultimatum this afternoon with Alex.

It was pretty good. After 3 of them, you start to recognize the formula. Hand-to-hand fight sequence (no music so it's grittier), multiple bad guy takedowns (several of those), car chase with lots of damage (trail of carnage in NYC, check), foot chase using oh-so-clever evasive maneuvers (check, check, check). I lost count after a while, but it sure felt like there were a lot of chase sequences. Exciting, yes. But they're always chasing each other. It was getting a bit old by the end.

I was entertained. It's a good addition to the Bourne series of well done action-spy movies.

Avocado Shake (dot net) is the personal website of Gregory Go, co-founder of Killer Aces Media and Drupal fanboy.

Full text blog feed

My Tumblog

FriendFeed Stream

Essential Skills of a Community Manager
From Google Reader, posted Saturday, July 26, 2008 - 21:12.
Cartoon: Fannie Mae & Freddie Mac
From Mixx, posted Saturday, July 26, 2008 - 21:04.
Essential Skills of a Community Manager
From Google Reader, posted Saturday, July 26, 2008 - 20:24.
Picturing Casualties In Iraq: Slide Show
From Mixx, posted Saturday, July 26, 2008 - 20:20.
Submitted: 19 Tips for Cheering Yourself Up -- From 200 Years Ago
From Mixx, posted Saturday, July 26, 2008 - 20:03.
Submitted: 3 Tips for Losing Weight on a Budget
From Mixx, posted Saturday, July 26, 2008 - 19:50.
Submitted: How to Deal with a Partner That Hides Money Problems
From Mixx, posted Saturday, July 26, 2008 - 18:10.
Blogging's Glass Ceiling (Kara Jesella/New York Times)
From Google Reader, posted Saturday, July 26, 2008 - 18:02.
How to increase submit speed from 45s to a fraction while keeping Akismet anti-spam - Pligg Forum
From del.icio.us, posted Saturday, July 26, 2008 - 17:26.
Lazy Linux: 10 essential tricks for admins
From del.icio.us, posted Saturday, July 26, 2008 - 16:21.