Hello Erlang!

Erlang Logo

It’s been a while since I’ve posted anything, again. So here’s something!

I first heard about Erlang a few years back now but I was having too much fun learning PHP at the time and didn’t look into it very far. I’ve noticed lately that Erlang seems to be popping up more often, so I thought it was about time I gave it a look.

Erlang, originally created by Joe Armstrong and originating from Ericsson, is an open-source language designed with concurrency, distribution and the communication between independent, isolated processes as the main focus. Spawning processes is a quick and cheap operation in Erlang and a single Erlang application could run across multiple machines just as easily as it could run on a single machine.

Here are some observations from the point of view of a PHP/Zend developer. I won’t even mention performance, one of the generally more talked about features of Erlang. I haven’t run any benchmarks, and I’m not particularly inclined to do so. All I’ll say is, it’s fast.

This is by no means an “Introduction to Erlang”, it’s just some ramblings. If you want a proper thought-through and organised introduction, check the links at the end of this post.

The Erlang Mentality

Erlang does seem to require you to re-learn how you think about problems to a degree. Or at least I’m having to. The mantra of “lots of small processes” needs a bit of hammering home for me. I mean, tiny processes. As far as I can tell, if each process only had a single task, then that’d probably be just fine. It’s all about distribution, doing things concurrently, asynchronously, and mostly, it’s all about the communication between isolated processes.

Another Erlang mantra is “let it crash”. Since processes in Erlang are all isolated, the idea is that it’s better just to let the process crash and log as much as you can about why it crashed than it is to attempt a recovery, potentially with broken data.

In the case of an IRC bot, on receiving each line from the IRC server, I would spawn a parser process, pass it the line, and it would go off and parse the line, sending back a native Erlang term representing the parsed IRC packet. Since the parser processes only have a single responsibility, “couldn’t parse line” and “crashed while trying to parse line” are essentially the same message. So we don’t bother with identifying that the line couldn’t be parsed, we just let the process die and log why it died.

Functional Language

Way back when I first started in Object Orientated development, I started with Objective-C. I didn’t stick with it. I found it quite confusing at the time, but thinking back, that was probably because the Cocoa/Objective-C example of “Currency Converter” is also MVC, which just confused matters further! I do remember mention of “message passing” in reference to Objective-C’s Smalltalk inspiration, but it meant nothing to me since Smalltalk is “a bit before my time” and I couldn’t see any message passing, all I could see were function/method calls, so I ignored it and muddled on.

Once it clicked with me that what Erlang calls “processes” are in fact “objects”, what I had read years previously about message passing suddenly made sense and I realised that Erlang’s more object orientated than any other language I’ve used! Oh, and that everything I thought I knew about object-orientated programming is wrong. Ok, it’s not wrong, just pretty useless to me in Erlang!

It’s isolation and message-passing that’s key in OOP, just as it is in Erlang. I was very pleased when I later found this interview with Ralph Johnson and Joe Armstrong on the state of Object Orientated Programming. It’s nice when one’s gut instinct is reinforced by the people who actually know what they’re talking about.

Side effects are pretty important in Erlang too, so it’s not as functional as all that anyway. You send messages to processes, you can print to the shell. That’s just the way it works.

Ugly Syntax

When I first started looking at screens of Erlang code, I thought to myself, “It ain’t pretty”. I totally take it back. Erlang’s syntax borrows heavily from Prolog, rather than the C-like “curly bracket” languages (of which PHP is a member), so if that’s what you’re used to then yeah, it may seem a bit weird at first. But it makes sense to me both from a logical point of view and a natural language point of view too. I found it surprisingly easy to switch to Erlang’s mode of syntax, to the point where I keep inadvertently using it in other languages! I thought the semicolon-return habit would be the hardest one to break.

Yes, occasionally it bites you when you’re copying and pasting code. But I’ve always been anti-copy-paste so in my opinion, you, I, deserve it for copying-and-pasting code in the first place! Anything that helps us break that habit is A Good Thing. Sure, it has it’s moments when it can be difficult to read, but no worse than some of the PHP or Javascript that I’ve seen! Even in those cases, it tends to be a use of whitespace issue, and that’s subjective. Often what’s “messy” to one developer is “concise” to another.

Despite this, when it comes to pure code alone, no comments and no real use of whitespace to speak of, then I have found Erlang code to be a lot easier to follow than the equivalent software in a typical object orientated language. So far I’ve seen and understood the inner workings of an HTTP server, OSC server and MQTT broker quite quickly. In the latter cases, including an introduction to the protocols themselves!

Pattern Matching

Wow, I love it. It’s just a beautiful way to express software in my opinion. But again, a bit of a shock from a PHP point of view. I think the best way for me to describe it is “Switch()es everywhere!”, except that you can switch() on an entire data structure. A bit like PHP switch abuse, except sanctified!

Take an simple example function that converts HTTP status codes to message strings called status_string/1.

The /1 specifies the function’s arity (but is not part of the name). Arity isn’t something that’s given much thought in PHP, it’s the number of arguments that the function takes. So a function called “status_string” that takes no arguments and a function called “status_string” that takes one argument are different functions. If you wanted to emulate optional arguments, you’d implement wrapper functions recursively for each optional argument, like Java.

status_string( 200 ) -> "OK";
status_string( 403 ) -> "Forbidden";
status_string( 404 ) -> "Not Found";
status_string( 500 ) -> "Internal Server Error";
status_string( Unknown ) when is_integer( Unknown ) ->
    Error = { unknown_status_code, Unknown },
    io:format( "Oh No! ~p~n", [ Error ] ),
    throw( Error ).

It’s like having a built-in switch() on every function definition! It gets right to the point. Less syntax, more power. You’ll notice the last clause on that function doesn’t match against a fixed value, it’s an unbound variable. This means that the data that occupies that position in the structure (in this case just a single value, the entire argument) gets put into that variable. Something a switch() can’t do!

We can also use guards, which is the “where is_integer( Unknown )” bit. Admittedly they’re a little more complicated than at first glance and you can only use certain built-in functions in them but it gives us a “catch all integer” in this case, and you can use them to ensure an argument is within a certain range and things like that. They allow you to fine-tune your patterns, negating the requirement of extra validation steps inside the function. In the case of status_string/1, if you were to pass, say a string into it, then we would just let it crash with a “badmatch” error. Since none of the clauses allow for an argument that isn’t an integer. The function doesn’t accept that input, rather than the function accepting and rejecting that input. Conceptually, that makes a lot of sense to me!

It doesn’t stop there though! You can do pattern matches against bitstreams! I’m not going to go into it here since it’s quite fiddly, but I will say that I’m finding it a great introduction to binary protocols!

Yes, I can see it being open to abuse, and I think it would make my soul cry if I saw patterns matching against tuples of tuples, lists of tuples and tuples of lists. But as long as you follow the Erlang principal of “lots of small processes” then the structures you’re dealing with shouldn’t get very big anyway.

String Handling

Virtually non-existant. I won’t lie to you. There’s no string data type, they’re just lists of integers (Latin1). Which makes sense, but it’s a bit of a shock when you’ve come from the world of PHP. There is the string module that accommodates a lot of the things you’d want to do and since strings are just integer lists, you can also use the lists module to handle them in other regards.

Personally, I find it a bit confusing sometimes knowing what module a function is in. It requires me to stop and think about exactly what it is I want to do with the string. To tokenise a string, you’d use string:tokens/2, but if you wanted to strip certain characters, then you’d use something more like lists:dropwhile/2, with a callback function that checks each character one at a time, or a “list comprehension” that would essentially do the same thing.

There do seem to be a variety of different techniques for dealing with strings including some UTF types in bitstream handling that I haven’t delved into too far yet. I’m still not sure how you’re supposed to tell the difference between a string and a list of strings however. I guess the answer is that I probably don’t need them.

Serial

Apparently there’s no native ability to use a serial port. I was quite surprised. But then when I thought about it, it does make sense. Erlang uses a VM, it’s big on isolation. Why would it get it’s hands dirty dealing with hardware level stuff? It tackles the high-up problems, it’s not meant for fiddling with hardware, all that is abstracted from it.

As such, it has absolutely no problem with handing stuff off to external code. The external code can be written in a more suitable language, typically C, and Erlang can maintain it’s isolation. You can open “ports” to external system processes that run outside Erlang, and it also supports NIFs (Natively Implemented Functions) which allow you to implement an Erlang function in C like it was a Built-In Function (BIF). A bit like a PHP Extension though the impression I’m getting is they should only be a very last resort solution! So all in all I guess it’s not really Erlang’s problem, get C to deal with it!

Undocumented Functions

There seem to be an awful lot of undocumented functions, as you’d expect. But what’s unclear is whether or not you’re allowed to use them. I’m sure I read somewhere that you absolutely shouldn’t and that they can change with no notice. Which seems totally sensible. But then I’ve seen examples where people are using them, such as for accepting sockets asynchronously, and claiming to be using them in production systems. So I really don’t know where I stand on that one yet. I’ll stick with the documented ones I think!

Conclusion

I love Erlang. It’s not for everyone that’s for sure, but for the kind of software I’m most interested in, back end server type stuff, it’s seems perfectly suited. I don’t think I would build a website with Erlang, but I would definitely use it to build a webservice.

Resources 

I can whole-heartedly recommend Erlang and OTP in Action, it’s well written and is easy to hop around from section to section (provided you have the basics down). It’s proving to be a great pick-up-put-down reference as well as an easy and engaging continuous read. It also includes a real world example application that starts out as a simple cache server and evolves as topics such as distribution and resource discovery are introduced, all the way to packaging up and deploying a release.

Free eBook about Erlang: Learn You Some Erlang

Interview with Ralph Johnson and Joe Armstrong on the state of OOP

Beebole Erlang Web Applications (with Mochiweb) screencast

Part one of a ten part lecture given by Joe Armstrong

Posted in Programming | Tagged , | Leave a comment

My first Instructable

I’ve posted my first Instructable!

http://www.instructables.com/id/LED-Patio-Umbrella-Jar-Lights/

It’s a write up on how to make some pretty damn cool LED jar lights. I’ve entered it into Instructables LED Contest.

I wouldn’t object at all if anyone reading this were to vote for it! ;)

The winners get MORE LEDS! If there’s anything I need it’s more LEDs! I just don’t have enough!

Posted in Electronics | Tagged | Leave a comment

Banish Mac OS X Resource Forks from FAT32 volumes

I bought a digital photo frame for Mum’s birthday. The first thing I encountered while getting it set up for her was that Mac OS X Resource Forks seriously confuse it. Resulting in every other “picture” being unreadable and rather than skipping past them, it would display a grey screen with an error in the middle for the allotted time (well done genius!).

As usual I discovered this problem while demoing it to her! How embarrassing! “Give me five minutes.” I said. I knew exactly what needed to be done. I needed a way to automatically delete all the resource fork files from the FAT32 SD card. I figured someone else would have done it already, and they probably have, but I couldn’t find it. I guess my GoogleFu was weak that day. Many hours later, I cracked it. So much for five minutes!

Mac OS X has a nifty feature called “Folder Actions”. What this does is allow you to execute scripts when the contents of a folder change. When files are added to the SD card, I want to run the command:

find . -name "._*" -exec rm -rf {} \;

If you open a Terminal window and run that command, it will find all the files that begin with “._” and execute the “rm -rf” command on each one. Resource forks gone.

If you test that command in the Terminal then be sure that you are in your FAT32 volume. It won’t do anything on a HFS volume. If you remove the “-exec rm -rf {} \;” from the end of the command you can see the results of the find command, the files it’ll be deleting. Nothing is returned on HFS volumes, which is exactly what should happen.

I had hoped that I could just stick that command in a Bash shell script and attach that as a Folder Action, but I ended up having to do it through Automator. Which isn’t as straightforward as I’d hoped. In order to do that the command needs to be modified slightly so that it will still work when invoked by Automator. That’s the bit I found time consuming, given that this is the first time I’d even looked at Automator!

The final command we’ll be using is:

find "`dirname "$@"`" -name "._*" -exec rm -rf {} \;

From what I understand, the script will be run once for every file in the folder and Automator will pass the full path to each file in the folder to the command by means of the $@ variable. We use the dirname command to get the folder path from the file path. So /Volumes/SDCARD/DSC0001.JPG would become /Volumes/SDCARD. Then the command can run as normal.

This does mean that the command gets run more times than is nessessary. But to be honest, I don’t care. It’s only going to run when the contents of the card are being changed, which won’t be that often and it’s not as if anyone’ll notice!

Now, I find the integration between Automator and Folder Actions, well, it’s not great. I’m pretty clued up on most things computery, I’m a programmer! But even I find it confusing.

Open Automator and create a new workflow from the “Folder Action” template. At the top of the workflow, you need to select the volume that you want the script attached to. Next you want to add the “Run Shell Script” action. Make sure that “Pass Input” is set to “as arguments” and enter the final command above into the Automator action. Save it and you should be done. Check to be sure by control-clicking on the volume icon in Finder and select “Folder Action Setup”. A small window will appear and drop a sheet in front. Dismiss the sheet and verify that your volume name is in the left column, click it, and check that your folder action is present in the right column. If it isn’t, click the little plus button at the bottom of the right column to get that sheet back and select your folder action from the list. If your volume doesn’t appear in the left column, you can add it there using the plus button at the bottom of that column.

Once that’s all done, the resource forks will be deleted automatically, even after you eject the volume and remount it, it’ll still work.

Posted in Programming | Tagged , | Leave a comment

HTML5 Video – Rotten Apple

Forgive me, but it’s a gonna be a long one…

Did anyone else notice Steve Jobs tearing a big-old centrefold page out from Microsoft’s book with regards to the whole HTML5 audio/video codec debarcle?

Just to get this clear, I’m not taking sides on what codec should be used, they both have their advantages and should both be supported in my opinion.

Before: Microsoft approached the PC OEMs and essentially bullied them into not including Netscape with their PCs. Going so far infact to threaten not to license Windows to them if they didn’t comply. (BBC Article) Microsoft successfully decided the future of the internet in regard to browser dominence and the familliar sight of “This site is best viewed in Internet Explorer”. Not to mention the hours of stress they caused web developers the world over, the relentless swearing at IE “quirks” that was to follow.

Now: Apple release a new “revolutionary” internet device, without Flash. This makes the web experience on the device today, less than revolutionary, and infact takes it a distinct step backward. To help alleviate that rather massive shortfall, they propose the all-singing all-dancing HTML5 and it’s <video/> element! Which is all very well and good but content providers are currently using today’s internet “standard” of Flash video. We’ll also temporarily ignore the fact that video isn’t the only thing Flash is used for.

To that end, they approach content providers, eg: Wall Street Journal, and Steve tells them to rewrite parts of their site(s) to accomodate his new device. (ArsTechnica) Just to keep perspective, this is one device, in a veritable ocean of web-enabled devices available to consumers. Or two devices if you really insist on pretending that the iPad is anything new. But Steve really does have the gift of the gab and it wouldn’t surprise me if these big-money content provider executaves swoon to him and do it his way. Maybe they all want to be him or just near him, he seems to be everyone’s favourite CEO lately. If all else fails a couple of hours in the Reality Distortion Field should do the trick.

Apple have decided that they can go ahead and do this because they support an interpretation of the HTML5 Audio and Video spec which is one that would see MP4 (H.264/AAC) used as the official format. Another interpretation would be one that uses Ogg (Theora/Vorbis) used instead. This is still a matter of hot debate.

I’m not going to go into detail on their respective pros and cons because they both have them and the intracacies of patent law quite frankly bemuse me. I swear it only exists to give lawyers something to do. Suffice to say there are good points for both. As it stands, Mozilla Firefox and Opera both support Ogg. Safari, in all it’s incarnations only supports MP4 as does the Android browser. Google Chrome is the only browser so far to support both. (Dive into HTML5) In my opinion they’re the only ones doing it right, but what do I know? If this stalemate continues for much longer then it’s only going to harm HTML5 audio and video.

But if Apple skips the whole formality of actually coming up with a fair compromise and goes straight to the content providers, then they can push the content providers to do it The Apple Way. Effectively they’re trying cut out the middleman and make the decision on behalf of The Internet without the hassle of involving other points of view. That just makes things more complicated, right?

Microsoft used their position of power to push Mozilla aside, now Apple are using their position of hype and popularity to do the same to Adobe. But not only that, also to strengthen the position of the codec they endorse as the future HTML5 video standard. Something that is causing quite a stir at the moment and nothing has been formally agreed thus far.

Now on the matter of Flash itself, I get that Flash isn’t exactly great or rather, the Flash player browser plugins. I use the Adobe Flash player plugin for Safari and Firefox on Mac OS X and Firefox for Linux. On my MacBook Pro, if flash is running, I notice. It gets hot. On linux, it’s just slow. Not slow in itself but it makes Firefox slow. The point is, dispite this, it is ubiquitious on the internet these days. Not because it was forced on anyone, but because there was a toolkit behind it that designers could use. Not developers. The combination of HTML, CSS3 and JavaScript is very developer-centric. Even with frameworks like jQuery or Prototype, it’s still “programming”, which is not a skill that all designers have, and those that do tend to have a reduced programming skillset since it’s not their main priority.

When you consider Flash’s versitility, with the multi-platform multi-browser plugins and the designer toolkit, it’s no wonder it’s in the position it’s in today. It powers the vast majority of the video on the web, as well as all manner of interactive apps like games. – Flash is not just for video.

Getting back to the point…

Apple’s actions are not about whether or not HTML5 replaces Flash for video delivery. That is a convenient side effect. This is about keeping Flash out of Apples precious, and maintaining 100% control over the platform, what code can and can’t be run. But most importantly what users can have for free and what they have to pay for through the App Store. No free flash-powered video, go buy it from iTunes (consumers) or do it our way either through MP4 HTML5 or a native app (content providers)! No free flash games, go buy special Apple-endorsed games from the App Store! You must do it The Apple Way. Don’t forget that doesn’t stop at technicial implementation, but moral standards (TechCrunch) as well. If you don’t endorse something, you don’t have to provide it, but what gives you the right to stop users from doing what they want to, in their own time?

Call me old-fashioned, but I believe that when I give someone money, and they give me a gadget, that gadget becomes mine. If I want to throw it on the ground and jump up and down on it, that’s my choice. If I tied it to my dog, that’d be my decision. So why can’t I make my own software choices?

Remember the Commodore 64 emulator app that was rejected because it could interpret BASIC? Gizmodo Story: Fully Licensed Commodore 64 Emulator Rejected By Apple App Store

Posted in Soapbox | Tagged , | Leave a comment

Buzz off Google Buzz!

Despite their entry into the “social network” scene with Orkut some time ago. (Anyone heard of that one? Know anyone who uses it? No, I didn’t think so.) Google are at it again, this time with a more Microsoftesque approach.

*sighs* What is a monolithic corporate to do? There’s so much data out there that could belong to Google, and it doesn’t! Nevermind the fact that nobody outside of Brazil seems to give a damn about Orkut. If Muhammad won’t go to the mountain, then the mountain must go to Muhammad.

Build it into something we know people use so that they can’t get away from it! Something like Gmail, the almost ubiquitous free email service! Yes!

Oh, but remember Google’s catchphrase, “Don’t be evil”. So in the spirit of not being evil let’s add a splash page when you log into Gmail asking if you want to try Buzz or not, give people the choice. We’ll make the “Yes” button huge and hard to miss, and we can make the “No” button the smallest link you ever did overlook repeatedly. Oh yeah and not everyone should get to see the splash page, some people are blessed and can have it automatically, but more importantly, silently enabled. As was the case with my mother who didn’t have a clue what the hell was going on, all she knew was that suddenly she had “loads of stalkers on Gmail”.

Should “no” disable it completely? – Don’t be silly! We can’t deny them the one true social network of freedom, democracy and peace! What kind of commie are you?! Just make “no” mean “yes” and have it automatically follow everyone you’ve ever emailed and vice versa. I guess we should have a disable button somewhere, but people shouldn’t find it, let’s just make it one of the smallest and most inconspicuous links in the footer. (That’s where it is by the way)

Google have a monopoly, they know it and they’re using it. Yeah, not evil at all.

Google do make some really cool products. Some I really like. I also realise that a lot of the cool stuff they can only do because they already have the infrastructure in place to make it happen. I also like that Google have always made a point about being able to get your data back out again through free APIs. So all the time that’s the case I’m appeased.

Just remember that too much of a good thing is bad for you. – I think it’s time for Google to back off. I can’t help but suspect that a slippery slope is just round the corner.

I think that’s this rant more-or-less over. I can’t vouch for those within earshot though, they may have to hear it one or two more times. ;)

UPDATE:

I was talking with Dave about this and he, being better with words than I, found a way to phrase my main gripe with this whole affair. It “devalues” your Google account. By adding all these new social features it’s making my Google account noisier and crowded with people all chattering away about stuff that I quite frankly don’t care about. There’s nothing wrong with the features themselves, besides being a bit flaky and having to authorise someone four times and still have it not work! I love that I can “connect” other sites to my Google account. The fact that it’s on by default regardless of whether or not you wanted it is the step too far.

People use different tools for different things and have different circles of friends that they may want to keep separate or just don’t relate. My “rocker” friends and “geek” friends don’t tend to mix much. I use my Google account for all my Google related gubbins. I use Facebook for being “social” online. Because that’s where my friends are. While it’s great that the capability is there, *I* don’t want Google to automatically broadcast everything I do on YouTube or any other site it happens to own.

Google seem to think that people have lost the ability to communicate with one another on their own and we need a web-app to do it for us. “They” talk about how technology and the Internet is making people more isolated than ever before. Why should I talk to someone when they can just watch my online activity in almost real-time?

Posted in Soapbox | Tagged | Leave a comment

Zend_Form_Decorator_ViewScript

Ok, not exactly breaking news, but I’ve just discovered the Zend_Form_Decorator_ViewScript class, the Zend DevZone article covering it, well, it helped me find it, but the examples are pretty useless if you want it to actually work! (No surprises there then, sorry DevZone.)

So to that end I thought I’d blog.

Zend Form Decorators can be hard enough to twist your brain around at the best of times. But the ViewScript Decorator makes forms easy again. You can apply the ViewScript decorator to any Zend_Form element, though I’d have thought that using it on the Form itself is all you’d really need.

File: ./application/forms/Example.php

<?php
/**
 * ViewScript Decorator example form
 */
class Form_Example extends Zend_Form
{
    /**
     * Initialise
     *
     * Set up the form, that's down to you,
     * set the ViewScript decorator for the form
     * @access public
     */
    public function init()
    {
        /* ... Initialise my form ... */
        $this->setDecorators( array(
            array( 'ViewScript', array( 'viewScript' => 'forms/example.phtml' ) )
        ) );
    }
}
?>

Remember that the path forms/example.phtml is relative to the configured view script directories. So in my app these are ./application/views/scripts/:./application/modules/default/views/scripts/:./application/modules/admin/views/scripts/.

Inside the view script, the form element you’re decorating is assigned to the element view property. So inside the view script ( $this->element instanceof Zend_Form ) === true.

That just leaves you with the view script itself now. Well, they’re just like any other view script except you only have $this->element property, your view helpers remain available to you as always.

File: ./application/views/scripts/forms/example.phtml

<form id="exampleForm" action="<?php echo $this->element->getAction() ?>" method="<?php echo $this->element->getMethod() ?>">
    <h2>Your Details</h2>
    <?php echo $this->element->email ?>
    <?php echo $this->element->dob ?>
    <h2>Account Details</h2>
    <?php echo $this->element->username ?>
    <?php echo $this->element->password ?>
    <?php echo $this->element->passwordconfirm ?>
    <h2>Terms & Conditions</h2>
    <p>Read our <a href="<?php echo $this->url( array(), 'terms_and_conditions' ) ?>">Terms & Conditions</a> before signing up.</p>
    <?php echo $this->element->termsandconditions ?>
    <?php echo $this->element->submit ?>
    <p class="small">NOTE: This is where you may want reassure your visitors that you're to be trusted.</p>
</form>

Now that’s a pretty simple example of how you’d use the ViewScript decorator. You may be able to achieve that markup using only the other decorators. I don’t know, and I can’t really be arsed enough to find out. I plan to just keep it simple and have a view script for each form that needs it, and use other decorators for the individual form elements.

It is now down to you to build the <form/> element, the individual form elements are still automatically generated though so you still get all those fancy features that made you want Zend_Form in the first place. Simply echo them out.

Posted in Programming | Tagged | 2 Comments

Main Config with Zend_Application

Mainly a note to myself, but it’s handy to know.

When you instanciate Zend_Application, you provide it with a path to the config file (Or an instance if you’re feelin’ kinky) Zend_Application loads this into a Zend_Config object and does it’s bit with it.

What’s less obvious is how to retrieve that config from within a Zend_Controller_Action::method().

My solution until recently was to have an _initConfig() in my bootstrap class that read in the file again, and stored the instance in a Zend_Registry entry. However I think I cracked the “proper” way or “better” way to do it.

<?php

class MyController extends Zend_Controller_Action
{
	/**
	 * @var array The application configuration
	 * @access protected
	 */
	protected $_config;

	/**
	 * Init
	 *
	 * Retrieve and assign the application configuration
	 *
	 * @access public
	 * @return null
	 */
	public function init()
	{
		$this->_config = Zend_Controller_Front::getInstance()
			->getParam( 'bootstrap' )
			->getOptions();
	}
}

?>

Edit: In that particular example there is actually an instance of Zend_Controller_Front closer to hand, you could use $this->_frontController. But I’ll stick with ::getInstance() for the example since since it gets the job done.

Posted in Programming | Tagged | Leave a comment

No carbon offset for me

No Carbon Offset for me

So, how do you run out of carbon offsets? For that matter, what kind of carbon offset will 50p buy me anyway? I mean, it can’t really cost a mere ( 50p x $number_of_rockers ) to “offset” ALL the evil anti-green-enviro-stuff entailed in putting on the festival, if it costs ( £10 x $number_of_rockers ) just for Ticketmaster to sell the damn tickets over t’intertubes.

Now, Download is put on by LiveNation, and I had a suspicion that Ticketmaster were owned by LiveNation. A quick google has told me that they weren’t bought but “merged”. So yeah, my “outrage at the evil faceless corporation queezing the blood from the innocent” nerve is running on overdrive at the moment.

Posted in Blog | Leave a comment

Sunjuice!

The sun shining through my bedroom window is now enough that it is starting to wake me in the morning before my alarms (yes, all five of them) go off. So I thought I’ll pull out that solar panel I so ingeniously bought during the winter!

Solar Panel

Even at the time I took that picture, it’s not terribly sunny but I was getting 11.3 volts out of it, in direct sunlight I got 20-odd so I’m quite happy with it. :D

Sunjuice! (Yeah, I need to vacuum)

Big-ass battery, heavy-ass battery too. Charge controller on top (duct-tape again), nothing hooked up to the load at the moment, need to get me some car-stylee sockets and a MacBook Pro charger. Though I may grab an inverter and give it a go with a few things. But I’d rather not take 12vdc turn it into 240vac (or whatever it is now) just to turn it into 17.5vdc!

In the mean time it’s just been powering a breadboard, again duct-taped to it, with a 5v regulator powering my Arduino via a spare USB PCI backplate I had knocking around. The Arduino just slowly fades a green LED via the successfully constructed Power LED driver circuit. Only, I don’t have an appropriate R3 (see diagram on previous link) for my Luxeon stars (d’oh) so it’s a bit superfluous at the moment. But all that together, Rube Goldberg would be proud!

Posted in Electronics | Tagged | Leave a comment