Install this theme
Extending native Java array types to Clojure protocols

;   Copyright (c) Daniel Kwiecinski. All rights reserved.
;   The use and distribution terms for this software are covered by the
;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;   which can be found in the file epl-v10.html at the root of this distribution.
;   By using this software in any fashion, you are agreeing to be bound by
;   the terms of this license.
;   You must not remove this notice, or any other, from this software.
;
; Example of extending native Java array types to Clojure protocols


(defn array-of [t]
  (.getClass (java.lang.reflect.Array/newInstance t 0)))

(defprotocol P
  (ppp [it]))


(extend-type Object
  P
  (ppp [s]
    (format "<%s>" s)))

(extend-type String
  P
  (ppp [s]
    (format "\"%s\"" s)))


(extend-type (array-of Object)
  P
  (ppp [a]
    (apply str
      (flatten
        ["Array["
         (interpose ", "
           (map
             #(ppp %)
             a))
         "]"]))))
  
; => (ppp (to-array [1 2 3 4]))
; "Array[<1>, <2>, <3>, <4>]"
; => (ppp (to-array ["foo" "bar"]))
; "Array[\"foo\", \"bar\"]"

With OOP you’re set up to do the wrong thing. You’ll die with locks.

This is splendid. Rich Hickey is talking about OOP in second part of Clojure for Java Programmers.
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.

I second that !!!

Read More

Why VanadiumJS is different

Recently I got an email which sugessted some people still don’t get what the VanadiumJS is all about. Here is my explanation:

Read More

erlang records <=> json

JSONERL is published. It is simple tool for turning your erlang records into json and back.

Read More

VanadiumJS.com is live !!!

I’m pleased to announce that the first version of demo site presenting my client-side validation toolkit Vanadium is on the go.

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).

E.g. for required field one can define it as: <input type="text" class=":required“/>

It also make use of Ajax. E.g checking for username availability can be expressed as:

<input type="text" class=":ajax;/username_checker/check.json“/>

Another handy feature is hierarchical validation regions, lots of build-in validator types and easy way of creating custom ones.

I’ll appreciate any comments on it.

You can give it try on VanadiumJS.com. The code is open source and available on github.

The BeeBole Erlang/Web Tutorial, Webmachine-Style

Justin Sheehy posted here his webmachine version of a small but fun web application created originally in mochiweb by Hughes Waroquier from BeeBole. Hughes posted it in a form of neatscreencast tutorial. It’s worth watching.

Justin’s version is dated from October 22, 2008 and at that time webmachine version was < 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 list_to_atombif with arbitrary arguments coming from API user, potentially opening door to blow our erlang VM’s memory up (running out of atoms).

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 static resource for webmachine resulting in having separation of Ajax API and static content delivery, reducing the original stickyNotes_webresource.erl to 18 lines of code.

Read More

Note to myslf: there is bitstring comprehensions in Erlang

It easy to handle streams of bytes in Erlang. For example consider the following simple task:
given a stream consisting of 3-byte chunks we want to return a stream consisting of those 3-byte chunks whose first byte is zero.

Read More

Simple HashMap in JavaScript

I’ve implemented HashMapJS, a simple hash map like implementation.
The project is located at github.

Read More

Dynamically scoped variables in Ruby

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 ;) )

As you may know Rails routing mappings are stored in global variable ActionController::Routing::Routes. So together with Craig McMillan I’ve hacked really evil piece of code ;) but it does the job!

Read More