arandomurl.com A collection of articles relating to design and development http://arandomurl.com "Tech Dating" In London <p><a href="http://seedcamp.com/">Seedcamp</a> are running a &quot;tech dating&quot; event to try and attract some more of a technical audience. Its basically an event where both non technical and technical entrepreneurs can meet up, talk about ideas, and hopefully make some new useful connections.</p> <p>Its a really good idea, while I spent quite a lot of time over the past year going to startup events, it does seem that the developers are still somewhat segregated (to user groups and tech conferences) whereas the non technical entrepreneurs are easier to find at startup events like open coffee, seedcamp itself or sun startup camp which happened not long ago.</p> <p>Its surprising as the type of companies these startup events are looking at are companies that need developers at the heart, I know the supply is there, I havent met a programmer yet that doesnt have a side project / idea to work on. So if you are a developer in or around london, and want to be involved in a startup, head along. </p> <p> <a href="http://blog.seedcamp.com/">Seedcamp invitation form etc</a> </p> http://blog.arandomurl.com/post/"Tech-Dating"-In-London/ Erlang: The problem with being "new" <p>So you spend 5/10 years learning X, but start to think it might not be the best solution for every problem, You have heard Y is good for solving your new problem, so you give it a shot, skim over some blogs, maybe even spend an afternoon learning it. After while you get fustrated, things that you can do easily in X are suddenly hard and fustrating in Y, you cant recognise the wierd interface. Conclusion: it must be a terrible language / application / etc.</p> <p>One of the most popular opinions I find on Erlang is that it looks like an amazing platform, but not a very nice language. Since I had a similiar opinion when coming to Erlang (from primarily PHP and Java), I thought I would post comparable snippets to show why I now enjoy programming in Erlang.</p> <h3>Problem:</h3> <p>Code a simple chat message handler, define a simple function that takes parsed input, and calls the function relating to that command. if the message isnt one of the valid format, throw an exception. The 3 valid inputs in both languages are :</p> <pre class="prettyprint"> Erlang : PHP : handle({enter,"user"}) handle(array(ENTER,"user")) handle({leave,"user"}) handle(array(LEAVE,"user")) handle({message,"user","message"}) handle(array(MESSAGE,"user","message")) </pre> <br /> <h3>PHP Solution :</h3> (check the comments for Jon Hohle's version, it is much more elegant) <pre class="prettyprint"> define("ENTER", 1); define("LEAVE", 2); define("MESSAGE", 3); function handle($cmd) { if(is_array($cmd) &amp;&amp; ($count = count($cmd)) > 1) { if($cmd[0] == ENTER &amp;&amp; $count == 2) return enter($cmd[1]); else if($cmd[0] == LEAVE &amp;&amp; $count == 2) return leave($cmd[1]); else if($cmd[0] == MESSAGE &amp;&amp; $count == 3) return message($cmd[1],$cmd[2]); } throw new Exception('Invalid Message'); } </pre> <br /> <h3>Erlang Solution :</h3> <pre class="prettyprint"> handle({enter,User}) -> enter(User); handle({leave,User}) -> leave(User); handle({message,User,Msg}) -> message(User,Msg); handle(_) -> throw("Invalid Message"). </pre> <p> The example illustrates a small benefit of pattern matching which is at the heart of Erlang. Some things new users might see as 'warts' are often powerful features, and a few hours introduction into a language is never going to match the cumulative experience gained in years of writing applications. </p> http://blog.arandomurl.com/post/Erlang:-The-problem-with-being-"new"/ Automatic Syntax Highlighting Erlang in gedit <p>I have spent a lot of times playing around with different IDE's / code editors to find one that fits my needs, and I always end up settling on gedit, aka &quot;Text editor&quot; in Ubuntu.</p> <p>One annoying 'feature' is that it lacks both a filetype / mime type preferences panel, and automatic detection. So to get your favourite language automatically syntax highlighted, create a new <code>Overrides.xml</code> in <code>~/.local/share/mime/packages</code>, and copy :</p> <pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; ?&gt; &lt;mime-info xmlns=&quot;http://www.freedesktop.org/standards/shared-mime-info&quot;&gt; &lt;mime-type type=&quot;text/x-erlang&quot;&gt; &lt;glob pattern=&quot;*.erl&quot;/&gt; &lt;/mime-type&gt; &lt;/mime-info&gt; </pre> <p>into it, Then run :</p> <pre class="prettyprint"><code>update-mime-database ~/.local/share/mime </code></pre> <p>I hope I have got this wrong and theres actually a really easy way, but it works for now.</p> http://blog.arandomurl.com/post/Automatic-Syntax-Highlighting-Erlang-in-gedit-/ "console is not defined" Firebug 1.2 and Firefox3 RC1 <p> Just a quick note since it took me a while to find on the mailing lists. After upgrading to Firefox3 RC1 and Firebug 1.2beta I couldn&#39;t use the console, getting a &quot;console is not defined&quot; (in ironically, the console). </p> <pre><code><a href="http://groups.google.co.uk/group/firebug/browse_thread/thread/a13f83ec1cd6a4ed" target="_blank">John J Barton :</a> In 1.2 the console is not added to the page unless you turn on Script debugging. Try that and let us know. </code></pre> <p> Turning on the script debugger worked fine for me. </p> </p> http://blog.arandomurl.com/post/"console-is-not-defined"-Firebug-1.2-and-Firefox3-RC1/ Automatic Flickr Linking <p> Quite a few people ask me about using the <a href="http://www.flickr.com/services/api/">flickr api</a> to pull in photos to show on their website. So while waiting on a never ending test suite to finish I put together a quick script. This isnt useful mean for a portfolio gallery or such, just a handy script for forums / blogs. </p> <p>The code simply looks through the current page for links to a flickr users "tags", then grabs the photos from flickr, and places the thumbnails on the page. I used the <a href="http://leandrovieira.com/projects/jquery/lightbox/">jquery lightbox plugin</a> to display the photos, but its easily replaced. </p> <pre class="prettyprint"><code>// This script checks the page for any links to a flickr // users tags page, for example // http://flickr.com/photos/user/tags/tagname/ // it then fetches the users photos with those tags // and puts thumbnails on the page, and 'lightboxes' them // Replace this with your own api key, which you can get from // http://www.flickr.com/services/api/keys/apply/ var api_key = "*********************************"; // Set this to the maximum number of photos to show, // -1 for no limit var num_photos = -1; var api_url = "http://api.flickr.com/services/rest/?method="; var json = "&format=json&jsoncallback=?"; // Grab links that point to flickr $("a[href^=http://www.flickr.com/]," + "a[href^=http://flickr.com/]").each(function() { var split_url = $(this).attr("href").split("/"); var link = this; var tag = split_url[6]; if(split_url.length > 6 && split_url[5] == "tags") { var gallery = $("&lt;div class='flickr_set' /&gt;").insertAfter($(link)); // Looks up the user_id from the url to flickr var lookup_url = api_url+"flickr.urls.lookupUser&api_key=" + api_key + "&url=" + this + json; $.getJSON(lookup_url, function(data) { var search_url = api_url+"flickr.photos.search&api_key="+api_key + "&user_id="+data.user.id+"&tags="+tag+json; $.getJSON(search_url, function(data) { $.each(data.photos.photo, function(i,item) { var image_url = "http://farm"+item.farm+".static.flickr.com/" +item.server+"/"+item.id+"_"+item.secret; gallery.append($("&lt;a href='"+image_url+".jpg' title='" + item.title+"'&gt;"+"&lt;img src=\""+image_url+"_s.jpg\"" + "alt=\""+item.title+"\" /&gt;&lt;/a&gt;")); if(num_photos != -1 && (num_photos-1) == i) return false; }); gallery.children("a").lightBox(); gallery.append($("&lt;br /&gt;")).append(link); }); }); } }); </code></pre> <p> So thats the code, to use it just link to flickr like so : <a href="http://flickr.com/photos/daleharvey/tags/randomphoto/">original link text</a> you can download the script + images + css from <a href="http://arandomurl.com/files/flickr_autolink.tar.gz" target="_blank">here</a> </p> <p>The flickr api is one that I really like using, its flexible request type support, along with its impressive <a href="http://www.flickr.com/services/api/">documentation</a> and <a href="http://www.flickr.com/services/api/explore/?method=flickr.photos.search">API Explorer</a> make it very easy to use. <a href="http://jquery.com">JQuery</a> helps make '5 minutes' scripts actually take 5 minutes to finish. I really do wish javascript supported printf natively though,</p> http://blog.arandomurl.com/post/Automatic-Flickr-Linking/