Better New Relic reporting on sites with Panels
My last week at DoSomething I spent some time working on getting better metrics on which panel pages are slow. One half of that was to use New Relic's PHP API to provide better transaction names that included the node type and panel name:
<?php
/**
* Implements hook_page_alter().
*
* We want to provide more detail to New Relic on the transaction and late in
* the page build seemed like the simplest place.
*/
function example_page_alter(&$page) {
if (!extension_loaded('newrelic')) {
return;
}
$name = NULL;
// Look for a panel page...
$panel_page = page_manager_get_current_page();
if (isset($panel_page['name'])) {
// If it's a node page put the argument's node type into the transaction
// name.
if ($panel_page['name'] == 'node_view') {
if (isset($panel_page['contexts']['argument_entity_id:node_1']->data)) {
$node = $panel_page['contexts']['argument_entity_id:node_1']->data;
$name = 'page_manager_node_view_page/' . $node->type;
}
}
// If it's a page_manager page use the panel name.
else if ($panel_page['task']['task type'] == 'page') {
$name = 'page_manager_page_execute/' . $panel_page['name'];
}
}
else {
$menu_item = menu_get_item();
if ($menu_item['path'] == 'node/%') {
// Looks like panels didn't have a variant and it's falling back to
// node_page_view.
$name = 'node_page_view/' . $menu_item['page_arguments'][0]->type;
}
}
if ($name) {
newrelic_name_transaction($name);
}
}
?>So once you know which panels are slowing down your site you can use the new Panels, Why so slow? module to put the blame on the specific panes.
Report a deployment to New Relic (in python)
I wanted to be able to have a fabric script report a code deployment to New Relic and eventually after brushing up on my python worked this snippet out:
import urllib
import urllib2
try:
request = urllib2.Request(
'https://rpm.newrelic.com/deployments.xml',
urllib.urlencode({'deployment[application_id]': 'YOUR APPLICATION ID'}),
{'X-api-key': 'YOUR API KEY'}
)
response = urllib2.urlopen(request)
except urllib2.HTTPError, e:
print 'Error reporting: ', e.code
print e.headers
print e.fp.read()Publishing pecl channels to GitHub
The process I used to build: http://drewish.github.com/phpredis/ to address this issue: https://github.com/nicolasff/phpredis/issues/42
Install prium:
pear channel-discover pear.pirum-project.org
pear install pirum/PirumCreate a pages repo. I did this as a separate checkout in a sibling directory:
git clone git@github.com:drewish/phpredis.git phpredis-channel
cd phpredis-channel
git checkout --orphan gh-pages
git rm -rf .Configure the pirum.xml file then build the channel:
pirum build .Add your channel to pear/pecl (this also validates it and warns you of any
problems before you push it up to github):
pecl channel-add channel.xml If that looks good then add all files and push it:
git add -A
git commit -m "Created the channel."
git push origin gh-pagesHop up a directory (since I've got them as siblings):
cd ..Package up a release:
pecl package phpredis/package.xmlSwitch into the pages repo:
cd phpredis-channelAdd the release to the channel:
pirum add . PhpRedis-2.2.1.tgzIf that doesn't have any errors then commit the changes and push them:
git add -A
git commit -m "Adding the PhpRedis-2.2.1 release."
git push origin gh-pagesSources
http://blog.stuartherbert.com/php/2011/09/22/php-components-publishing-y...
http://blog.shupp.org/2010/12/24/github-pages-pirum-easy-pear-channel/
https://help.github.com/articles/creating-project-pages-manually
Drupal on Mountain Lion (OS X 10.8)
The instructions still need some work. I'd did some updating but haven't tried using it with a clean install yet. After reading this it sounds like there's some bigger changes. I've also been trying to switch from macports to homebrew so that'll also mean some changes to this.
Install XCode
Install XCode from the App Store. Run Xcode and open its Preferences (⌘+,) select the Downloads tab and then the Components sub-tab. Click the Install button on the Command Line Tools component.
Install MacPorts
Follow the directions to install Mac Ports.
Become root
To follow these instructions you need to be running as the root user using the default sh shell. If you've got administrator permissions you can open up a Terminal window and switch users using the sudo command then provide your password.
amorton@minivac:~% sudo su
Password:
sh-3.2# Install MySQL
Use port to install MySQL:
/opt/local/bin/port install mysql55-serverYou'll need to create the databases:
sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_dbLet launchd know it should start MySQL at startup.
/opt/local/bin/port load mysql55-serverSecure the server and set a new admin password:
/opt/local/lib/mysql55/bin/mysql_secure_installationCreate a configuration file:
cp /opt/local/share/mysql55/support-files/my-large.cnf /etc/my.cnf Edit /etc/my.cnf using your editor of choice and make the following changes to the [mysqld]:
- Change the maximum packet size to 16M:
max_allowed_packet = 16M
Drupal on Lion (OS X 10.7)
I was half way done adding some info how to setup pecl/pear to my guide to running Drupal 6 on OS X 10.6 before I realized I'd been running Lion for almost nine months. So it seemed like a good excuse to update it for Lion. These might be a little wonky since I did an upgrade rather than a clean install so if you notice anything please drop me a line.
Note:I'll save you the trouble of commenting, I am familiar with MAMP but would rather punch myself myself in the face than use it. If you'd like to, go right, but I'm going to continue to compile my own so I know where everything ends up.
Creating a sprite from cocos2d's CCTMXTiledMap
I'm working on a Pipe Mania/Dream clone for iOS using cocos2d. I was able to quickly implement the board using the CCTMXTiledMap component, but then when I started trying to figure out how to setup a sprite preview the next piece I got stuck. I'd intended to try to document all the false starts I took before figuring this solution out, but I waited too long before doing the writeup.

My map gets setup like this and I store a variable to make it easy to get to the board's layer where I'm placing the pieces:
CCTMXTiledMap *map = [CCTMXTiledMap tiledMapWithTMXFile:@"Board.tmx"];
CCTMXLayer *playLayer = [map layerNamed:@"Play"];
[self addChild:map z:-1];What I eventually figured out that I could just create my own texture from the layer's source image, then ask the layer which part of the texture the sprite should use:
CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:playLayer.tileset.sourceImage];
// Since I'm doing an 8-bit style I want it crisp and pixel aligned.
[tex setAliasTexParameters];
// We don't know what the piece is yet so just use the first tile.
CGRect rect = [playLayer.tileset rectForGID:playLayer.tileset.firstGid];
CCSprite *nextPiece = [CCSprite spriteWithTexture:tex rect:rect];
nextPiece.anchorPoint = CGPointZero;
nextPiece.position = CGPointMake(400, 224);
[self addChild:nextPiece];Then in my pickNextPiece method I can just adjust the rectangle:
// Pick a random tile...
nextTileGid = (arc4random_uniform(7)) + 2;
// Then ask the layer where the texture is.
CGRect rect = [playLayer.tileset rectForGID:nextTileGid];
[nextPiece setTextureRectInPixels:rect rotated:NO untrimmedSize:rect.size];Drupal JavaScripting
I was trying to find some docs on how to use Drupal's JavaScript behaviors system to send to some people at work and realized that two years after D6 was released it was still poorly documented. The JavaScript and jQuery page had good examples of how to get JavaScript onto the page from a module or theme but didn't really discuss what to do from that point. I spent some time adding some documentation to the page on drupal.org but wanted to put a copy here for Google's benefit.
After announcing the change on twitter Tim Plunkett pointed out that there were already some D7 docs so incorporated those.
Using memcached with stock OS X Apache
I wanted to use memcached but didn't want to compile all the dependencies by hand and wanted to use the stock version of Apache that ships with OS X so I cobbled together the following instructions.
- Install MacPorts
- Use MacPorts to install memcached:
sudo port install memcached - Use
peclto download the latest version ofmemcachedand uncompress it:
cd /tmp
pecl download memcached
tar xvzf memcached-*.tgz - Build the extension using MacPort's version of
libmemcached(which was installed as a dependency ofmemcached):
cd memcached-*/
phpize
./configure --with-libmemcached-dir=/opt/local/
sudo make install - Enable it by editing
php.iniand adding the following line:
extension=memcached.so - Restart Apache:
sudo apachectl graceful
References:
Setup Drupal 6
The station's website will be build using Drupal an extremely powerful, open source content managment system written in PHP.
Drupal uses some PHP functions that require the installation of additional ports. You'll need:
- devel/php5-pcre - Perl regular expressions.
- textproc/php5-xml - XML parsing.
- textproc/php5-simplexml - Simple XML.
- databases/php5-mysqli - MySQL support for PHP.
- www/php5-session - Session support.
- ftp/php5-curl - cURL support.
- graphics/php5-gd - Image handing. Optional, some modules need it.
- converters/php5-mbstring - Unicode support. Optional, but Drupal prefers that it be installed.
Setup the Drupal station module
First you'll want to install these packages:
- archivers/unzip - you need this to unzip the getID3 library
Now we'll check out the necessary Drupal modules using Drush.
New Mac Mini
I just picked up a new Mac mini servers to replace the one that's been my desktop machine for over 2 years. The new server version has two 500GB hard drives (as opposed to the single 120GB drive I've been working with) but no optical drive. That seemed like a bit of an inconvenience since I just bought a MacBook Air and it doesn't have an optical drive either so I picked up a SuperDrive that I can use with either.
I ran through the initial install process only to realize that I couldn't setup the drives as a RAID mirror. I found a message board thread that describes how to setup the RAID mirror involving the system disk. The short version is boot off the install DVD and use the Disk Utility to create the mirror (which will wipe the disk) then install onto that.
The install and subsequent updates is starting to approach Windows XP levels. It took three rounds of running Software Update before it finished.
The next big step was running through and updated my guide to setting up Apache, PHP and MySQL on OS X. The only change I found was that the new Java update means you need to install an additional developer package before you can really use MacPorts.
Other bits:
- Enable verbose boot mode:
sudo nvram boot-args="-v" - Show hidden files in Finder:
defaults write com.apple.finder AppleShowAllFiles TRUE
Using Mercurial and SVN
At Sony we're looking for a distributed version control system to replace Subversion—primarily Git and Mercurial. I'm very familiar with Git but hadn't done much with Mercurial so it seemed like a good idea to use it for a couple of weeks and learn the quirks. Since I'm stuck using Subversion I decided to see if it would be feasible to use Mercurial as a "super client" working locally then pushing changes back to svn. A little Googling turned up two candidates hgsvn and
hgsubversion. hgsubversion extends the commands pushing and pulling changes, giving a more native experience, so it seemed like the best choice for learning the system.
The setup is actually pretty simple but I'm documenting it for my own future reference.
Use MacPorts to Install hgsubversion:
sudo port install py26-hgsubversionEnable the rebase and hgsubversion extensions:
printf "[extensions]\nrebase=\nhgsubversion =\n" >> ~/.hgrcCheck that the extension was enabled:
hg help extensionsIt should list something like:
enabled extensions:
hgsubversion
integration with Subversion repositoriesNow you're good to checkout from SVN (note: using the svn+ prefix in the URL lets you use passwords stored in your keychain):
hg clone svn+http://example.com/svn/repo/trunkI actually ran into an issue where the clone was exploding with a stack trace. The bug had been fixed in 1.1.2 but MacPorts hadn't yet been updated so I rolled a patch to update it.
MAMP + memcache = drilling a screw in my eye
Here's yet another blog post to document something so stupid that I hope to never do it again, but know I will. I spent the better part of the afternoon trying to get the PECL memcache extension working with the PHP 5.2 part of a MAMP installation and finally managed to get it working.
Install XCode.
Open up a terminal and become the root user:
sudo suMake all the MAMP PHP binaries executable:
chmod u+x /Applications/MAMP/bin/php5.2/bin/p*Now get the memcache source, compile it and copy the library into PHP's extensions directory:
cd /tmp
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar -zxvf memcache-2.2.5.tgz
cd memcached-2.2.5
/Applications/MAMP/bin/php5.2/bin/phpize
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure
make
cp modules/memcache.so /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/Tell PHP to load the memcache extension:
echo 'extension=memcache.so' > /Applications/MAMP/conf/php5.2/php.iniSources:
http://www.php.net/manual/en/memcache.installation.php#95063
http://blog.m-schmidt.eu/2010/03/30/develop-memcached-web-apps-with-xamp...