I’ve been working recently on a new project, Jello, which I intend to be an easy to use expression/rule evaluator, and has just hit a useable-though-lacking-in-features state.

Why use?

I wanted Jello to be really simple to use, and think I achieved that. Before I began writing Jello I tried a number of different approaches, including using embeddable languages such as Boo or IronPython, parser generators such as Irony, and expression evaluators such as NCalc. I found that for my needs, to evaluate simple expressions, the embeddable languages were just overkill; parser generators worked well, but I had to write a lot of boilerplate each time to specify the core of the language; and the expression evaluators didn’t offer the flexibility I wanted; and so decided to roll my own. The result is a compact, simple and easy to use and (will be) highly configurable.

Typical use cases could be:

  • Decision/underwriting rules (I’ve used this in a document generator to allow users to specify criteria to determine if a part of a document is included or not. I’ve also implemented similar behaviour in the past (before writing Jello) for scripting rules to determine whether a buyer accepts a particular lead or not)
  • Evaluating simple expressions, such as calculating the max value for a field based on some criteria
  • Essentially, any time that you need your users to be able to have a high degree of flexibility when specifying rules/calculations, Jello is your friend

Syntax

Currently it has a very simple syntax consisting of basic equality/logical operators (&&, || and ==) and arithmetic (+, -, * and /), and supports basic data types: booleans, strings, dates and numbers (only decimal types to keep it simple – after all, Jello is intended for the users of your system). Date formats are not fixed allowing you to specify the format that best suits your needs – the default is to use the StandardDateParser which ships with Jello and uses the .net DateTime.TryParse(dateString, out date) method internally, but you can create a class which inherits from the IDateParser interface and parse dates however you’d like. Using the StandardDateParser you can also specify an IFormatProvider and DateTimeStyles if you’d like.

You can also use variables which take their values from a data source that is passed into the parse result when executing. Data sources are classes that inherit from a simple interface, IDataSource, which specifies only a single method: bool TryGet(string key, out object value). The only datasource currently shipped with Jello is a CompositeDataSource, which simply allows you to aggregate multiple data sources, though I intend to add a basic dictionary datasource shortly so that you won’t always have to create your own classes.

Modifiability

As I said before, the syntax is currently fixed, but my hope for Jello is that it will become flexible enough that it can be fit to most uses. The date parser is the first example of this to be added, since there are so many nuances with dates that I didn’t want to force users to use one specific date format, but I plan to add configurable operator overloading, functions and macros so that Jello can be bent to any will.

Todo:

  • Add operator overloading / functions
  • Support user-defined datatypes
  • Add macros to allow substituting operators (ie. using ‘and’ instead of ‘&&’)
  • Extend grammar to make it more than just expression evaluation; allowing for specifying/amending variables, if/else statements, loops and return statements.

In my last post, looking at “typed” function overloading, I mentioned that I was working on a new project aiming to simplify animations in paper.js, and I’m pleased to say that today I was able to get the project to what I would consider a useable form. I’m also pleased to mention that I completely changed the approach that I was taking with the api, with the effect that it is simpler to use, and has also allowed me to do away with all the function overloading stuff! (Don’t worry, I’m not a hypocrite; I said at the beginning of the post that it was something I disagreed with in Javascript!).

Anyway, check it out over on GitHub, I’d love to hear any opinions or feedback.

 

Usage

paper.animate.js has been designed to integrate easily with existing paper.js code. Simply prefix a transform command withanimate(duration, updater, chain) / animate(duration, chain). This returns a proxy object, PaperAnimate.AnimationProxy, with overloads for all the transform methods found on paper.Item. To run the animations, call the update() method of the proxy from the paper.js view onFrame event handler. It’s easiest to use the PaperAnimate.Updater to make this easier and to automatically clear up any finished animations (more info below).

var shape = ...
var updater = new PaperAnimate.Updater();

function onFrame(e) { // paper.js onFrame event
    updater.update(e);
}

// Translate
shape.translate(new Point(100, 50); // paper.js
shape.animate(1, updater).translate(new Point(100, 50)); // paper.animate.js

// Rotate
shape.rotate(90); // paper.js
shape.animate(4, updater).rotate(90); // paper.animate.js

// Chaining
shape.animate(2, updater, true) // 2 secs, chained = true
     .scale(2)
     .shear(0.1, 0.3);

// Animate Shape (paper.animate.js only)
shape.animate(2, updater).replaceShape(differentShape);

// Not using PaperAnimate.Updater
var anim = shape.animate(1).rotate(45);
function onFrame(e) {
    anim.update(e);
}

Params

animate(duration[, updater, chain]) or animate(duration[, chain])

  • duration (Number): Specifies, in seconds, the duration of the animation. If unspecified then defaults to 1 second
  • updater (PaperAnimate.Updater): Makes it simple to work with and update many animations
  • chain (Boolean): Allows chaining commands by returning PaperAnimate.AnimationProxy object rather than originalpaper.Item. Defaults false, in keeping with paper.js api (returning item)

Supported Transformations

paper.animate.js supports all the transformations currently implemented by paper.js:

  • scale(scale[, center])
  • scale(hor, ver[, center])
  • translate(delta)
  • rotate(angle[, center])
  • shear(point[, center])
  • shear(hor, ver[, center])
  • transform(matrix, flags)
  • fitBounds(rectangle[, fill])

PaperAnimate.Updater

The updater is simply an easy way to manage animations. Rather than having to maintain a list of all the animation proxies returned every time animate() is called, simply pass in the reference to the updater and then call update() only on that. Additionally, the updater will remove animations when they have completed

I’m a big fan of Twitter’s Bootstrap html/css/javascript framework, and use it on practically all new web projects that I work on. It makes it super easy to quickly knock up a slick-looking web application, and since it’s built on less it’s really easy to customize the look of each site.

That said, the markup is complex enough that when developing sites I typically have the docs open in another tab at all times as a reference point, which lead me to start building little HtmlHelper extensions to create the more complicated elements, such as navbars, forms, etc. These extensions have been bounced around from project to project, and have ended up a little scrappy as they’ve been built as-and-when with no real planning, but they have been hugely useful, so I decided it was finally time to look at rewriting them. Check out the Bootstrap Extensions repo over on GitHub, or have a browse through the documentation (design somewhat inspired by the original bootstrap docs!).

The library is by no means complete, as of writing this I’ve only implemented lists, buttons, button groups + toolbars, navbars and progress bars; but it’s a start, and I intend to cover the majority of the more involved elements. I’ll also look at fine tuning the API to make development as pleasurable as possible.

Update: This project has been included on The Big Badass List of Twitter Bootstrap Resources. Check it out, there’s some brilliant useful stuff on there

I’m currently working on implementing an issue tracker within a customer’s web portal so that their users can more easily log system issues with us and be updated on their progress, without the need for additional phone calls and emails, and it’s been decided that a convenient feature would be for it to integrate closely with our own issue tracking (which is hosted on BitBucket).

After a quick google I stumbled across a nice, albeit fairly young, API wrapper that uses RestSharp – conveniently named BitBucketSharp. It was started just a couple of months ago by Dillon Buchanan, and has made it really easy to start use the BitBucket API from within a web application.

There is another similar project, CSharp.Bitbucket, which is built upon the Spring.NET Social framework; but a quick look at the download counts on NuGet shows developers clearly favour RestSharp, with 28,230 downloads, rather than Spring.NET Social’s 529. CSharp.Bitbucket does, however, have the advantage of being hosted on NuGet, so makes it really easy to pull down and have a play with.

Since BitBucketSharp is fairly new, it currently only really has support for GET requests, so I’ve forked it and am in the process of adding support for creating/updating resources, and I’d also like to get a NuGet package up when I get the opportunity.

Check it out at bitbucket.org/j_wallwork/bitbucketsharp