Sometimes in a configuration file you want to express something should happen periodically or after a delay. The problem is that Erlang like most languages wants to see an integer number of milliseconds, while I want to write something that will make sense. If I see 5400000 in a config file I have no idea what that means. On the other hand if I see {90, minute} then it is very clear that this is a time value.
Here is a brief function that will let you specify time as seconds, minutes, hours or days.
A blog dedicated to exploring the future of Web Development, including CoffeeScript, Erlang and other functional web development platforms.
Sunday, October 14, 2012
Thursday, October 11, 2012
Meta Web Services
I have been building applications and services on the web for almost 20 years. Really it has been that long I put up my first very simple web app with Perl 5 and mSQL (MySQL wasn't out yet) in about 1994. And what I find is that I seem to still be writing the same code now as I was then.
Ok I switched from Perl to PHP to Erlang and have upgraded architectures in there a few times but I am still writing CRUD code by hand after almost 20 years. At one point I actually built a generator to build PHP from templates which was nice but really why am I doing this?
What I really want is a generator script. Let me write a set of rules in to describe the service in a config file of some form, then have the computer build the code.
Now the question is what do I want in this package....
Ok I switched from Perl to PHP to Erlang and have upgraded architectures in there a few times but I am still writing CRUD code by hand after almost 20 years. At one point I actually built a generator to build PHP from templates which was nice but really why am I doing this?
What I really want is a generator script. Let me write a set of rules in to describe the service in a config file of some form, then have the computer build the code.
Now the question is what do I want in this package....
- Written in Erlang
- Use Yaws or Cowboy
- Support Mnesia, MySQL, PostgreSQL and Riak
- Support Web Sockets
- REST
- Authentication via OAuth or local
- Integration with Web services (Facebook, Twitter, Dropbox etc)
- Allow Custom Extensions
- Should Focus on providing web services not pages (JSON over HTML)
- Easy to read setup files
Well there you have it. I want to be able to describe my service in a DSL check that into github and have my server pull it out, build what I want and push it live.
Monday, September 10, 2012
CoffeeScript keeps crashing on me
I am a big fan of CoffeeScript, I think it is the syntax that Javascript should have. The problem I have is this, the compiler keeps crashing on me. I generally set it up with the "--watch" command so that it will keep track of my files and recompile as I go, which is nice. Except when it crashes and I spend 5 minutes wondering why my new code is not showing up.
I had originally thought to write an erlang app to fix this, but then I realized that I need something much simpler, a shell script will do:
(yea I suck as shell scripts) But it does the job. It runs the compiler and if it should exit well then bash will just restart it without bothering me.
When in doubt have the computer do the boring and repetitive stuff!
I had originally thought to write an erlang app to fix this, but then I realized that I need something much simpler, a shell script will do:
(yea I suck as shell scripts) But it does the job. It runs the compiler and if it should exit well then bash will just restart it without bothering me.
When in doubt have the computer do the boring and repetitive stuff!
Sunday, September 9, 2012
Mixed in with all the other programming stuff I am doing I am going to be teaching my Step Daughter to code. So we will be working threw "How to Design Programs" which should be fun so expect to see some scheme here intermixed with the CoffeeScript, Erlang and whatever else runs across my desk. Look for it under tag "scheme"
Thursday, September 6, 2012
A Mock Sync For Backbone.js
If you want to do unit tests on a backbone.js application it would be really nice if you could replace the default sync with one that will not make an AJAX call but will return prebuilt data so you can test the application.
This is very easy to do. What you need to do is to replace the default Backbone.Sync object with one that will pull prebuilt data. This is what I have been using so far. It just takes an existing table of mock data and when a request comes in uses the URI as a key to retrieve the data and resets the data for the collection.
Obviously this only works for reading data, for Update, Delete etc things get a little more complex but there is no reason to not be able to expand this approach.
This is very easy to do. What you need to do is to replace the default Backbone.Sync object with one that will pull prebuilt data. This is what I have been using so far. It just takes an existing table of mock data and when a request comes in uses the URI as a key to retrieve the data and resets the data for the collection.
Obviously this only works for reading data, for Update, Delete etc things get a little more complex but there is no reason to not be able to expand this approach.
Wednesday, September 5, 2012
Running QUnit on Save with PhantomJS
I have started doing TDD in my CoffeeScript using QUnit. This is pretty amazing really and it has been making me pretty happy. However there is still the very repetitive cycle of save, switch to a browser run the tests and switch back to emacs. What would be amazing is if I could get emacs to do everything for me. After all I should be able to program my system to do the boring repetitive stuff
It turns out that this is not even that hard, but it does take several parts.
First of all we need a browser to run the tests. We could use Selenium (which I rather like actually for other things) but even better would be to use PhantomJS which is a headless browser.
What PhantomJS is is a browser based on WebKit (which is also used by Chrome and Safari) that does not display anything. But you can interact with it via JavaScript. So what I want to do is launch my web page (which is on a local web server) then have QUnit run and return the results. Thankfully the PhantomJS folks have a script do just that in the form of a QUnit Driver. (They also have one for Jasmine if you like that).
So now I can call PhantomJS like this:
phantomjs run-qunit.js http://localhost:8080/test.html
I can have it load up my page and return the results of qunit:
What PhantomJS is is a browser based on WebKit (which is also used by Chrome and Safari) that does not display anything. But you can interact with it via JavaScript. So what I want to do is launch my web page (which is on a local web server) then have QUnit run and return the results. Thankfully the PhantomJS folks have a script do just that in the form of a QUnit Driver. (They also have one for Jasmine if you like that).
So now I can call PhantomJS like this:
phantomjs run-qunit.js http://localhost:8080/test.html
I can have it load up my page and return the results of qunit:
'waitFor()' finished in 407ms.
Tests completed in 222 milliseconds.
80 tests of 95 passed, 15 failed.
It gives me a result like that. Which is nice, it tells me exactly what I want to know, if everything passed or not. So what I want is for emacs to run it when I save a file, to do this I run this bit of emacs lisp.
What I would really like for future is to change it so that if everything passes it will give me a line
that says "203 tests pass" or the like and if all tests do not pass then it should open a buffer to tell me exactly which tests failed. (Maybe even try to figure out which file the failing code is in to bring me to the right spot to fix it )
Monday, June 11, 2012
Orthonomics: AMI Magazine Article Review: Duped
Orthonomics: AMI Magazine Article Review: Duped: anon426 My editor is Simon St Lawrence who I don't think was around then, but I have also worked with Andy Oram. I have been an O'Reilly fan for a very long time and when the chance came to write books for O'Reilly I jumped at it. Of course I spent 3-4 years making sure that chance would come.
If my career as a programmer is flying now its because I spent the last 5 years building it up!
If my career as a programmer is flying now its because I spent the last 5 years building it up!
Subscribe to:
Posts (Atom)