Angel \”Java\” Lopez on Blog

March 3, 2015

New Month’s Resolutions: March 2015

Filed under: JavaScript, C Sharp, Open Source Projects, NodeJs — ajlopez @ 4:30 pm

Time to review the past month’s resolutions, and to write the new ones

- Complete first version ClojJS [partial] see repo
- Complete first version BScript [partial] see repo
- Improve ClojSharp [complete] see repo
- Improve ScalaSharp [complete] see repo
- Complete first version Chip8 emulator [partial] see repo
- Write more posts about JavaScript and Artificial Intelligence [pending]

Although ClojJS has many pieces in place (like resolving requires using a clojjs.json file), there are many forms to be defined in clojure.cljs. I should release a first version with the current status, and then add support for detecting node_modules with clojjs.json definitions, build for browser version, etc.

Additionally, I worked on:

- Start SimpleDSL node.js/javascript module [complete] see repo
- Improve AjScript [complete] see repo
- Improve AcquarellaJS [complete] see repo
- Start DValues [complete] see repo

Then, this new month’s resolutions are:

- Improve ClojSharp
- Improve ScalaSharp
- Write posts about JavaScript and Artificial Intelligence
- First published version of ClojJS
- Add npm modules support to ClojJS
- First published version of BScript
- Improve Chip8 emulator
- Give a full-day course on NodeJS

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

February 20, 2015

Liqueed Project (2)

Filed under: Express, JavaScript, Liqueed, NodeJs — ajlopez @ 8:07 pm

Previous Post

Liqueed is a Node.js project, repository at

https://github.com/liquid-co-ops/liqueed

And it has a package.json file, the current content:

{
  "name": "liqueed",
  "version": "0.0.2alpha",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "test": "simpleunit ./test ./testserver"
  },
  "dependencies": {
    "express": "~4.2.0",
    "static-favicon": "~1.0.0",
    "morgan": "~1.0.0",
    "cookie-parser": "~1.0.1",
    "body-parser": "~1.0.0",
    "debug": "~0.7.4",
    "ejs": "~0.8.5",
    "express-ejs-layouts": "^1.1.0",
    "ostore": "0.0.4",
    "simplelists": "0.0.4",
    "simpleasync": "0.0.5",
    "mongodb": "~1.4.19",
    "bcrypt-nodejs": "0.0.3",
    "express-session": "~1.9.3"
  },
  "devDependencies": {
    "simpleunit": "0.0.5",
    "simplejquery": "0.0.1",
    "zombie": "2.5.1"
  }
}

It is a private application, so you cannot publish it to the public npm repository.

It is a typical Express application, the initial code was generated with the express-generator. The file bin\www contains the source code to launch the application. It uses express modules, like morgan, cookie-parser, body-parser, express-session, but there are others that were included to be used from the logic of application server:

- ostore: Simple JavaScript objects repository, in-memory, used in many test and in the initial version, implementing persistence in-memory, without the need for a database.

- mongodb: the current app uses MongoDB as NoSQL persistence

- simplelists: a simple utility library with list/array functions

- simpleasync: a library to chain asynchronous callsbacks.

- bcript-nodejs: encryption module written in JavaScript

In the tests (written using Test-Driven Design workflow), it uses:

- simpleunit: test library, based on internal use of assert, exporting the test functions.

There are new tests to exercise the Single Page Application of public\index.html, using:

- zombie: it visits a page as a browser

Topics for the next posts: application structure, written tests, exposed API, MVC admin pages, persistence, SPA client, etc.

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

February 9, 2015

Programando for Internet of Things

Usually, I practice programming every day, applying TDD (Test-Driven Development) workflow. There are non-public projects, but the majority of that practice is public, in my GitHub account. In my opinion, Node.js is a very interesting technology: ubiquos, powerful and simple. I can implement many ideas using Node.js/JavaScript, in a easier way than using other technologies (Java, .NET, Scala, Ruby, Python, Clojure, Smalltalk). The only price to pay: understand and use the JavaScript callbacks.

There are many ideas and implementation, in current applications, public projects, startups. An interesting topic is Internet of Things (OK, a “buzzword”). Many startups are fighting in that battle field. Maybe, many of them will be adquired by Google, Apple, Microsoft. These are interesting time. But this is a time for implement ideas, in open source projects. Then, an startup can leverage the open source world. I think that the important part of an startup is the execution, not the idea or the implementation..

Meanwhile, I want to implement some ideas in my public projects. This post is written to describe the landscape of ideas to implement:

- Collect informaiton from devices connected to the Internet. To have a data repository, the data is send by SDKs, one SDK per device type. Then, use the repository and the collected data in other projects.

- Apply Artificial Intelligence (OK, it is a wide term, but the better we have), to all the collected data, discovering patterns, using machine learning, deep learning. I wrote some JavaScript projects to explore such paths.

- Take decisions, execute actions, using expert systems or other systems. My first implementations, again, are in JavaScript/NodeJs. Having somethink like IFTTT but open source, consuming Internet of Things data.

- Run all these implementations as distributed applicacionts, not only horizontal scalability or cloud computing. Node.js, again, is an interesting vehicle to implement first experiments and applications. Only if needed, then switch to compiled languages and technologies.

I apologize my auto-reference to my projects, but it is the way to explain why I’m writing them.

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

February 6, 2015

Sending messages to Slack using JavaScript/Node.js

Filed under: JavaScript, NodeJs, Slack — ajlopez @ 12:42 pm

A year ago, Slack entered in my radar:

https://slack.com/

I read “Slack is a platform for team communication; everything in one place, instantly searcheable, available wherever you go”.

In general, I am somewhat skeptical to online tools like this, I prefer a simpler combination. For the above statement, I simply use gmail and mailing lists per project or team. The interesting story behind Slack founder:

http://www.wired.com/2014/08/the-most-fascinating-profile-youll-ever-read-about-a-guy-and-his-boring-startup/

My links about Slack at:

https://delicious.com/ajlopez/slack

Example:

https://medium.com/@slackhq/11-useful-tips-for-getting-the-most-of-slack-5dfb3d1af77

Past wednesday, at afternoon, I started to explore how to send programmatically a message to Slack, using their exposed API, using Node.js (I think Node is the simplest technology to use in this kind of experiments). More general info about the API at:

https://api.slack.com/

My current experiment code:

https://github.com/ajlopez/NodeSamples/tree/master/Slack

I searched in Google for some Node.js module to access Slack, my first result:

https://github.com/xoxco/node-slack

Initially I installed it using npm, in a working directory. My first try:

var domain = process.env.SLACK_DOMAIN;
var token = process.env.SLACK_TOKEN;

var Slack = require('node-slack');
var slack = new Slack(domain, token);

var channel = process.argv[2];
var message = process.argv[3];

console.log('Sending message', message, 'to channel', channel);

slack.send({
    text: message,
    channel: '#' + channel,
    username: username
});

You must set environment variables: SLACK_DOMAIN and SLACK_TOKEN. When you enter to a Slack group, the group has an associated domain. For example, I’m a member of https://squeakros.slack.com the group for Smalltalk Squek Rosario. Other group is https://nodejsar.slack.com, Node.js Argentina. The provided token correspond to a user AND an applicaction, it can be obtained from:

https://api.slack.com/web

The above program run, without errors, being invoked via

node run.js general “Hello, world”

(on Windows). The first argument after run.js is the target channel, without the initial #, and the second argument is the message text. All OK, but the message didn’t arrive to the channel. After a bit of research, I found the Pull Request:

https://github.com/xoxco/node-slack/pull/8

that it was not merged with the original source, yet. Some months ago, the Slack API changed. The suggested pull requests uses another access point, a web hook URL provided from:

https://your-domain.slack.com/services/new/incoming-webhook

I applied the suggestion I found in one comment, and I put directly the link to the new code, in my package.json:

{
  "name": "slack-demo",
  "private": true,
  "version": "0.0.1",
  "dependencies": {
    "node-slack": "git://github.com/Dahlgren/node-slack.git#hook-url"
  }
}

An now, my program use the web hook URL, provided via a variable environment:

var hookUrl = process.env.SLACK_WEBHOOK;
var username = process.env.SLACK_USER;

var Slack = require('node-slack');
//var slack = new Slack(domain, token);
var slack = new Slack(hookUrl);

var channel = process.argv[2];
var message = process.argv[3];

console.log('Sending message', message, 'to channel', channel);

slack.send({
    text: message,
    channel: '#' + channel,
    username: username
});

Now, it works! Topics to research: any way to use domain/token again? other modules?.

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

February 3, 2015

New Month’s Resolutions: February 2015

Filed under: C Sharp, JavaScript, NodeJs, Open Source Projects — ajlopez @ 5:14 pm

Again, time to review the past month’s resolutions, and to write down the new ones.

- Continue add distributed features to AjErl, Erlang-like interpreter in C# [pending]
- Improve ClojSharp [complete] repo
- Improve ScalaSharp [complete] repo
- Improve Chip8 emulator [complete] repo
- Code generation with AjGenesis for Node [pending]
- Improve Basic Script Language for C# [complete] repo
- Write JavaScript and Artificial Intelligence [complete] post 1 post 2 post 3

Additionally, I was working on:

- Start ClojJS, ClojureScript to JavaScript compiler and runtime [complete] repo
- Start DValues, data values store for internet of things [complete] repo
- Work on Liqueed project [complete] repo
- Improve AjScript, JavaScript-like interpreter in C# [complete] repo

This new month’s resolutions:

- Complete first version ClojJS
- Complete first version BScript
- Improve ClojSharp
- Improve ScalaSharp
- Complete first version Chip8 emulator
- Write more posts about JavaScript and Artificial Intelligence

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

January 23, 2015

Liqueed Project (1)

Filed under: Express, JavaScript, Liqueed, MongoDB, NodeJs, Open Source Projects — ajlopez @ 6:36 pm

Next Post

Today, I want to present the Liqueed Project, see repo at:

https://github.com/liquid-co-ops/liqueed

It is a web application based on an idea by @acyment, read post:

http://blog.agilar.org/index.php/2014/04/30/leancoops-first-draft/

The basic idea of the application is to help teams that are developing something in the way that Cyment suggested, on the issue of allocation of shares on the project. For several months, the application (code, backlog, ideas, implementation, hosting and others) has been putting together by a “liquid” team (with entry and exit of people)

In this series of posts starting today I want to discuss interesting technical issues raised by the project. For today, I commented that:

– It is a Node.js application, exposed to the web using Express. Bringing the programming language is JavaScript.

– In addition to some internal administration pages with MVC, has an API exposed, exchanging JSON.

‘- There’s an app Single Page which is what would have to use the end user to view projects, voting, distributions of shares and to enter new ratings

– Most of the code was written using the workflow of TDD (Test-Driven Development). Even the first code implemented the model in memory, allowing easier progress on the implementation of use cases, without bothering about persistence (even the SPA client can run without having a walk server)

– A few months ago, we added persistence with MongoDB. We could use another database, relational perhaps. We are not taking advantage of the facilities to handle documents MongoDB yet. Only chose it for its ubiquity in development platforms and different Node hosting services.

– Some weeks ago, we added Istambul for code coverage.

– When TDD tests for pure code began to be long, we created a textual DSL (Domain Specific Language) that allows us to write text files for more complicated functional tests.

– Begin to add tests of SPA (Single Page Application) using Zombie

And there are more details and topics to comment, in the upcoming posts.

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

January 2, 2015

New Month’s Resolutions: January 2015

A new year begins. Time to review past month’s resolutions:

- Add distributed features to AjErl, Erlang-like interpreter in C# [partial] see repo
- Improve ClojSharp [complete] see repo
- Improve SimpleLisp [complete] see repo
- Code generation with AjGenesis for Node [pending]
- Start Basic Script Language for C# [complete] see repo

Additionally, I was working on:

- Improve ScalaSharp [complete] see repo
- First operations in Chip8 emulator [complete] see repo
- Write Clojure samples (Ring, Compojure) [complete] see repo
- Work on Liqueed project [complete] see repo
- Improve AjScript [complete] see repo

This new month’s resolutions:

- Continue add distributed features to AjErl, Erlang-like interpreter in C#
- Improve ClojSharp
- Improve ScalaSharp
- Improve Chip8 emulator
- Code generation with AjGenesis for Node
- Improve Basic Script Language for C#
- Write JavaScript and Artificial Intelligence posts

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

December 10, 2014

SimpleLisp (2) Compiling Lisp Values and Variables to JavaScript

Previos Post

Let’s review the project’s implementation

https://github.com/ajlopez/SimpleLisp

the Lisp compiler to JavaScript, written in JavaScript, following the workflow of TDD (Test-Driven Development). All is “work in progress”, so today I will explain part of the implementation but it could be change in the future, when new use cases were added, and new ways of doing things were implemented.

I took the decision that each Lisp symbol is a JavaScript variable. So, the compilation of a symbol is:

exports['compile symbol'] = function (test) {
    test.equal(sl.compile('a'), 'a');
}

The sl is the SimpleLisp module, loaded in this test file (test/compile.js)

An integer and an string are compiled to natural values in JavaScript:

exports['compile integer'] = function (test) {
    test.equal(sl.compile('42'), '42');
}

exports['compile string'] = function (test) {
    test.equal(sl.compile('"foo"'), '"foo"');
}

It’s quoted values, too:

exports['compile quoted integer'] = function (test) {
    test.equal(sl.compile("'42"), '42');
}

exports['compile quoted string'] = function (test) {
    test.equal(sl.compile("'\"foo\""), '"foo"');
}

I decided to compile Lisp nil to JavaScript null. The boolean values are the same:

exports['compile nil'] = function (test) {
    test.equal(sl.compile('nil'), 'null');
}

exports['compile booleans'] = function (test) {
    test.strictEqual(sl.compile('false'), 'false');
    test.strictEqual(sl.compile('true'), 'true');
}

But, what happens if an expression serie is compiled? I build an anonymous function, invoked without arguments, and the last expression value is returned:

exports['compile two symbols'] = function (test) {
    test.equal(sl.compile('a b'), '(function () { a; return b; })()');
}

Next topics: compilation of a Lisp lisp, and more quoted values, macros, ect.

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

December 4, 2014

New Month’s Resolutions: December 2014

It’s time to review past month’s resolutions:

- Give a talk about JavaScript and Artificial Intelligence [complete] see repo see talk read Spanish post
- Neural network in JavaScript example [complete] see repo
- Genetic Algorithms in JavaScript example [complete] see repo
- More Code Generation using AjGenesis for NodeJs [pending]
- Basic Script Language for C# [pending]
- Improve SimpleScript for JavaScript [complete] see repo

Also, I was working on:

- Improve SimpleLisp, Lisp to JavaScript compiler [complete] see repo
- Improve RuScript, Ruby interpreter in JavaScript [complete] see repo
- Improve RustScript, Rust-like interpreter in JavaScript [complete] see repo
- Create SimpleDT, simple decision tree in JavaScript [complete] see repo
- Improve ClojSharp, Clojure-like interpreter in C# [complete] see repo
- Backgammon evaluation page [complete] see repo

This new month’s resolutions:

- Add distributed features to AjElr, Erlang-like interpreter in C#
- Improve ClojSharp
- Improve SimpleLisp
- Code generation with AjGenesis for Node
- Start Basic Script Language for C#

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

November 28, 2014

SimpleScript (3) The Parser, Expressions and Commands

Previos Post

Let’s visit the Parser, that is a separated module. It starts with a simple declaration:

'use strict';

var lexer;

if (typeof lexer == 'undefined')
    lexer = require('./lexer');

var parser = (function () {
    var TokenType = lexer.TokenType;
    var binoperators = [ "+", "-", "*", "/", "==", "!=", "<", ">", "<=", ">=" ];

It uses and requires the lexer module. After this declaration, there are many expressions and commands. This is the expression “class” for a name (ie, foo):

function NameExpression(name) {
    this.isLeftValue = true;

    this.compile = function () {
        return name;
    };

    this.getName = function () {
        return name;
    }

    this.collectContext = function (context) {
        context.declare(name);
    }
}

In an upcoming post, I will describe the detection and construction of commands and expression. An expression should implement two methods: compile, that returns an string with the compiled JavaScript code associated to the expression, and collectContext, that allows the discover of used variables in an expression/command. In the above code, NameExpression declares its name to a context, an object that is recovering the used variables.

This is an IndexedExpression, composed by an expression and another one for the index (it’s like foo[42+1]):

function IndexedExpression(expr, indexpr) {
    this.isLeftValue = true;

    this.compile = function () {
        return expr.compile() + '[' + indexpr.compile() + ']';
    };

    this.collectContext = function (context) {
        expr.collectContext(context);
    }
}

The collectContext visits the internal expression (I could add the visit of the index expression, too).

There are commands, like IfCommand:

function IfCommand(cond, thencmd, elsecmd) {
    this.compile = function () {
        var code = 'if (' + cond.compile() + ') { ' + thencmd.compile() + ' }';
        if (elsecmd)
            code += ' else { ' + elsecmd.compile() + ' }';
        return code;
    };

    this.collectContext = function (context) {
        cond.collectContext(context);
        thencmd.collectContext(context);
        if (elsecmd)
            elsecmd.collectContext(context);
    }
}

The distinction between commands and expressions is a formal one. Again, a command should implement compile and collectContext. The above code generates a JavaScript if command.

As usual, I followed TDD (Test-Driven Development) workflow. Partial tests example:

exports['Compile string without quotes inside'] = function (test) {
    test.equal(compileExpression("'foo'", test), "'foo'");
    test.equal(compileExpression('"foo"', test), "'foo'");
}

exports['Compile name'] = function (test) {
    test.equal(compileExpression("foo", test), "foo");
}

exports['Qualified name'] = function (test) {
    test.equal(compileExpression("foo.bar", test), "foo.bar");
}

exports['Indexed term'] = function (test) {
    test.equal(compileExpression("foo[bar]", test), "foo[bar]");
}

Remember: No TDD, no paradise! ;-)

Next topics: how to recognize and build expressions and commands.

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Older Posts »

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 69 other followers