opensource

S2ajax v1.0 connects simply PHP and JavaScript

S2ajaxHere comes S2ajax v1.0!
And it was long overdue. Six months already since I posted S2ajax says “hi()” I can hardly believe it.

What I think of as v1.0’s main feature is that it is now possible to simply export classes in PHP and these classes can be instantiated in JavaScript. Whenever these instances are modified through asynchronous method calls, these modifications are transparently persisted server-side.

The concept

Is it a PHP class? Is it a JavaScript class? Why, it’s both! The class is defined in PHP on the server. Instances of the class are created on demand using JavaScript on the client. Whatever modifications are made to an instance are serialized on the server.
You can create a complex application using as many classes and instances as you need.

100

Under the hood

The PHP class is exported; the proxy JavaScript code is generated.
Whenever the client needs to access one of the class’ properties/methods, the proxy transparently talks to the class; the class lives server-side.

99

The Client’s point of view

An arbitrary number of instances of the class can be created in JavaScript.
The only hint that you are using a client-server architecture is the fact that when invoking a method, its return value is obtained through a callback. This mechanism allows your client interface to remain responsive while the server is preparing a response.

101

The server’s point of view

S2ajax automatically persists your instances’ state and data between consecutive asynchronous calls. You still get the benefits of the “shared nothing” approach of PHP but complex objects can be manipulated through an unlimited number of clients requests.

102

A code sample

Server-side

Let’s create a class that will increment an instance variable every time a method is invoked. Let’s keep it as simple as possible:

class CounterTester
{
    private $counter;
 
    function __construct() {
        $this->counter = 0;
    }
 
    public function increment_counter() {
        $this->counter++;
        return $this->counter;
    }
}

Clearly, every time increment_counter() is invoked, $counter will be incremented and its new value returned.

Client-Side

First, an instance of our class is created. Then, when a user click on the button labeled ‘Increment counter’, the instance’s increment_counter() method will be invoked and the new $counter value returned to our callback and displayed.

?View Code JAVASCRIPT
<script>
function display_result(val) {
    alert(val); // Display new counter value
}
var counter = new CounterTester();
</script>
<button onclick="counter.increment_counter(display_result);">Increment counter</button>

Note that we could create as many instances of our class as we wish and provided we display the matching buttons, we could independently increment multiple counters.

Get it now!

Click our valiant friend “Octocat”, artistically represented below, to go to S2ajax’s Github page. If you just wish to use the library, look for the [Download] button:

Git!

Git!

If you enjoyed this post, make sure you subscribe to my RSS feed!


“n2″ Message Board Software: Update

This is a cross-posting with the nextBBS support board.

Some of you already know about this but keep reading…

Development of nextBBS v2 was steered in a new direction about two months ago and this is for the better.

“n2″ is the software’s new code name. And the change is more than skin-deep because it is actually the result of the merger of three different pieces of software:

+ wtcBB
+ nextBBS v2 “current”
+ My own PHP framework called “Lenses”

The result is a very fast, very user and admin-friendly board with easy install and localization across the board.

This new direction is very exciting for at least two reasons:

1. It allows me to work without being hindered by “youthful” mistakes I had made when developing nBBS v1 such as SEO being an afterthought and an Admin Control Panel that was too intimidating

2. wtcBB and nextBBS share a common philosophy on many levels and integrating both programs allows me to pick the best implementation. A few examples are BBCode editor, sub-sub forums, micro-caching, high logging granularity, editing look and feel in the admin cp…

You can follow progress through my submits and the issues tracker.

Go to my original post to see a few screenshots. I should bring a demo online soon.

If you enjoyed this post, make sure you subscribe to my RSS feed!


Wordpress FLV Player Plugin v2.0

Cat  reloadedClose to two years ago, after quickly putting together my own FLV Player plugin for Wordpress (original post) I added it to Wordpress.org’s already impressive list of plugins. Who knows? Someone else might find it useful (it’s been downloaded more than 4,500 times since then so I guess that means someone did)

Yesterday a few people commented on that original post, thus reminding me of that plugin. It shamed me when I revisited its packaging to find out that it required from its users to download more pieces left and right. So, here it is, brand new v2.0, with everything included, and this means brand new SWF wrapper and brand new Flash file. Hope you forgive the fact that it took me all this time to provide a real self-contained archive.

wordpress-e280ba-flv-player-c2ab-wordpress-pluginsGo to the Plugin Page

Oh, and there is something I would like to address about this plugin. It’s actually a reply to one of the comments I received recently:

What do you mean by “a flash stream”? Does it stream an flv or use progressive download? To stream flash, you need a streaming media server. You should be clear and say what you mean – stop contributing to peoples’ ignorance.

Well, I hope it helps you feel a little less ignorant to know that the answer is “both.” This plugin can stream both types, depending on your use of a http-type or a rtmp-type URI. It can also play live streams. More information can be found here.

If you enjoyed this post, make sure you subscribe to my RSS feed!


Twitterified Client now fully Open-Source

Twitterified Client - Open Sourced!Well, this title says it all!

Find the announcement here.

And, of course, find the source code at GitHub: here.

If you enjoyed this post, make sure you subscribe to my RSS feed!


Bespin in Titanium: From The Jaws Of Victory…

bespin is really an intriguing project. Since I’ve grown frustrated with the inconsistencies between the various code editors that I have been using — I work on Leopard at home and Ubuntu at work — I thought that creating my own editor would be the answer to that. Nothing fancy, mind you. Just something consistent.

My first impulse was to use Flex. And it almost worked! Using mx:html I was able to wrap a nice web page in an otherwise very ActionScript-y application.
And then, catastrophe! Flex Webkit’s canvas implementation is subpar and I could only get a very mamed version of bespin. Nothing usable, anyway.

Thus, I turned to Titanium.
After some light trial and error, I got it to work!

Unfortunately, the result is less than awesome: Titanium’s Webkit gets easily overwhelmed and, worse, crashes reliably ( :g: ) as soon as I ask it to do some medium lifting.

This video shows the original victory followed by the vexing defeat:

Note that, to get it to work, I replaced embed.js with my own version that works around any dojo.request()/eval issue:

?View Code JAVASCRIPT
(function() {
    // -- Load Script
    var loadme = new Array();
    var loadScript = function(src, onload) {
        var embedscript = document.createElement("script");
        embedscript.type = "text/javascript";
        embedscript.src = src;
        embedscript.onload = onload;
        document.getElementsByTagName("head")[0].appendChild(embedscript);
    }
    var onScriptLoaded = function() {
        var src = loadme.shift();
        if(src)
            loadScript(src, onScriptLoaded);
    }
 
    var componentRequires = function() {
        dojo.require("bespin.bespin");
 
        dojo.require("bespin.util.canvas");
        dojo.require("bespin.util.keys");
        dojo.require("bespin.util.navigate");
        dojo.require("bespin.util.path");
        dojo.require("bespin.util.tokenobject");
        dojo.require("bespin.util.util");
        dojo.require("bespin.util.mousewheelevent");
        dojo.require("bespin.util.urlbar");
 
        dojo.require("bespin.client.filesystem");
        dojo.require("bespin.client.settings");
        dojo.require("bespin.client.status");
        dojo.require("bespin.client.server");
        dojo.require("bespin.client.session");
 
        dojo.require("bespin.editor.actions");
        dojo.require("bespin.editor.clipboard");
        dojo.require("bespin.editor.cursor");
        dojo.require("bespin.editor.editor");
        dojo.require("bespin.editor.events");
        dojo.require("bespin.editor.model");
        dojo.require("bespin.editor.toolbar");
        dojo.require("bespin.editor.themes");
        dojo.require("bespin.editor.undo");
 
        dojo.require("bespin.syntax.base"); 
        dojo.require("bespin.syntax.simple._base");
 
        dojo.require("bespin.cmd.commandline");
        dojo.require("bespin.cmd.commands");
        dojo.require("bespin.cmd.editorcommands");
 
        dojo.require("th.helpers"); // -- Thunderhead... hooooo
        dojo.require("th.css");
        dojo.require("th.th");
        dojo.require("th.models");
        dojo.require("th.borders");
        dojo.require("th.components");      
    }
 
    loadScript("js/dojo/dojo.js.uncompressed.js", function() {
        dojo.require = function(src) {          
            loadme.push('js/' + src.replace(/\./g, '/') + '.js');
        }
        componentRequires();
        dojo.require("bespin.editor.component");
        loadScript(loadme.shift(), onScriptLoaded);
    });
})();

As you can see, I override dojo.request() with my own, stack up all the component names, then load them one by one, waiting for each to be fully loaded before moving on.

If you enjoyed this post, make sure you subscribe to my RSS feed!


A very geeky Holidays break

Kill BillWas your break as geeky as mine? Come on, admit it: you’ve done at least one incredibly unsexy thing in the last couple weeks. I know I have. Well, in fact, I had to take a four weeks-long break and it shows in the number of silly things I’ve played with.

In no particular order:

If you enjoyed this post, make sure you subscribe to my RSS feed!


How To Make The EFF ISP Throttling Tool Work On Leopard

Switzerland LogoI love the idea of Switzerland, the new EFF tool for checking ISP throttling; unfortunately as of release Zero.0.5, Leopard seems to still be a mere afterthought. Here is how I worked around the few things that were not working out of the box.

First, Switzerland is written in Python and will require Psyco. It’s a good thing since Psyco is all about performance. If you do not have it already installed:

svn co http://codespeak.net/svn/psyco/dist/ psyco-dist
cd psyco-dist/
sudo python setup.py install
cd ..

Download Switzerland from https://sourceforge.net/project/showfiles.php?group_id=233013
Extract it and change to its directory; eg

tar zxvf switzerland-0.0.5.tgz
cd switzerland-0.0.5

The FastCollector provided doesn’t work. So…

rm bin/FastCollector.darwin

Now when we build FastCollector, it will be available in /usr/local/bin/FastCollector

Here comes the only moderately scary thing for non-developers. Use the patch command to modify switzerland/client/PacketListener.py. This is the input for patch:

diff --git a/switzerland/client/PacketListener.py b/switzerland/client/PacketListener.py
index 211b68f..dc0bbcc 100755
--- a/switzerland/client/PacketListener.py
+++ b/switzerland/client/PacketListener.py
@@ -93,8 +93,7 @@ class PacketListener(threading.Thread):
         p = platform.system()
         # Implementing the recommendations from
         # http://www.net.t-labs.tu-berlin.de/research/hppc/
-        if p[-3:] == "BSD" or p == "Darwin":
-          print p
+        if p[-3:] == "BSD":
           cmd = ["sysctl","-w","net.bpf.bufsize=10485760"]
           try:     # Recent FreeBSDs
             proc = Popen(cmd, stdin=PIPE, stdout=PIPE)
@@ -110,6 +109,14 @@ class PacketListener(threading.Thread):
             proc = Popen(cmd, stdin=PIPE, stdout=PIPE)
             assert proc.wait() == 0
 
+        elif p == "Darwin":
+          cmd = ["sysctl","-w","debug.bpf_bufsize=10485760"]
+          proc = Popen(cmd, stdin=PIPE, stdout=PIPE)
+          assert proc.wait() == 0
+          cmd[2] = "debug.bpf_maxbufsize=10485760"
+          proc = Popen(cmd, stdin=PIPE, stdout=PIPE)
+          assert proc.wait() == 0
+
         elif p == "Linux":
           vars = [("/proc/sys/net/core/rmem_default", "33554432"),
                   ("/proc/sys/net/core/rmem_max", "33554432"),

Let’s build and install everything:

sudo python setup.py install

Well, it was easy (if it worked!)

Let’s create a log directory for Switzerland:

sudo mkdir /var/log/switzerland-pcaps
sudo chmod a+wx /var/log/switzerland-pcaps

And finally let’s run it:

sudo switzerland-client

or if you wish to run your own server (you need to advertise it too!)

sudo switzerland-client --server yourserveraddress

Questions?

If you enjoyed this post, make sure you subscribe to my RSS feed!


Open Letter to The Blogging Microcosm: give me content, not school fights!

Cat fightFunny, how everybody is gazing at everybody else’s navel in our little world – disclaimer: I do not consider myself a Web2.0 “celebrity”, simply because I’m not – but even so it’s hard to always keep in mind that we are only talking about a very minor percentage of the world population, so busy are we all trumpeting that we are “building the future.”
Are we?

Loren Feldman’s quite innocent puppet show is now over. He wrote an open letter to Shel Israel, who was the butt of this particular joke, and that letter is quite bitter.
We are, in effect, moving from a situation where Shel Israel would have done himself some good by taking the joke graciously and instead damaged his image by over reacting, to one where Loren Feldman is the one reacting quite poorly – see his comments to his own post.

It would seem that Dave Winer is next. I will not go into details on this one, just read the comments at 1938media.com if you are that curious.

Some background: Shel Israel claims that he only met Feldman once, at SXSW, thus when Feldman writes “You and your crew”, he may be referring to Robert Scobble. True, it would appear that Feldman was fired from PodTech after posting his retarded “TechNigga” video. No link, I do not want Google to find a link from my blog to that. True, Scobble may have helped with the firing business. Honestly, I do not think that Scobble needed to intervene for people to realize of how little value the piece was. OK, there is always the possibility that there was a double layer of sarcasm: Feldman mocking people who rely on such stereotypes.

Well, that’s too bad: Feldman should move on. Israel should move on. There is money and sponsorship for everybody -well, everybody interesting- in the blogging world and I, for one, am reclaiming some much needed free time by unsubscribing from the blogs of people who keep obsessing over their jobs, Arrington, Scobble, and other topics that, while somewhat topical, live at the bottom of my list of things I give a hoot about. Yay!

My favourite blog post was made by Chris Edward and is titled “Loren Feldman: fighting for old media one blogger at a time.” It deliciously underscores the multi-facetted irony of Feldman’s post in such a compact post that it is a treasure of “content vs ego” ratio in my opinion. Suitably entertained, I decided to read more of Edward’s blog posts and found them interesting.

As a result, Chris Edward wins a new reader, others lose an old reader. If more people followed suit, I am sure that the numbers would have a welcome sobering effect on them.

I’m glad I’m not famous.

If you enjoyed this post, make sure you subscribe to my RSS feed!


My dilemma: rewrite and lose features or keep building on old framework?

I just posted the text below at http://www.nextbbs.com/do_topic_title_nextBBS-direction–please-give-your-input_id_1288

I know that a lot of open-source projects have gone through the same dilemma:

Well, what do we do now? Rip apart our existing software and restart with more up-to-date technologies, or keep building on the old workhorse, hoping that nothing will go wrong?
(more…)

If you enjoyed this post, make sure you subscribe to my RSS feed!


Ext Licensing: Oh, what a mess.

Lego Soap OperaWhen things start smelling “funny” in the open-source community, they tend to go to the dogs with the haste of a drunk marching band.

Today’s drama is brought to you by your friendly ExtJS community. For those of you not familiar with ExtJS, it is a professionally made Javascript library that allows web application developers to create very elaborate desktop-like applications. Jack Slocum originally started this project as a YUI extension. That extension being open-source. He’s then regularly improved it by adding support for different building stones such as JQuery and finally a full-ExtJS solution, reaching ExtJS 2.0. For those of you who have managed not to fall asleep while reading my ramblings, you already know that I’ve used ExtJS myself, for instance when I created the ExtPHP wrapper.

Where this gets complicated is that Jack decided to license the assets under a different license, allowing him to retain all rights. I would like to make very clear that it’s his work and he can do whatever he wants with it. I am just narrating, here. He also added a clause that supposedly completely voids the LGPL license if someone attempted to use his work to create a derivative framework.

After a lot of moaning in the community – to the drum of “that’s a GNU license, man, the whole idea is that you cannot add restrictions!”, he decided to change the LGPL license to a pure GPL one, while retaining a pure commercial license on the side. I’ll bet he thought, at that point, “At least now things are clear.”

Well, that was only the beginning of a real sh*tstorm that threatens to cause a lot of damage to everyone involved, culminating -fleetingly, to be sure- with Sanjiv Jivan’s scathing blog post. Sanjiv, if I am correct, wrote a Ext “compiler” for the GWT library, called GWT-Ext – note that there is another project, apparently endorsed by Jack, that connects ExtJS and GWT. Sanjiv decided that he would fork the last LGPL release of ExtJS and start a new project. You may remember that Jack tried to prevent this by adding a provision in his license agreement.

The crux of Sanjiv’s beef with Jack Slocum is this: Jack created a great product, led people to believe that it was truly open-source when it wasn’t, and doesn’t understand open-source licenses. Jack is greedy. Now, the crux of Jack’s beef with Sanjiv is this: Sanjiv created a nice tool based on hits product, doesn’t understand open-source licenses and, oh, is greedy.

So, our protagonists are not talking to each other. This love story was consumed a long time ago. And potential “corporate” customers, like me, are revisiting the possibility of building their product on top of pure JQuery extensions and living happily ever after.
Now, in a move that would shame any seasoned soap opera writer, a new character enters left stage. And her name is OpenEXT. Contrary to what Dion Almar wrote, it is not a fork: the idea is to create patches that can be dropped on top of ExtJS. Now, I am curious: was Dion right when he posted his own piece on the topic? After all, things seem to change at a meteoric pace around here.

Anyway, stay tuned for even more implausible developments!

If you enjoyed this post, make sure you subscribe to my RSS feed!