Posts

How long NodeJS setTimeout takes on various environments?

Image
A while ago, I posted about latency spikes while sending messages through RabbitMQ. I'm back to the latency topic with a bit more measurements. The results back then turned out to be a bit of mystery and surprise to me, and latency is not something that can be easily debugged. It took many small steps to better understand what's happening. First of them, was closer look at what impact does the environment have on the test. One of the things that I tried back then was running benchmarks in VirtualBox on idle MacBook Pro - my primary home machine. I was also using an ageing ThinkPad laptop with 32bit CPU, but it's results were hardly comparable to 64bit architectures so I left it. Anyway, VBox+MacBookPro turned out to be fairly bad idea, because those extra layers add a lot of noise, whereas latency test is exactly that moment in time when you don't want any noise. Running the tests in the cloud (i.e. DigitalOcean) appeared to be much better because that way, each...

Talking with DigitalOcean from shell or JSON + bash = rcli

RESTful APIs with JSON are all over the software world.  SaaS, PaaS and other aS'es frequently expose HTTP endpoints that eat and breed JSON. They're fairly easy to work with by using almost any language, except when it comes to do something really simple from a shell script. Having extremely positive experience with JavaScript library Ramda that makes JSON processing very verbose, I'm now discovering new uses of it's command-line sister - Rcli: Ramda for Command line . DigitalOcean example Let's pretend we have a droplet in DigitalOcean and want to run a script on it. We're going to figure out droplet IP using API and run some script there via ssh. Sounds ideal for bash script. IP=`curl_get_droplet | \   R path droplets | \   R find where '{"name": "example.com"}' | \   R path networks.v4.0.ip_address ` ssh root@$IP 'bash -s' < script.sh For simplicity, I replaced exact curl command with curl_get_droplet func...

Spikes in RabbitMQ + NodeJS latency test

Image
Measuring things is a fun way to confront assumptions we put everywhere. In software development products tend to be based on tens of assumptions, such as that network will be fast enough, REST or database transaction time short enough, success rate for external API calls within reasonable range. Knowing the limits of those assumptions is always worth at least one beer. The other day I was looking how long it takes my message queue, RabbitMQ, to pass messages from producer to consumer. RabbitMQ has loads of options: queues, topics, durability, acknowledgements, clustering to name a few. It's not obvious how those different options affect latency.  I wrote two little NodeJS processes - producer and consumer, based on samples from RabbitMQ tutorial, to measure how long it takes a message to fly from one process to the other. Those processes would just run many times with various configs to produce data - big latency table. Unfortunately, the very basic scenario turned out to be a...

Drawing in Graphiti

Image
It seems Eclipse Graphiti is really popular lately. Germany is using it to build cars, Engineers in India are getting to speed with it as well. Finally I made a try as well and fell in love with the simple APIs and helpful docs. The only thing that struck me is that most diagram editors out there are used mostly to draw just boxes and connections between them. Is that really all you can do!?!?? Ok so you here's what I did, a simple drawing tool in Graphiti: Click below to see it in action! And Fork it on Github Youtube video:

Trouble signing Apps for OSX Mountain Lion

Image
If you're building desktop Apps for OSX, chances are you'll need or you're already working on getting them signed with Apple's certificate. Otherwise your users might see this, starting with Mountain Lion: I just signing few apps and scored new items in my erroropedia: Error 1: "Error signing data" $ productsign --sign 'Developer ID Application: YourCompany' from.pkg to.pkg productsign: signing product with identity "Developer ID Application: YourCompany" from keychain /Users/user/Library/Keychains/login.keychain Error signing data. productsign: error: Failed to sign the product. Reason: keychain is locked for access from SSH. Try security unlock-keychain -p You might also need to enable access to certificate private key for all applications: Error 2: "MyApp.app: object file format unrecognized, invalid, or unsuitable" One solution that worked for me: export CODESIGN_ALLOCATE="/Applications/Xcode.app/Cont...

How to create Restful API in Zend Framework 2

Your ZF module just needs to provide Controller that speaks REST (for example RestfulController) and make sure that generated response will be formatted in JSON, in other words configure JSON rendering strategy. Below you can see an example controller. Note that it has convenient methods for to get all elements, single element, create/update and delete an element: use Zend\Mvc\Controller\RestfulController; class UserController extends RestfulController { public function getList() { return array("users" => array()); } public function get($id) { return array("id" => $id); } public function create($data) { return array("created" => "yes"); } public function update($id, $data) { return array("updated" => "yes"); } public function delete($id) { return array("deleted" => $i); } } When associating this controller to route, make sure to NOT use 'action' parameter. Otherwis...

Wedding table problem

Here's the old ancient wedding table problem that each man inevitably has to solve on his way to honeymoon. Research on the topic shows that some philosophers simplify this problem to set partitioning problem (not sure if they were on any wedding, or are they just dinning philosophers). Whereas others assign the problem to the social nature of participants. But I guess that for all my readers it's obvious that this is strictly mathematical subject and should be analysed from the algorithms perspective. Problem statement: Newlyweds are holding a party of n guests, where 2m of them comes in couples and the rest comes single. There's one long table with n chairs, split equally on both sides and each guest needs to have a chair assigned. Each couple has to together. Guests sitting next to each other, or on the opposite sides of the table are in talking range. There's a graph G(V, E), where each vertex represents a couple or single guest and each edge represents an acquai...

Choosing JS build tool

Lately I was tasked to setup a JS based project together with full build and testing automation. Today I'd like to share the build and testing part, as it turned out to be quite interesting problem. In short, we have a little JavaScript library that is designed for browsers. During build it should be packaged from source (e.g. multiple extensively documented files) to several different versions (e.g. bundled with other files, minified, etc.); ran against unit tests and validated with JSLint. Assuming that someone would like to try this library, they might be willing to build and test it as well, so a JS-friendly technology would be a perfect hit, won't it? Ok, so it was time for a little research on what do others use for building their JS libs. Half of the internet seems to be using Makefiles, while the other half is deep in love with Ant. To be specific, jQuery, Bootstrap, Code9 IDE were using make, while for example Dojo and Firebug were on Ant! It's actually quite relie...

Google Summer of Code + Eclipse PHP Tools !?

Image
It's that time of year again when students join open source projects, disrupt the old traditions and bring new ideas into life as part of Google Summer of Code! Last year I was mentoring a great project led by Karol Gusak , which was crossing the edge of Web and desktop developer tools. Karol built Eclipse PDT into Orion web tools , bringing core PHP coding support to cloud. Click to see the video Do you hate how Eclipse PDT works, absolutely can't stand what great feature it's missing, or wondering why it still doesn't integrate with that other awesome technology in your mind? Start thinking and chime in with your ideas on Eclipse PDT email list , post it on ideas wiki or contact me ! I'd be happy to mentor this year again, and I'm on look out for anything cloud mobile revolutionary lego embedded wordpress css javascript php zendframework symfony automotive node mongo and smart tv too.

No error dialogs in eclipse headless test

Here's a small funny thing I learned a while ago while running GUI tests of Eclipse application and now stumbled upon it again. When running Eclipse tests headlessly, certain dialogs don't show up as they would normally (e.g. when writing/recording the test). This is because of flags: org.eclipse.jface.dialogsErrorDialog.AUTOMATED_MODE = false; org.eclipse.jface.util.SafeRunnable.setIgnoreErrors(true); So if you for example have a test scenario that DOES expect an error dialog to show up, make sure you have above flags set correctly, or find out a different assertion than waiting for an error dialog.

Orion PHP Support demo

Image
If you're following Eclipse planet , you couldn't have missed Karol Gusak's weekly status reports about PHP support that's being built for Orion. If you still haven't tried PHP in Orion yourself, here's a little demo now on YouTube that nicely shows syntax highlighting, content-assist as well as overall PHP experience in Orion. Click below to check it now.

Making extensible GUI with org.eclipse.ui.menus

Image
It's actually first time I had to make a custom part of GUI extensible. In an Eclipse forms editor like following, we wanted custom actions to come from various plugins: Since eclipse APIs provides this sort of extensibility with their org.eclipse.ui.menus extension point, I looked at how to reuse that mechanism. It turns simple. All you need to do is, while creating the editable area, add: final Composite parent = ... // that's the area we want to make extensible ContributionManager contributionManager = new ContributionManager() { public void update(boolean force) { for (IContributionItem item : items) { item.fill(parent); } } }; IMenuService service = (IMenuService) getSite().getService(IMenuService.class); contributionManager.add(new GroupMarker("testing")); service.populateContributionManager(contributionManager, "toolbar:org.zend.editor1?after=testing"); contributionManager.update(false); Now to contribute something to that area, you ...

Starting and immediately using OSGi bundle: possible?

Lately I had this little thing to do: an OSGi bundle (SuperTool) comes with some other OSGi bundle (GreatSdk) included. SuperTool depends on logic in GreatSdk so the first thing it needs to do during activation is to install GreatSdk and immediately after that start loading classes from GreatSdk. At first thought it seems logical to make SuperTool-GreatSdk dependency optional, to let SuperTool install and start safely without GreatSdk. Once installed, during startup SuperTool should install GreatSdk and start using it, for example: BundleActivator.start(BundleContext context) { greatSdk = context.installBundle("file:///path/to/great.sdk_1.0.0.jar"); greatSdk.start(); GreatSdkStarter gss = new GreatSdkStarter(); // separate class in SuperTool that references some classes from GreatSdk gss.start(); // creates some GreatSdk classes } Unfortunately this fails in gss.start() with ClassNotFoundException: java.lang.ClassNotFoundException: greatSdk.Sdk at org.eclipse.osgi.internal.lo...

Installing V8Cgi on Mac

V8CGI is a very thin Apache module encapsulating V8 - Google's JavaScript engine that's used e.g. in Google Chrome. Those concerned with NodeJS stability may consider V8CGI a better choice, thanks to stability provided by Apache base. A short while ago, on DevMeetings.pl DevCamp we've been playing with V8CGI, RingoJS and Node. Thanks to good performance , intuitive and high quality APIs , V8CGI turned out to be the black horse of the whole event, although installing it on Macs was little tricky. Readers with Windows and Linux should follow to V8CGI home page , where they can get precompiled Windows binary and learn how to install binary on Ubuntu . Mac users, let's open terminal and try to build the V8 apache module ourselves. Getting V8CGI to work is four steps: 1. Getting the source code 2. Building it 3. Configuration 4. Test drive 1. Getting the source code When checking out sources from SVN, we actually need two packages V8 and V8CGI: a) svn checkout http://v8cgi...

Search by multiple keys in CouchDB

While developing a simple Twitter clone on V8CGi + CouchDB stack, we faced an interesting problem. We have a CouchDB database with users and messages. Each user has many followers and he'd like to see messages from all these followers. So we need to query tweets database for all documents that have author belonging to the list. In SQL it's something as simple as: SELECT * FROM tweets WHERE author IN ("szymon", "wiktor", "marek") SORT BY timestamp; In CouchDB it turned out to be an open issue https://issues.apache.org/jira/browse/COUCHDB-523 As far as I remember we ended up with running two separate queries. I'd be happy to hear how others solved this!

Signing firefox extensions

Signing FF extensions is pretty straightforward. Lately I've been going through some strains related to them, so I thought I'd share lesson learned. You have two sides that need to match with each other: online update URL and extension itself. Online update URL is a single file - update.rdf. Extension is an XPI file, with install.rdf file inside. Update.rdf contains a list of available extensions. Each extension should have checksum information, e.g. in sha1 algorithm. Once update.rdf is complete with all information and checksums, it must be signed with signer key. Note that, every time you change any of extension, it's checksum will likely change and so you need to update and re-sign update.rdf as well. On the other side, the install.rdf included in our XPI file needs to have our public key. Once you create install.rdf and put public key there, you can forget about it. XPI file does not have any checksum or signing. This all sounds nice and well but sometimes it doesn...

Building Windows installer with WiX

WiX is Windows Installer XML (WIX) Toolset. It's an open source project coming from Microsoft. Actually, it was the first project that Microsoft has officially published under Open Source license. Initially it appeared on SF.NET, but recently has moved to Microsoft's owned CodePlex.com. Half of the internet still points to SF though. This tool let's you pack a bunch of files into a user-friendly MSI installer, including GUI, silent install, repair, windows registry editing and Start menu customizations. WiX is a bunch of cool ideas. The first one goes with the each tools names. There's Heat, Candle and Light. They act as preprocessor, linker and compiler. So no matter whether you know everything about compilers, or you always left it to the IDE - tools seem friendly from the very first look. As name says it, the spine of the toolset is XML. To turn on the heat, developer needs to specify files to install, user interface, user interactions, install steps, resources and c...

Two Eclipse p2 repository operations to make you happy

On the integrations side of the Eclipse business I often happen to need two things: 1. add a random OSGi jar to repository 2. copy from one repository to another Looking thru p2 manual it's not always entirely obvious how to do it, so here goes my take on the subject. All my automation uses Ant, so I'll speak a bit of Ant now: 1. Add a random OSGi jar to repository <p2.publish.featuresAndBundles repository="file:/path/to/destination/repository" e.g. ${buildDirectory}/repo publishArtifacts="true" compress="true" append="true" source="/absolute/path/to/folder/with/jar" /> Few notes: 1. source attribute must be an absolute path. 2. source path must contain "features" and "plugins" directories. So if you have only one bundle, make sure to put it under plugins dir first. 3. make sure repository attribute is a URL, not plain path 2. Copy from one repository to another <p2.mirror verbose=...

Extending Eclipse Orion

Image
Yesterday Eclipse E4 team announced Orion - an experimental Eclipse Web IDE. There's plenty of information about the project on Orion wiki . Orion is a set of JavaScript and HTTP APIs that simplify common development part of rich applications, like file storage, preferences, authentication, dialogs, selection. Since it's coming from Eclipse, Orion is skewed towards IDE development, so from start it also includes text editor with some decent features, like JavaScript syntax highlighting and JSLint integration. The project may go towards strengthening it's JS IDE feature set, as well as enhancing it's core side - extensibility, client APIs ...or do it all at once. In any case it's going to be fascinating journey! So how to extend Orion? One can re-implement existing HTTP API in language other than Java; add more HTTP APIs, e.g. for task management, calendar, etc. Same with JavaScript API - it seems fairly easy to add more. Looking at this from classic Eclipse adopter...

Google App Inventor Eclipse Plugin

Image
Hey, in case you missed it, here it is - the App Inventor plugin for easily making Android apps straight from your favourite IDE. Together with git, task management and debugger now you can make not only silly kitty apps, but something bigger too :-) See it in action: (embedded Youtube video below) ..hm so wouldn't that be easy with web plugins ?