Wednesday, July 17, 2013

Toilets and innovation

I have always been surprised by the difficulty that knowledge and innovation find to flow across cultures, fields, countries.

My wife just called me panicky to tell me that the washer water is coming out and it is all over the wooden floors. The most silly litlle thing and you have permanant damage to the floors. If I were in an appartment or a second floor the damage would extend to the ceiling of the guy below me. This disaster would never happen in Europe. There every toilet has in the middle what the showers have here: a small covered drain ,  and the toilet floor is always built in a way that it has a tilt towards that point. On top of avoiding flooding the appartment, it makes washing toilets a much less ugly chore.

(I will avoid discussing the details of the opposite problem. European toilet bowls haven't discovered the simple idea of being filled up with water (its more than that - they use a different flushing technique) Water is only at the very bottom which makes flushing/self cleaning a disaster compared to American toilets bowls...)


Nodejs development trick

I am developing an app . I have pushed out most of the functionality of the app in modules. The modules are relatively application specific - but they would allow someone to create a similar/slightly different app without having to deal/change much of the module-encapsulated code.
Any this has resulted in a 2 level deep dependence
 app depends on module1
module1 depends on module2.

To keep things developped in parallel modules are alredy in repos.. and published as they advance.
When I need to do some concurrent development across modules/apps how do I do it.

Here is my trick
I have cloned the repos of all three app, module1, module2 above.
I have run npm install in the app where I prefer to work
I run
> nodemon index.js 
in the app.
I remove the (sole code ) index.js in the node_modules and replace them with a soft link to the repos..
> cd node_modules/module1
> rm index.js
> ln -s ../../../module1/index.js .
> cd ../..
I do the same for the deeper module as well:
> cd node_modules/module1/node_modules/module2
> rm index.js

> ln -s ../../../../../module2/index.js .

At this point I can edit the module's index.js inside their own repos...as I would have like to do and the changes are automatically reflected in my app repo. Nodemon is smart , it does anyway a recursive decent and follows the symlinks... saving my index.js in the module repo results in nodemon restarting my app. 

The only problem is I need to remember and not do any destructive operations on the node_modules tree.


Living on github

1. I am happy/proud that my github contributions are getting denser :
Still I find it hard to keep a 7-day streak.. I think it has to do with the length of my code iterations.. (and yes one day I want my contributions chart to look like substack's :-).

2. Looking at my repositories I realize that I dislike the fact the home page becomes this endless list of .files. At a minimum every repo of mine would have 4 dot files:


The reason that I need to commit .gitignore, .jshint and .cover is that I collaborate with others. They fork the repo and .jshint is the coding rules that I want to enforce, .coverignore is the coverage I need them to have etc. So this is a feature request for github : please collapse the dot files as a "hidden file" line that one can expand at whim. This will make the list more similar to what you would get with an ls in unix.




Monday, June 24, 2013

Language trends

Continuing from last related post about this,
read a dr. dobbs article (kind of happy that this publication still exists.. it was the publication we were respecting the most with my friends as we were getting into the PC world back in college (83-88) )
Dr Dobbs post :

Language surveys mentioned :
 ohloh
 tiobe

I would add to these the
 hacker news poll
 github stats  (can't find historical version of this)


Finally regarding google trends as a metric for judging the reach of a language.
Google trends is good to assess whether a language is picking up or is in decline.
It is harder to use as a comparative metric... many language have less unique terms than others and adding keywords eg. programming next to them makes the comparison less apples to apples (nodejs programming vs java programming vs ...)

I was discussing this again with sk and I wanted to make the argument that there is a trend towards a single language across all layers ... (js front end, back end nodejs, db mongodb)
anyway using github.com/language page from the archive.org

here are the data  (the data show that they can't be too relied upon, viml made it in the top10 a couple years ago... and the swings are too massive => they must be looking at file-commits/short terms instead of something more reliable...)

2009
Language Name Percentage
  Ruby 30%
  JavaScript 18%
  Python 9%
  Shell 7%
  Perl 6%
  C 6%
  PHP 5%
  Java 4%
  C++ 4%
  Objective-C 2%

20010
Ruby  19%
JavaScript  16%
Perl  12%
Python  9%
Shell 7%
PHP 7%
C 6%
Java  5%
C++ 4%
Objective-C 2%

2011
JavaScript  19%
Ruby  17%
Python  9%
C 8%
PHP 7%
Shell 7%
Perl  7%
Java  7%
C++ 4%
VimL  2%

2013

JavaScript  21%
Ruby  12%
Java  8%
Shell 8%
Python  8%
PHP  7%
C 6%
C++ 5%
Perl  4%
CoffeeScript  3%

Thursday, June 20, 2013

Working notes - sorter.herokuapp.com

So where am I :

I was implementing a travis-ci-like badge providing lines of code report

Purpose
  - get some exposure on building travis-ci like services
  - see how viral sth like this can be
  - leverage a rather amazing program like perl cloc

In doing so I decided to structure the service on top of web service version of cloc  (what modules if they were to exist would make the implementation of whatever you want to develop trivial..)
In doing so I realized/decided that implementing the cloc web service (ie exposing the plain cloc functionality as a web service) would need some more basic glue that could be reused by any use of someone that would want to expose a typical stdin/stdout processing unix utility as a functional web service. In doing so I realized that to get the full power of the later I would some way to describe nodejs streams so as they do their streaming server-side….  (all that in http://www.otdump.com/2013/06/unix-utilities-as-web-services.html)


Anyway, this was yesterday. I asked my friend gl for an opinion and he saw me falling down my typical infinite recursive loop ... and he suggested to cut and return to the original cloc web service .
(which was itself pretty far deeper than where I was supposed to be)
He probably didn't hear that I am on vacation which in the context means that  I am Alice and I have no problem chasing rabbits wherever they might take me...

So, 1 day later, I have my first unix utility as a web service:
 http://sorter.herokuapp.com

You can use it rather simply:
> cat /etc/passwd|curl --data-binary @- 'http://sorter.herokuapp.com/?args=-t&args=%3A&args=-k&args=3&args=-n'
....
_krb_changepw:*:932:-2:Open Directory Kerberos Change Password Service:/var/empty:/usr/bin/false
_krb_kerberos:*:933:-2:Open Directory Kerberos:/var/empty:/usr/bin/false
_krb_anonymous:*:934:-2:Open Directory Kerberos Anonymous:/var/empty:/usr/bin/false
> 

%3A is :  
The code is surprisingly simple
https://github.com/ogt/sorter/blob/master/index.js


The interesting things in the code are:
Apparently req and res are streams, readable and writable correspondingly.
Any process you get a handle on (with spawn, exec etc.. or just via global var process.xx) gives you access to file descriptors like stdin, stdout, that are themselves streams.
A little handy function "child" create a duplex stream out of anything that has stdin and stdout.
You need duplex streams to do things like
a.pipe(b).pipe(c).pipe(d) :
b and c need to both send and recv a just send down the  pipe and d only receives from its left....
So, req.pipe(proc).pipe(res) requires very little documentation to explain what it does!.

The testing client would do sth like:

var req = request(options, function(res) {
  res.pipe(process.stdout);
});
process.stdin.pipe(req);


We could create a duplex stream out of req/res, (there is a utility function called duplexer or sth in event-stream) so as we could make the 3 lines above look more the server ... but that would come at a cost: we only have a handle to both req and res after the callback is called... which means that we would need to do the "piping" inside the callback.  Its not a big deal but the code above starts pushing data to the server earlier... I think...

Anyway, the fun thing is that this was sooo easy to do. On top of that heroku seems to have in its minimal slugs the core unix utilities, so this works on heroku.
This means that I can create - with practically no effort one app (seder, gziper, gunziper, awker, sorter,...) for anything I like.. no effort and I get functionality (and service/cpu time) for free.
I like the xx-er terminology its funky enough that probably nobody has taken these names. I will probably push the single 10-line function of the server into a module... and then the project would be practically just the scaffolding of every nodejs heroku app. Nothing more. (by creating a separate app per utility, I get one server per utility - more cpu... Besides most unix utilities (e.g. ls) don't make sense this way.. Maybe I will create an automated way to generate these projects/repositories/deploys... how about doc... all I need is the man-page to markdown converter and that together with a common header would suffice... 



Tuesday, June 18, 2013

Unix utilities as web services

I wanted to convert a very useful unix utility (cloc) into a web service.
I thought, that someone may have already created a little glue that can do that.
Especially given nodejs  and the recent love that streams are getting there (https://github.com/substack/stream-handbook) together with the re-focus back into the unix small utility programs fit together with stdio/outs.. etc someone must have done it.

Anyway, so far I can't find anyone.
The only thing I found is someone 5yr old blog and broken references (guthub and gists weren't that popular then .. so no trace of whatever this guy did...)
http://swik.net/Unix/BASH+Cures+Cancer+Blog/Exposing+command+line+programs+as+web+services/b3x8u

This guy seems to have the right idea:

$ ./to_web.py -p8008 sort &
Thu Mar 27 13:45:54 2008 sort server started - 8008
$ ./to_web.py -p8009 gzip &
Thu Mar 27 13:46:29 2008 gzip server started - 8009
Use the services:
$ for i in {1..10}; do echo ${RANDOM:0:2}; done | \
> curl –data-binary @- “http://swat:8008/sort+-nr” | \
> curl –data-binary @- “http://swat:8009/gzip” | \
> gunzip
97
37
23
23
21
18
11
11
10
10
-
Note that the to_web.py, seems to be doing just a popen of the command passing the stdin/stdout of the server to the command. Even the URL query string is passed intact as  ... no need to think much about mapping cli parameters to url params.
The whole thing looks like substack's way of doing things.
(without any extra that substack may have already added I would use this
http://nodejs.org/docs/v0.4.6/api/child_processes.html  as starting point to write the ~10 line to_web.py
... possibly by using .pipe() instead of tie-ing outs  and ins manually https://github.com/substack/stream-handbook)

Any command that is sideffect free and uses just cpu/mem resources, can be made available to third parties... possibly with a bit lower than normal ulimit to prevent abuse... just like travis-ci....
I wonder how many of these commands are part of what heroku exposes... if it does it should be easy to create a free web-servuce version of all unix utilities. All that would be needed would some consistent naming for the domains  ... hm and some client side pipe operation (would we need any syntactic sugar??) across the web services.. If I recall correctly streams and related libs can be browserified just fine....
On the other hand Ideally I should be able to hook webservices directly as opposed to be using the browser as the intermediate point.
If I want for example to take a gziped csv file unzipped it sort it and re-zipped.. assuming that I have
gzip.herokuapp.com, gunzip.herokuapp.com  sort.herokuapp.com how would I do keeping the stream of bytes going from one webservice to the next....???

One ugly way would be to be calling gunzip with a special option
"send the response to "sort.herokuapp.com" instead of me
But that wouldn't work because then sort would send it to me instead of gunzip.herokuapp.com
I guess we would have to be calling gunzip with a special option
"send the response to "sort.herokuapp.com" instead of me but when doing so with a special option to
send it to gunzip.herokuapp.com" instead of me...

So then the trick is to create a library that does the "syntactic sugar" on top of the ugly thing above so as all I have to say is sth very simlar to
"gunzip.herokuapp.com PIPE sort.herokupapp.com PIPE gunzip.herokuapp.com



Sunday, June 16, 2013

Exporting from evernote

All my evernote files that are a "startup idea" have a unique title "NIDEA - xxx" (tags are nice - but for some types of notes - I add the unique keyword as part of the title... e.g.
HOWTO - xxx
NIDEA - xxx
TODOS - xxxx
)
anyway I wanted to capture the titles of all my nideas into a file to work with them... how to do that with evernote?
Ok : simple:
1. Do the evernote search that finds them, in my case 'nidea'
2. Select All or multiple select individual whichever you want..
3. File -> Export notes -> exports to some folder all the notes be default as an html file per note
4. cd to that folder, ls -1 and capture that output (the filenames are the titles) and paste it into your file..