Stumbled across this much easier solution today for rigging up my favorite modern headless javascriptable browser tools on my favorite Windows-compatible shell. Should work in pretty much all versions of Windows/Cygwin/phantomjs/casperjs.
Download phantomjs and casperjs and unzip them in c:\phantomjs and c:\casperjs. Like it’s 1984.
Make them more cygwinny. As a local admin†:
cd /usr/local/bin ln -s /cygdrive/c/casperjs/bin/casperjs.exe ### BROKEN: ln -s /cygdrive/c/phantomjs/phantomjs.exe # Aww, casperjs doesn't speak Cygwin symlinks. cp /cygdrive/c/phantomjs/phantomjs.exe ./ chmod 755 ./phantomjs.exe |
† Right-click the Mintty shortcut and “Open as Administrator”. Don’t think too hard.
Node
Install Node on the Nagios machine (My Nagios XI VM running CentOS… for other platforms see nodejs.org)
wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm sudo yum localinstall --nogpgcheck nodejs-stable-release.noarch.rpm sudo yum install nodejs-compat-symlinks npm rm nodejs-stable-release.noarch.rpm |
Install the “commander” package by TJ Holowaychuk for easier option processing.
$ sudo HTTP_PROXY=$HTTP_PROXY npm install -g commander npm http GET https://registry.npmjs.org/commander npm http 200 https://registry.npmjs.org/commander npm http GET https://registry.npmjs.org/commander/-/commander-1.0.4.tgz npm http GET https://registry.npmjs.org/keypress npm http 200 https://registry.npmjs.org/keypress npm http GET https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz commander@1.0.4 /usr/lib/node_modules/commander └── keypress@0.1.0 |
Install PhantomJS and CasperJS
Again on the NagiosXI VM:
# Get PhantomJS and install it in /opt/ with a symlink in /usr/local/bin/ # http://phantomjs.org/download.html wget http://phantomjs.googlecode.com/files/phantomjs-1.6.1-linux-x86_64-dynamic.tar.bz2 bunzip2 phantomjs-1.6.1-linux-x86_64-dynamic.tar.bz2 tar xf phantomjs-1.6.1-linux-x86_64-dynamic.tar sudo mv phantomjs-1.6.1-linux-x86_64-dynamic /opt/ sudo ln -s /opt/phantomjs-1.6.1-linux-x86_64-dynamic/ /opt/phantomjs sudo ln -s /opt/phantomjs/bin/phantomjs /usr/local/bin/ which phantomjs # should return /usr/local/bin/phantomjs phantomjs --version # should return `1.6.1` with no errors # Check out and install the latest CasperJS with Git # http://casperjs.org/installation.html sudo yum install git -y git clone https://github.com/n1k0/casperjs.git sudo mv casperjs/ /opt/casperjs sudo ln -s /opt/casperjs/bin/casperjs /usr/local/bin/ which casperjs # should return /usr/local/bin/casperjs casperjs --version # should return `1.0.0-RC1` |
I want programming computers to be like coloring with crayons and playing with duplo blocks… I just want to make computers suck less.
I never write about Emacs because I’m such a n00b and most of my ELisp “programming” has consisted of pasting random code from the Internet into my ~/.emacs file and hoping it works. But finally today I wrote a lick of it and it worked!
I’ve been using Ethan Schoonover’s obsessively comfortable “Solarized” color scheme for a while now, but I’ve become annoyed how many keys I have to mash to switch from light to dark. So I set a global variable to track the current state and mapped Ctrl-c, d (which I at least wasn’t using) to a function to toggle between the two states.
(when window-system ;; ColorTheme - see http://www.emacswiki.org/cgi-bin/wiki/ColorTheme ;; and see gallery at http://www.cs.cmu.edu/~maverick/GNUEmacsColorThemeTest/ ;; try also M-x color-theme-select (message "loading color-theme") (add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0") (require 'color-theme) ;; Ethan Schoonover's Solarized theme from ;; https://github.com/sellout/emacs-color-theme-solarized (load-file "~/.emacs.d/emacs-colors-solarized/color-theme-solarized.el") ;; Set initial theme to "dark" (setq dark-or-light 'dark) (color-theme-solarized dark-or-light) ;; Shortcut to toggle between light and dark (global-set-key (kbd "C-c d") (lambda () (interactive) (if (eq dark-or-light 'light) (setq dark-or-light 'dark) (setq dark-or-light 'light) ) (color-theme-solarized dark-or-light))) ) |
And ooh, I just found this awesome crash course on Elisp by Steve Yegge which I will certainly consult next time I have a reason to write my own (i.e., I can’t paste it from some random Internet).
And then after it was all over I finally found some instructions for doing it which would’ve been easy enough to paste. Ah well, I’ve learned something.
Steps to get PHPUnit to run on my XAMPP setup with Cygwin, so I can write and run Symfony2 unit tests.
1. Upgrade PEAR
Download
http://pear.php.net/go-pear.phar
to C:\xampp\php\go-pear.pharRun this in cmd.exe (cygwin prompts hosed somehow), taking all defaults
c:\xampp\php>go-pear.bat |
- Yay.
c:\xampp\php>pear version PEAR Version: 1.9.4 PHP Version: 5.3.5 Zend Engine Version: 2.3.0 Running on: Windows NT FAI1046162 6.1 build 7600 (Unknow Windows version Enterpr ise Edition) i586 |
2. Install/upgrade PHPUnit
Now we can use the cygwin shell. Not sure all these channels are needed, I did this out of order.
cd /cygdrive/c/xampp/php pear update-channels pear channel-discover components.ez.no pear channel-discover pear.symfony-project.com pear channel-discover pear.phpunit.de pear install --alldeps phpunit/PHPUnit |
3. Use it
XAMPP and/or PHPUnit come with a wrapper called phpunit.bat, which has now been upgraded, but you may need to set your PHPBIN environment var. Also I already have c:\xampp\php in my $PATH.
export PHPBIN=c:/xampp/php/php.exe cd /path/to/mysf2project phpunit.bat -c app |
Now PHPUnit works. Make tests and make them work!
Propel 1.6 (and Propel 1.5 before it) is pretty sweet (thank you François!). I had some confusion with my model’s array of related objects though, thinking it was a regular PHP array. Actually it’s a Collection, specifically a PropelObjectCollection, which implements PHP 5’s ArrayObject interface. You can do a lot of cool things with them.
Sorting
Not immediately obvious, however, was how to sort them. This did the trick for my case (I have a Sequence field manually re-calculable through a jQueryUI sortable widget. Also note the cool inline anonymous function syntax available since PHP 5.3. Incidentally, I’m not sure the terms lambda or closure are helpful because they’re not quite like Lisp lambdas or JavaScript closures.
// Re-sort them by Sequence, numerically $this->collSegments->uasort(function($a, $b) { return $a->getSequence() - $b->getSequence(); }); |
// Re-sort them as strings, case-insensitively. $this->collSegments->uasort(function($a, $b) { return strnatcasecmp($a->__toString(), $b->__toString(); }); |
Deleting
Thanks to the PropelArrayCollection API Documentation
/* * Remove the provided Segment object. * * @param Segment $s * @return Segment $s that was deleted. */ public function deleteSegment(Segment $s) { $s->delete(); $key = $this->collSegments->search($s); $ret = $this->collSegments->remove($key); return $s; } |
So elsewhere,
$this->deleteSegment($s); |
Problem
On my Snow Leopard machine this kept happening.
- The “open” indicator (glowing silver ball under the app icon) in the Dock was flaky, only showing for a few apps though more were running.
- The task switcher (which you see when you
option-tab
/alt-tab
) didn’t show all running apps. That RUINS it for me. I always use option-tab. - I hate rebooting.
Workaround–Restart the Dock process.
Open Terminal† and use one command:
killall -HUP Dock |
Don’t be afraid of “killall”. HUP means “Hang Up” and is the normal way of telling something to relaunch.
Thanks to AcmeTech’s old post.
† Terminal is located in the Utilities folder in the Applications folder. Or the quick Spotlight way is command-space
, Terminal.
A while back I realized something important:
Monitoring tools are to the sysadmin what testing tools are to the developer.
Recently I realized that there need to be more ways to bring both toolsets together. Here’s one, tying the Nagios monitoring toolset to anything that emits the popular Test Anything Protocol.