<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>This is my journey into the world of computer science and geekery.</description><title>λambder on software</title><generator>Tumblr (3.0; @lambder)</generator><link>http://lambder.com/</link><item><title>Extending native Java array types to Clojure protocols</title><description>&lt;p&gt;&lt;pre&gt;&lt;em&gt;;   Copyright (c) Daniel Kwiecinski. All rights reserved.&lt;/em&gt;&lt;/pre&gt;
&lt;div id="LC2"&gt;
&lt;pre&gt;&lt;em&gt;;   The use and distribution terms for this software are covered by the&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC3"&gt;
&lt;pre&gt;&lt;em&gt;;   Eclipse Public License 1.0 (&lt;a href="http://opensource.org/licenses/eclipse-1.0.php"&gt;http://opensource.org/licenses/eclipse-1.0.php&lt;/a&gt;)&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC4"&gt;
&lt;pre&gt;&lt;em&gt;;   which can be found in the file epl-v10.html at the root of this distribution.&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC5"&gt;
&lt;pre&gt;&lt;em&gt;;   By using this software in any fashion, you are agreeing to be bound by&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC6"&gt;
&lt;pre&gt;&lt;em&gt;;   the terms of this license.&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC7"&gt;
&lt;pre&gt;&lt;em&gt;;   You must not remove this notice, or any other, from this software.&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC8"&gt;
&lt;pre&gt;&lt;em&gt;;&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC9"&gt;
&lt;pre&gt;&lt;em&gt;; Example of extending native Java array types to Clojure protocols&lt;/em&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;em&gt;&lt;br/&gt;&lt;/em&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;em&gt;&lt;br/&gt;&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC10"&gt;&lt;/div&gt;
&lt;div id="LC11"&gt;
&lt;pre&gt;(&lt;strong&gt;defn&lt;/strong&gt; array-of [t]&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC12"&gt;
&lt;pre&gt;  (&lt;strong&gt;.getClass&lt;/strong&gt; (&lt;strong&gt;java.lang.reflect.Array/newInstance&lt;/strong&gt; t 0)))&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC13"&gt;&lt;/div&gt;
&lt;div id="LC14"&gt;&lt;/div&gt;
&lt;div id="LC15"&gt;
&lt;pre&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;pre&gt;(&lt;strong&gt;defprotocol&lt;/strong&gt; P&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC16"&gt;
&lt;pre&gt;  (&lt;strong&gt;ppp&lt;/strong&gt; [it]))&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC17"&gt;&lt;/div&gt;
&lt;div id="LC18"&gt;&lt;/div&gt;
&lt;div id="LC19"&gt;
&lt;pre&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;pre&gt;(&lt;strong&gt;extend-type&lt;/strong&gt; Object&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC20"&gt;
&lt;pre&gt;  P&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC21"&gt;
&lt;pre&gt;  (&lt;strong&gt;ppp&lt;/strong&gt; [s]&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC22"&gt;
&lt;pre&gt;    (&lt;strong&gt;format&lt;/strong&gt; "&lt;%s&gt;" s)))&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC23"&gt;&lt;/div&gt;
&lt;div id="LC24"&gt;&lt;/div&gt;
&lt;div id="LC25"&gt;
&lt;pre&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;pre&gt;(&lt;strong&gt;extend-type&lt;/strong&gt; String&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC26"&gt;
&lt;pre&gt;  P&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC27"&gt;
&lt;pre&gt;  (&lt;strong&gt;ppp&lt;/strong&gt; [s]&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC28"&gt;
&lt;pre&gt;    (&lt;strong&gt;format&lt;/strong&gt; "\"%s\"" s)))&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC29"&gt;&lt;/div&gt;
&lt;div id="LC30"&gt;
&lt;pre&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;pre&gt;(&lt;strong&gt;extend-type&lt;/strong&gt; (&lt;strong&gt;array-of&lt;/strong&gt; Object)&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC31"&gt;
&lt;pre&gt;  P&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC32"&gt;
&lt;pre&gt;  (&lt;strong&gt;ppp&lt;/strong&gt; [a]&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC33"&gt;
&lt;pre&gt;    (&lt;strong&gt;apply&lt;/strong&gt; str&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC34"&gt;
&lt;pre&gt;      (&lt;strong&gt;flatten&lt;/strong&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC35"&gt;
&lt;pre&gt;        ["Array["&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC36"&gt;
&lt;pre&gt;         (&lt;strong&gt;interpose&lt;/strong&gt; ", "&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC37"&gt;
&lt;pre&gt;           (&lt;strong&gt;map&lt;/strong&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC38"&gt;
&lt;pre&gt;             &lt;strong&gt;#&lt;/strong&gt;(&lt;strong&gt;ppp&lt;/strong&gt; %)&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC39"&gt;
&lt;pre&gt;             a))&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC40"&gt;
&lt;pre&gt;         "]"]))))&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC41"&gt;
&lt;pre&gt;  &lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC42"&gt;&lt;/div&gt;
&lt;div id="LC43"&gt;
&lt;pre&gt;&lt;em&gt;; =&gt; (ppp (to-array [1 2 3 4]))&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC44"&gt;
&lt;pre&gt;&lt;em&gt;; "Array[&lt;1&gt;, &lt;2&gt;, &lt;3&gt;, &lt;4&gt;]"&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC45"&gt;
&lt;pre&gt;&lt;em&gt;; =&gt; (ppp (to-array ["foo" "bar"]))&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="LC46"&gt;
&lt;pre&gt;&lt;em&gt;; "Array[\"foo\", \"bar\"]"&lt;/em&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;/p&gt;</description><link>http://lambder.com/post/14613592992</link><guid>http://lambder.com/post/14613592992</guid><pubDate>Thu, 22 Dec 2011 07:22:41 -0500</pubDate></item><item><title>With OOP you’re set up to do the wrong thing. You’ll die with locks.</title><description>&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This is splendid. Rich Hickey is talking about OOP in &lt;a href="http://blip.tv/file/982957"&gt;second part of Clojure for Java Programmers&lt;/a&gt;.&lt;br/&gt;At 35:40 he says: [With OOP] you’re set up to do the wrong thing. From the concurrency standpoint its complete catastrophe. It’s a disaster. It’s unworkable. Eventually you’ll die with locks. You either die trying make them work or to try to understand them or just from the stress.&lt;/p&gt;
&lt;p&gt;I second that !!!&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;&lt;embed allowfullscreen="true" allowscriptaccess="always" height="400" width="600" type="application/x-shockwave-flash" src="http://blip.tv/play/AbyxMoqaCw"&gt;&lt;/embed&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class="BLUEKAI" src="http://tags.bluekai.com/site/2132"/&gt;&lt;/p&gt;
&lt;p&gt;.&lt;/p&gt;</description><link>http://lambder.com/post/6138856680</link><guid>http://lambder.com/post/6138856680</guid><pubDate>Wed, 11 Nov 2009 00:00:00 -0500</pubDate></item><item><title>Why VanadiumJS is different</title><description>&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Recently I got an email which sugessted some people still don’t get what the VanadiumJS is all about. Here is my explanation:&lt;!-- more --&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&gt; Vanadium won’t replace the need for server side validation but the client side instant notification is great for usability.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt; Vanadium is not intended to replace the server-side validation. But it is not the client-side validation toolkit only. The real value of Vanadium is its ability to integrate both validations. Vanadium splits validation into two phases: testing and decoration. If, for an example, you do client-side validation vanadium performs testing on validated elements or the entire form and produces result of these tests in json format. Then it uses that structure in order to inject appropriate css classes to validated fields and their containers (decoration). On the other hand when your form is valid on client side you make a request to the server and you perform server-side validations there. Rather than rendering the invalid decorated html on the server-side you can pass server-side validation result as a description in very same json format vanadium uses and vanadium will decorate on the client-side the result of server-side tests. This philosophy make extremely easy to create plugins for web frameworks in order to have dynamic, transparent server side validation on the clinet-side. Currently I have RubyOnRails Vanadium plugin on my roadmap. Anther person is interested in developing one for CackePHP.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Having said that, now I call all web developers: If you would like to create server-client-validation plugin for web-framework of your choice, I’m happy to help you in explanation of VanadiumJS quirks and magic, mentoring on different levels and in giving general advice and support.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://lambder.com/post/6139241613</link><guid>http://lambder.com/post/6139241613</guid><pubDate>Wed, 28 Oct 2009 00:00:00 -0400</pubDate></item><item><title>erlang records &lt;=&gt; json</title><description>&lt;p&gt;JSONERL is published.  It is simple tool for turning your erlang records into json and back.&lt;!-- more --&gt; Here is an example of the usage of jsonerl:&lt;/p&gt;
&lt;pre class="brush: erlang"&gt;-include("jsonerl.hrl").
-record(artist, {name, year_of_birth, city, photo, movies}).
 
Artist = #artist{name = &lt;&lt;"Luc Besson"&gt;&gt;, year_of_birth = 1959, city = &lt;&lt;"Paris"&gt;&gt;, photo = &lt;&lt;"http://is.gd/3pYJF"&gt;&gt;, movies = [&lt;&lt;"Taken"&gt;&gt;,&lt;&lt;"Bandidas"&gt;&gt;,&lt;&lt;"Taxi"&gt;&gt;]},
Json = ?record_to_json(artist, Artist),
Artist = ?json_to_record(artist, Json).
&lt;/pre&gt;
&lt;p&gt;the resulting json will be:&lt;/p&gt;
&lt;pre class="brush: erlang"&gt;{
     name: "Luc Besson",
     year_of_birth: 1959,
     city: "Paris",
     photo: "http://is.gd/3pYJF",
     movies: ["Taken","Bandidas","Taxi"]
}
&lt;/pre&gt;
&lt;p&gt;The code is available at github.   &lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;.&lt;/p&gt;</description><link>http://lambder.com/post/6139277397</link><guid>http://lambder.com/post/6139277397</guid><pubDate>Fri, 18 Sep 2009 00:00:00 -0400</pubDate></item><item><title>VanadiumJS.com is live !!!</title><description>&lt;p&gt;&lt;span&gt;
&lt;p&gt;I’m pleased to announce that the first version of demo site presenting my client-side validation toolkit Vanadium is on the go.&lt;/p&gt;
&lt;p&gt;Vanadium is declarative, client-side validation toolkit. There is no need for coding. Just use simple markup in side class attributes (or if you are HTML purist you may prefer to attach it as external configuration file in json format).&lt;/p&gt;
&lt;p&gt;E.g. for required field one can define it as:&lt;code&gt; &lt;input type="text" class="&lt;strong&gt;:required&lt;/strong&gt;“/&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It also make use of Ajax. E.g checking for username availability can be expressed as:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;input type="text" class="&lt;strong&gt;:ajax;/username_checker/check.json&lt;/strong&gt;“/&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Another handy feature is hierarchical validation regions, lots of build-in validator types and easy way of creating custom ones.&lt;/p&gt;
&lt;p&gt;I’ll appreciate any comments on it.&lt;/p&gt;
&lt;p&gt;You can give it try on &lt;a href="http://vanadiumjs.com/"&gt;VanadiumJS.com&lt;/a&gt;. The code is open source and available on &lt;a href="http://github.com/lambder/Vanadium/tree/master"&gt;github&lt;/a&gt;.&lt;/p&gt;
&lt;/span&gt;&lt;/p&gt;</description><link>http://lambder.com/post/6287100248</link><guid>http://lambder.com/post/6287100248</guid><pubDate>Wed, 26 Aug 2009 00:00:00 -0400</pubDate></item><item><title>The BeeBole Erlang/Web Tutorial, Webmachine-Style</title><description>&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Justin Sheehy posted &lt;a href="http://blog.therestfulway.com/2008/10/beebole-erlangweb-tutorial-webmachine.html"&gt;here&lt;/a&gt; his &lt;a href="http://bitbucket.org/justin/webmachine/wiki/Home"&gt;webmachine&lt;/a&gt; version of a small but fun web application created originally in &lt;a href="http://code.google.com/p/mochiweb/"&gt;mochiweb&lt;/a&gt; by Hughes Waroquier from &lt;a href="http://beebole.com/en/"&gt;BeeBole&lt;/a&gt;. Hughes posted it in a form of neat&lt;a href="http://beebole.com/en/blog/erlang/tutorial-web-application-erlang/"&gt;screencast&lt;/a&gt; tutorial. It’s worth watching.&lt;/p&gt;
&lt;p&gt;Justin’s version is dated from October 22, 2008 and at that time webmachine version was &lt; 1.0. Since that time the webmachine progressed and API has changed. Moreover, Justin’s great example is not a single file but rather code in-lined with post prose. His code has the static content delivery mixed-up with sticky notes resource. It also contained a security issue, which is using &lt;code&gt;list_to_atom&lt;/code&gt;bif with arbitrary arguments coming from API user, potentially opening door to blow our erlang VM’s memory up (running out of atoms).&lt;/p&gt;
&lt;p&gt;Recently I was asked by my friend to introduce him Erlang webdevelopment. I though immediately about webmachine and the sweet sticky notes tutorial so I decided to create working code of that stuff. I have reused my &lt;a href="http://lambder.com/2009/06/providing-static-content-in-webmachine"&gt;static resource for webmachine&lt;/a&gt; resulting in having separation of Ajax API and static content delivery, reducing the original stickyNotes_webresource.erl to 18 lines of code.&lt;!-- more --&gt;&lt;/p&gt;
&lt;pre class="brush: erl"&gt; 
 
-module(stickyNotes_webresource).
-export([init/1, process_post/2, allowed_methods/2]).
 
-include_lib("webmachine/include/webmachine.hrl").
 
init(Config) -&gt; {{trace, "/tmp"}, Config}.
 
allowed_methods(ReqData, Context) -&gt;
    {['POST'], ReqData, Context}.
 
 
process_post(ReqData, Context) -&gt;
    Ps = mochiweb_util:parse_qs(wrq:req_body(ReqData)),
    Struct = mochijson2:decode(proplists:get_value("json", Ps)),
    Act = list_to_existing_atom(binary_to_list(struct:get_value(&lt;&lt;"action"&gt;&gt;, Struct))), 
    Resp = wrq:merge_resp_headers([{"Content-Type", "application/json"}], ReqData),
    Resp2 = wrq:append_to_response_body(mochijson2:encode(notes:Act(Struct)), Resp),
    {true, Resp2, Context}.
 
 
 
&lt;/pre&gt;</description><link>http://lambder.com/post/6287228348</link><guid>http://lambder.com/post/6287228348</guid><pubDate>Tue, 25 Aug 2009 00:00:00 -0400</pubDate></item><item><title>Note to myslf: there is bitstring comprehensions in Erlang</title><description>&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It easy to handle streams of bytes in Erlang. For example consider the following simple task:&lt;br/&gt;given a stream consisting of 3-byte chunks we want to return a stream consisting of those 3-byte chunks whose ﬁrst byte is zero.&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;This can be written in the following manner:&lt;/p&gt;
&lt;pre class="brush: erl"&gt; 
keep_0XX(Bin) -&gt; &lt;&lt; &lt;&lt;0:1,X:2&gt;&gt; || &lt;&lt;0:1,X:2&gt;&gt; &lt;= Bin &gt;&gt;.
 
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I like it, I hope you too.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;[update]&lt;/strong&gt;&lt;br/&gt;Previously I thought it was undocumented feature of erlang. As &lt;a href="http://blog.beerriot.com/"&gt;Bryan&lt;/a&gt; kindly pointed out, one can find it documented &lt;a href="http://erlang.org/doc/reference_manual/expressions.html#6.23"&gt;here&lt;/a&gt;.&lt;br/&gt;Thank you &lt;a href="http://blog.beerriot.com/"&gt;Bryan&lt;/a&gt;.&lt;/p&gt;</description><link>http://lambder.com/post/6287338804</link><guid>http://lambder.com/post/6287338804</guid><pubDate>Fri, 10 Jul 2009 00:00:00 -0400</pubDate></item><item><title>Simple HashMap in JavaScript</title><description>&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I’ve implemented HashMapJS, a simple hash map like implementation.&lt;br/&gt;The project is located at &lt;a href="http://github.com/lambder/HashMapJS/tree/master"&gt;github&lt;/a&gt;.&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here is the code with the usage examples:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="brush: js"&gt; 
/*
=====================================================
   @license MIT
   @author Daniel Kwiecinski 
   @copyright 2009 Daniel Kwiecinski.
   @end
=======================================================
*/
var HashMap = function() {
  this.initialize();
}
 
HashMap.prototype = {
  hashkey_prefix: "&lt;#HashMapHashkeyPerfix&gt;",
  hashcode_field: "&lt;#HashMapHashcodeField&gt;",
  hashmap_instance_id: 0,
 
  initialize: function() {
    this.backing_hash = {};
    this.code = 0;
    this.hashmap_instance_id += 1;
    this.instance_id = this.hashmap_instance_id;
  },
 
  hashcodeField: function() {
    return this.hashcode_field + this.instance_id;
  },
  /*
   maps value to key returning previous assocciation
   */
  put: function(key, value) {
    var prev;
 
    if (key &amp;&amp; value) {
      var hashCode;
      if (typeof(key) === "number" || typeof(key) === "string") {
        hashCode = key;
      } else {
        hashCode = key[this.hashcodeField()];
      }
      if (hashCode) {
        prev = this.backing_hash[hashCode];
      } else {
        this.code += 1;
        hashCode = this.hashkey_prefix + this.code;
        key[this.hashcodeField()] = hashCode;
      }
      this.backing_hash[hashCode] = value;
    }
    return prev;
  },
  /*
   returns value associated with given key
   */
  get: function(key) {
    var value;
    if (key) {
      var hashCode;
      if (typeof(key) === "number" || typeof(key) === "string") {
        hashCode = key;
      } else {
        hashCode = key[this.hashcodeField()];
      }
      if (hashCode) {
        value = this.backing_hash[hashCode];
      }
    }
    return value;
  },
  /*
   deletes association by given key.
   Returns true if the assocciation existed, false otherwise
   */
  del: function(key) {
    var success = false;
    if (key) {
      var hashCode;
      if (typeof(key) === "number" || typeof(key) === "string") {
        hashCode = key;
      } else {
        hashCode = key[this.hashcodeField()];
      }
      if (hashCode) {
        var prev = this.backing_hash[hashCode];
        this.backing_hash[hashCode] = undefined;
        if (prev !== undefined)
          success = true;
      }
    }
    return success;
  }
}
 
/*
 =====================================================================
       usage
 =====================================================================
*/
 
 
// creation
 
var my_map = new HashMap();
 
// insertion
 
var a_key = {};
var a_value = {struct: "structA"};
var b_key = {};
var b_value = {struct: "structB"};
var c_key = {};
var c_value = {struct: "structC"};
 
my_map.put(a_key, a_value);
my_map.put(b_key, b_value);
var prev_b = my_map.put(b_key, c_value);
 
// retrieval
 
if(my_map.get(a_key) !== a_value){
  throw("fail1")
}
if(my_map.get(b_key) !== c_value){
  throw("fail2")
}
if(prev_b !== b_value){
  throw("fail3")
}
 
// deletion
 
var a_existed = my_map.del(a_key);
var c_existed = my_map.del(c_key);
var a2_existed = my_map.del(a_key);
 
if(a_existed !== true){
  throw("fail4")
}
if(c_existed !== false){
  throw("fail5")
}
if(a2_existed !== false){
  throw("fail6")
}
 
 
// primitive types keys 
var d_value = {struct: "structD"};
my_map.put(1, d_value);
 
if (my_map.get(1) !== d_value) {
  throw("fail7")
}

&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;The keys and values can be arbitrary javascript objects.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;
&lt;p&gt;There is no requirements on objects used as keys or values.&lt;/p&gt;
&lt;p&gt;The mechanism is trivial. For every key there is generated unique id (per HashMap instance).&lt;br/&gt;That id is injected to the key object under high unlikely to collide field name &lt;img class="wp-smiley" alt=";)" src="http://lambder.com/wp-includes/images/smilies/icon_wink.gif"/&gt;&lt;/p&gt;
&lt;p&gt;That id is then used to keying in the underlying baking standard javascript association object.&lt;/p&gt;
&lt;p&gt;Notes:&lt;br/&gt;1. This HashMap implementation is not thread safe.&lt;br/&gt;OK I know javascript is not multithreaded but it can have concurrent activities (e.g. setTimeout)&lt;br/&gt;This is enough to have race conditions.&lt;/p&gt;
&lt;p&gt;2. The mentioned high unlikely to collide name is not a problem as log as there is no&lt;br/&gt;massively concurrent activities.&lt;/p&gt;
&lt;p&gt;Roadmap:&lt;br/&gt;1. Make the HashMap implementation thread safe by applying The Wallace Variation of Lamport’s bakery algorithm.&lt;br/&gt;&lt;a href="http://www.polyglotinc.com/AJAXscratch/Mutex/mutualExclusion.html"&gt;&lt;a href="http://www.polyglotinc.com/AJAXscratch/Mutex/mutualExclusion.html"&gt;http://www.polyglotinc.com/AJAXscratch/Mutex/mutualExclusion.html&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Bon Appétit,&lt;br/&gt;Daniel Kwiecinski&lt;/p&gt;
&lt;/span&gt;&lt;/p&gt;</description><link>http://lambder.com/post/6287463727</link><guid>http://lambder.com/post/6287463727</guid><pubDate>Thu, 09 Jul 2009 00:00:00 -0400</pubDate></item><item><title>Dynamically scoped variables in Ruby</title><description>&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Recently I had a need to use routing definition of one RoR from the other one (don’t ask why it’s irrelevant to this post ;) )&lt;/p&gt;
&lt;p&gt;As you may know Rails routing mappings are stored in global variable ActionController::Routing::Routes. So together with &lt;a target="_blank" href="http://github.com/mccraigmccraig/"&gt;Craig McMillan&lt;/a&gt; I’ve hacked really evil piece of code ;) but it does the job!&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;So here it goes:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;# evil Ruby dynamic variables
class DynamicValue
 
  def initialize(val)
    @default_value = val
  end
 
  def method_missing(name, *args, &amp;proc)
    if tv=Thread.current['DynamicValue']
      tv.send( name, *args, &amp;proc)
    else
      @default_value.send( name, *args, &amp;proc)
    end
  end
 
  def with_dynamic_value(value)
    tmp = Thread.current['DynamicValue']
    begin
      Thread.current['DynamicValue'] = value
      yield
    ensure
      Thread.current['DynamicValue'] = tmp
    end
  end
 
  def to_s
    "dynamic value"
  end
 
  def inspect
    to_s
  end
end
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;One can use it for example like this:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;# let's deal with fresh empty RouteSet object
ActionController::Routing::Routes.with_dynamic_value( ActionController::Routing::RouteSet.new ) do
  # let's load other RoR routes to it
  load File.join(Sonar::SONAR_ROOT, 'other_ror', 'config', 'routes.rb')
  # now we can use the other RoR routing definition to generate email tamplate used from the other RoR
  email = NewItemsMessage::create_new_message(person)
end
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Only thread invoking with_dynamic_value will experience the variable reassignment. For other threads it will be transparent. Once the thread exit the block, again it will see the value in the variable as it was before the trick.&lt;/p&gt;
&lt;p&gt;In order to enable that evil you have to invoke once and only once (placing it at the end of config/environment.rb should be fine) the following line:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;ActionController::Routing.const_set("Routes", DynamicValue.new(ActionController::Routing::Routes))
&lt;/pre&gt;
&lt;p&gt;Or any other variable substitution. Doing it once is important because applying more than one proxy will discard the original value of the variable.&lt;/p&gt;
&lt;p&gt;Enjoy more LISP’y Ruby ;)&lt;/p&gt;</description><link>http://lambder.com/post/6320520227</link><guid>http://lambder.com/post/6320520227</guid><pubDate>Thu, 02 Jul 2009 00:00:00 -0400</pubDate></item></channel></rss>

