Kohana book for Coda

Kohana Book for Coda

This is book number two for Coda. NOM is currently working on a project built with Kohana, a framework originally based on CodeIgniter.

Their marketing copy reads something like this:

Kohana is a PHP 5 FRAMEWORK that uses the MODEL VIEW CONTROLLER architectural pattern. It aims to be SECURE, LIGHTWEIGHT, and EASY to use.

This book cover is much simpler than the one i produced for Subversion here. I quickly came to realize that there’s no point at all in spending the time to make such a complicated image.

Book Title: Kohana
URL: http://docs.kohanaphp.com/
Simple cover: KohanaBook.png
Use for Mode: PHP-HTML
Search URL: http://docs.kohanaphp.com/?do=search&id=*

Subversion 1.6 book for Coda

Subversion Book

I was just reading through Adding more Coda Books, and thought that if you were going to add Subversion’s documentation to Coda, it deserved an okay looking cover. I also thought that linking to the nightly documentation wouldn’t be a bad idea either.

For SVN 1.6 nightlies

Book Title: Subversion 1.6
URL: http://svnbook.red-bean.com/nightly/en/svn-book.html
Simple cover: http://www.naterkane.com/blog/wp-content/uploads/2009/09/SubversionBook.png
Use for Mode: None
Search URL: http://www.google.com/search?q=site:svnbook.red-bean.com%20*%20

For SVN 1.5

Book Title: Subversion 1.5
URL: http://svnbook.red-bean.com/en/1.5/svn-book.html
Simple cover: http://www.naterkane.com/blog/wp-content/uploads/2009/09/SubversionBook-1.5.png
Use for Mode: None
Search URL: http://www.google.com/search?q=site:svnbook.red-bean.com%20*%20

cputhrottle lets you limit cpu consumption on osx

I’ve been having some issues with a particular App consuming a serious amount of processing lately, and it’s really been driving me nuts. having 7/8th of your total processing on a macbookpro (2.6 GHz Intel Core 2 Duo w/ 3 GB ram) will make it run really hot. After seeing that my cpu temp was hovering at around 170 degrees, and the cpu fans maxed out at 6000 rpm, I opened Activity Monitor and saw this: (note: the App that’s eating so much CPU is not shown to protect the guilty)
Activity Monitor

So I posted a message on twitter to see if there’s anyone who follows me who might be able to suggest a solution.

if anyone can tell me how to limit the % of cpu a process can be allowed to use on osx, please let me know, and i'll be your best friend.

Then just a short 2 minutes later, Ryan Barr (@ryanbarr) came through and pointed me in the right direction.

cputhrottle is a small OS X command-line utility designed to limit the CPU usage of a process to which it attaches.

I found that even though I have a utility installed to increase the fan speed when CPU temperature increases, sometimes I would run jobs that maxed out the CPU for long periods — and this caused my MacBook to get extremely hot. Within the space of a couple minutes, the temperature displayed had jumped by over 40 degrees Fahrenheit.

The utility takes a process ID (pid) and a percentage amount to limit. For example:

sudo ./cputhrottle 328 25

Running this command would limit process 328 to a maximum of 25% CPU usage.

Note that cputhrottle needs to be run with root privileges to be able to attach to the process to control. I recommend doing this via the sudo command.

Source code is below, as well as a pre-compiled binary (OS X 10.5.1, Intel). If there is any interest in a PPC version I would be willing to cross-compile one. The program requires that Boost 1.33.1 be installed to compile. Run make all to build cputhrottle and a test program.

The source hopefully will be interesting to those looking into how to manipulate processes in Mac OS via mach system calls. The code is a subset of code I was working on to create a simple debugger as an alternative to gdb. Obviously, this project was much simpler and ultimately more useful.

cputhrottle makes use of the task_info, task_suspend, and task_resume calls. task_info and task_threads are used to collect CPU usage statistics on the process, and the program then suspends/resumes the attached process appropriately until the CPU usage has stabilized. Any errors occurring are assumed to be a result of the attached process exiting, and result in cputhrottle also exiting. Control-C is intercepted, and the attached process allowed to resume gracefully before cputhrottle exits.

Source: cputhrottle.tar.gz

Binary: cputhrottle.gz

Note: Thanks to Nikolaj Schumacher for pointing out a race condition whereby a thread being sampled could have ceased to exist after having been enumerated as existing within the process. Specifically, he noticed this while throttling Handbrake, which creates/kills threads in rapid succession. I have applied his patch and the new sources and binary reflect his changes. I tested the fix and cputhrottle behaved as before (for my test case).

Contact email: nolanw, followed by an underbar and then the word “commerce” at willnolan dot com

http://www.willnolan.com/cputhrottle/cputhrottle.html.

Aptana and Lighthouse for easy ticket tracking

Aptana and Lighthouse can finally come together thanks to Aptana 1.5 and the Mylyn Web Template connector.

I've been a fan of Aptana for quite awhile, through all of it's ups and down as it's development I've generally still managed to prefer it over other more common 'bare-bones' editors like TextMate. Admittedly, a lot of this has to do with Aptana's ease of install and support for Subclipse.

Public/stable builds of Aptana have been running on Eclipse 3.2 for what seems like forever, and one feature that I've always had want for, is bugtracking integration. Mylyn is a great Eclipse plugin that does just that, well, sort of. The versions of Mylyn that run on Eclipse 3.2 haven't seen an update in ages, and support little more than Mantis, Jira and Trak. When I had a decent number of projects that were using Trak or Mantis, I was in heaven; NOM's migration to relying on 3rd party SaaS tools has made administration of our ticketing software and repositories a snap, but I haven't had any way to integrate our preferred ticketing software (Lighthouse) into my personal workflow until now.

Since last november (at least) Lighthouse has now been able to be integrated with Eclipse with the Mylyn's Web Templates connector. The only catch... it's still requires at least Eclipse 3.3+. Fortunately, the next version of Aptana, currently called Apana Andretti Alpha is built on Eclipse 3.4, and though it seems to have some memory consumption issues (it is an alpha remember!), I was able to find a copy of it here and get everything sorted and working together nicely. And let me just say, my life has became a little bit easier.

Simen Brekekn was generous enough to post about his setup over on Lighthouse's support site here. Below is his info, with some added/updated information.

  1. Make sure you're running Eclipse 3.4 or above (or grab a copy of Aptana's Andretti Alpha #3 here http://www.aptana.com/node/577Aptana 1.5 here)\
  2. In Eclipse/Aptana install Mylyn from the Mylyn update site
    http://download.eclipse.org/tools/mylyn/update/e3.4 (Eclipse 3.4, 3.5, Galileo Packages)
    http://download.eclipse.org/tools/mylyn/update/e3.4 (Eclipse 3.3)
  3. In Eclipse/Aptana install the "Mylyn Connector: Web Templates" form the Mylyn incubation update site ( http://download.eclipse.org/tools/mylyn/update/incubator )

Then add a new Task Repository and enter the following information:

Please note that the query pattern in this screenshot is incorrect.

Please note that the query pattern in this screenshot is incorrect.

  • Enter the full url of your project, ie. http://foo.lighthouseapp.com/projects/123
  • Give the task repository a Label
  • Enter your authentication info (if it's a private project)
  • Then add the following settings under "Advanced Configuration":

  • Task URL: ${serverUrl}/tickets/
  • New Task URL: ${serverUrl}/tickets/new
  • Query Request URL: ${serverUrl}/tickets.xml?q=${query}
  • Query Pattern (make sure you enter it in one line):
XML:
  1. <ticket>.*?<assigned -user-id type="integer">({Owner}.+?)</assigned>.*?<number type="integer">({Id}.+?)</number>.*?<state>({Status}.+?)</state>.*?<title>({Description}.+?)</title></ticket>

Next enable HTTP Authentication, enter your login (again), click Finish and you're all set!

completely suppressing errors in php

This is something that's been bugging me for awhile, and I never really bothered to dig in and see what I could do to work around it, until now.

unserializing an unserializable string

The easiest, and most popular way to check if a string is serialized is simple.

PHP:
  1. /**
  2. * Is a string serialized?
  3. *
  4. * @param string
  5. * @return boolean  
  6. */
  7. function isSerialized($str)
  8. {
  9.     if ($str === 0)
  10.     {
  11.         return false;
  12.     }
  13.     else
  14.     {
  15.         return ($str == serialize(false) || @unserialize($str) !== false);
  16.     }
  17. }

Quite a few very popular frameworks and apps do it this way, try to just simply pass the string to the unserialize method, make sure it isn't the boolean false, and prepend the method with an @ to suppress notice-level error output. Don't get me wrong, it works. But if you're logging your notice-level errors, then any time you're trying to check if a string is serialized in this way, it logs the notice that's generated. Storing data as a serialized hash in a key-value database (Tokyo Cabinet — which we've chosen to use for Nomcat, BerkeleyDB, CouchDB, Redis, etc.) magnifies the scenario and takes this wee-little_old Notice, and makes your logs fill up really fast. Since error logs are for tracking issues that a developer should really concern themselves with, logging all of these notices just wouldn't do, it's simply a waste of space and processing time to handle them over and over and over again.

As we've been building Nomcat over at NOM, we're often faced with dozens of reads from the data storage layer with each view that's generated, and recently while testing, we've run into log files that look something like this.

CODE:
  1. ERROR - 2009-06-04 01:49:15 --> Severity: Notice  --> unserialize(): Error at offset 0 of 1 bytes /path/to/application/libraries/App_Model.php 432
  2. ... a couple hundred lines ...
  3. ERROR - 2009-06-04 01:51:19 --> Severity: Notice  --> unserialize(): Error at offset 0 of 1 bytes /path/to/application/libraries/App_Model.php 432

just set_error_handler to an empty method

Initially I tried a few different options to work around this annoying little problem.

  1. Prepending the unserialize method with @ to suppress output, but it doesn't prevent logging.
  2. Wrapping in a try-catch block doesn't do the trick
  3. Wrapping it with error_reporting(0) and error_reporting(2) doesn't do the trick either
  4. But creating an method to handle the error, have it to nothing, and wrapping the unserialize line with set_error_handler and restore_error_handler does the trick!

This is what I came up with.

PHP:
  1. /**
  2. * Is a string serialized?
  3. *
  4. * @param string
  5. * @return boolean  
  6. */
  7. function isSerialized($str)
  8. {
  9.     if ($str === 0)
  10.     {
  11.         return false;
  12.     }
  13.     else
  14.     {
  15.         set_error_handler(array('App_Model','unserialize_handler'));
  16.         $return = ($str == serialize(false) || @unserialize($str) !== false);
  17.         restore_error_handler();
  18.         return $return;
  19.     }
  20. }
  21.  
  22. /**
  23. * dummy error handler set up to obsorb any errors thrown by isSerialized
  24. * @return
  25. * @param object $errno
  26. * @param object $errstr
  27. */
  28. function unserialize_handler($errno, $errstr)
  29. {
  30.    // don't do anything
  31. }

If you noticed that I'm passing an array like this: set_error_handler(array('App_Model','unserialize_handler'));, you've got a good eye. This is how you can specify in which class to find the method you want to use as a callback, neither $this->methodname or Classname::methodname will work. However if you aren't writing object oriented code, you can simply pass the name of the method you want to use to handle the error as a string like this: set_error_handler('unserialize_handler');.

Let me know how it works for you.

Similar Posts

Categories

Archives

About

Nater Kane is freelance developer and user experience & technology consultant based in Brooklyn, NY.

Nater's focus is on creating a semantic and accessible web, and having delighted clients with happy customers.

He likes to spend time playing with his cats, playing drums, working on his diesel vw rabbit and his motorcycle, and enjoying a decent espresso.

RSS

Twitter » What I'm Up To

How I'm Social

Basecamp

Meta


Nater Kane naterkane personal http://www.naterkane.com LinkedIn Profile Web Technologist personal nater@naterkane.com 1978-09-12 voice 845.234.6698 | fax 707.922.0593
964 Flushing Ave. Brooklyn, NY 11206