testing post
-
Twitter
Error: Twitter did not respond. Please wait a few minutes and refresh this page.
-
Latest Bookmarks
This is totally untested code! It should work but I haven’t got round to testing it yet… I found something similar in an old project and I thought it might be useful, I couldn’t help tweaking it first.
<?php
/**
* Create a new vocabulary and save some terms
* @param $terms, an array of taxonomy terms
* @param $vocabulary, a string representing the machine name of exiting vocab
*/
function _create_terms($terms = array(), $vocabulary = 'existing_vocab') {
// check to see that the vocabulary exists.
if ( $vocab = taxonomy_vocabulary_machine_name_load($vocabulary) ) {
// $terms[] = "Cats";
// $terms[] = "Dogs";
// $terms[] = "Mice";
foreach ($terms as $name) {
$term = new stdClass();
$term->vid = $vocab->vid;
$term->name = $name;
taxonomy_term_save($term);
}
} else {
// vocab doesn't exist, nothing happened, return false.
return false;
}
}
A closure is a special kind of object that combines two things: a function, and the environment in which that function was created.
Sometimes it’s nice to run some Javascript that doesn’t involve starting Firefox or Chrome and using the developer tools console. The contenders I’ve looked at include:
A small irony is that all these options power the Javascript consoles in the browsers we’re trying to avoid. Installation wise, Node is the only option that has an officially maintained package for Ubuntu so it doesn’t get any easier than:
$ apt-get install nodejs
We can test node with a simple hello world script.
$ echo 'console.log("Hello World");' > helloworld.js
$ node /tmp/helloworld.js
Hello World
Node builds on top of Google’s V8 Javascript engine itself but if you just want V8 without Node there’s a nice writeup I found on a blog. It’s the first time I’ve seen the SCons tool in action which is a next-generation build tool built in Python which is an alternative to make. Anyways, V8 comes with configuration to build a shell and it works nicely too, there’s just a few more manual steps to compile and install the software.
After following Steve Ried’s blog post I get a shell program at /usr/local/src/v8/shell and for convenience I’ve symlinked it to a more useful path:
$ ls -s /usr/local/src/v8/shell /usr/local/bin/js
We don’t get the console object in the V8 shell but we do get a print function. So our hello world script above needs to change to this:
$ echo 'print("Hello World");' > /tmp/v8-helloworld.js
$ js /tmp/v8-helloworld.js
Hello World
I did attempt to install SpiderMonkey but I ran into some dependency issues early on which looked to be minor but on a Sunday morning with hot-cross buns in the oven I just didn’t have the time to investigate.
What can we do now that we’ve got a Javacript environment installed? …
If you can’t tell that your system is fundamentally skewing (from the user perspective), then it’s not.
Mike Solomon recently gave a talk at PyCon 2012 where he explained some strategies they use at YouTube to achieve scalability. My favorite strategy was cheating. The relevant snippet is at the 16:00 mark:
Visual index of Australian native ducks
Image search + Google Docs + public sharing + blatant disregard for IP = all (or at least most) of the ducks native to Australia.
Usually if I’ve been working late into the night I get the urge around 2am to move my blog onto some new cool technology (the more deadlines that I have approaching, the stronger the urge). The problem is that there’s no single blog platform which has all the buzz-words in one package. So instead of implementing an existing technology I’ve developed a new one from scratch which could be the antithesis of a server-side javascript blogging engine publishing via git post-commit hooks using a RESTful interface.
Introducing Couldn’t Be Fucked. The blogging technology for people who care the least.
I recently started working on a Drupal project where one of the developers was using Windows 7 for his main development machine and we wanted to setup a distributed development workflow based on the Drush Make theory for happy profile development. The machine already had a *AMP stack installed (XAMPP for Windows) so I thought the easiest way to get the rest of the required tools was to install Cygwin. Two days later and we finally have everything working. No particular step was terribly complicated there was just a general lack of information for dealing with some of the gotchas we experienced.
Randy Fay’s excellent article from 2010 – Cygwin Quickstart for Drupal Users – helped immensely but there were a couple of roadblocks. Continue reading