Saturday, February 23, 2013

Civilization starter


I always want to think that I am fairly self-sufficient, in the sense that I depend on very few material things. Another way of saying this is that as longas I have my small backpack (which contains, laptop and associated parafernalia) I can just fly anywhere and be able to be productive - thus happy from where-ever I am. I guess thats not exactly true - there are a few things that I will probably be needing for a prolonged stay anywhere:

So I want to start compiling the list so as I can easily recreate my basic "civilization starter kit":


Assumes existance of studio-like place with mini-fridge, microwave (and for eggs mini stove top), 2 silverware, 2 plates, 2 cups. It is also important that all these things below should not be too expensive - ie, I can leave them behind without much guilt.


Coffee

+ From Amazon
  - Frappe Maker - $40
  - (if no fridge with icemaker) - portable ice maker - $100
+ From Local Supermarket
  - Nescafe/monthly
  - Sugar/monthly
  - Full Milk/weekly
  - Straws/once
  - Large 16oz transparent cups/monthly


Snack

+ From Local Supermarket
  - Salted roasted almonds  (monthly)
  - Sundried raisins (no additives) (monthly)
+ or from Amazon

  - Salted roasted almonds - $25
  - Sundried raisins (no additives) $20



Food

Paninis
+ From Amazon
  - Panini Grill - $50
  - Pastry Brush - $4 x 2

+ From Local SuperMarket
  - Gouda Cheese/Weekly
  - Good Ham/Weekly
  - Whole Wheat-minimal ingredients thin sliced  breads/Weekly
  - Butter/Weekly
  - Napkins/Monthly

Eggs
+ From Amazon
  - 12" Pan - $25

+ From Supermarket
  - Spatula set - once (or from amazon )
  - Large Organic Eggs (weekly)
  - Salt (quarterly)
  - Pepper (quarterly)
  - Ground Pepper (once)
  - Cold Pressed Olive Oil (Monthly)

Salad
+ From Local Supermarket
 + a
  - Good Tomatoes (weekly)
  - Kalamata Olives (monthly)
  - onions (monthly)
  - Soft Feta Cheese (weekly)
  - Olive Oil (also in eggs) (monthly)
  - Minimal ingredient Valsamic Vinegar (monthly)
  - Oregano (monthly)
 + b
  - lettuce (monthly)
  - green onions (monthly)
  - Lemons (monthly)

I will continue later with the 6 clothing articles (3 for winter and 3 for summer) that I need.

Friday, February 22, 2013

Work notes - loginator - smaller steps

Ok.
It seems that what I thought as the next step, ie, a system that simply allows signup/login is a bit too big of a jump, given the level of my ignorance. So I will create a sequence of helloworlds to move more incrementally.

A system that uses passport-local seems to need:
  - a db to save the information,
  - a session to remember that you are logged in,
  - cookies to allow for the session to be identified, and possibly
  - some basic routing since we have at least two urls /login and / .
Thats a lot.
So here are the steps that I would follow (found by mentally unraveling the dependencies of each of of the steps above)

- helloword-cookies (cookieparser?).
I would first add to my hello world the cookie functionality possibly keeping track something like the value that I entered in a form asking for a userid and my name (First, Last). After my first entry, the page should be able to display who I am and still allow me to  add a new identity
by re-filling the form.

- helloworld-db (mongdbhq?).
Then I would add a db to allow saving that information  (first, last) in the db keyed by my userid, save only the userid as a cookie. In the case the form would display who I am, allow me to switch identities to someone else by picking a new userid that exists already in the db, or add a new identity all together

- helloworld-routes (express)
I would break the single page site into multiple pages /index.html being the form that displays who
is currently logged in and gives links to logout, login-as-someone-else, register

- helloworld-session (?).
Then probably the next thing would be to see how I could use db backed sessions and session identifiers as the cookie in that case. In that case when I create the session I can store in there the name that I fetched from the db, and rely on that for subsequent fetches.

- helloworld-authentication (passport, passport-local)

Tuesday, February 19, 2013

Politics and why I don't like them




A friend sent me a white house petition. It was one of those well intended petitions that
 - has no chance to ever be voted for
 - are so flawed that they would cause more damage than do anything good
 - they are so naive that makes you wonder about the person that authored them

Of course like everyone else, I didn't read the petition, just read the title, agreed with its intentions and given that I knew and respected the person that forwarded it to me, I did the obvious thing.

I signed the petition and shared it at my google plus urging my followers to do the same

.. and perpetuated recursively the stupidity...

Sucks.


--- pasting arguments from follow-on skypes


> http://www.internationalstudent.com/study_usa/choosing-the-usa/usa-education-system/graduate.shtml
Every year 500K people are awarded a masters degree. and 45K a doctorate degree.

- We all know that everyone can get a job offer if they really want to - so thats not a true filter - it is just there to create the illusion to the petition signers that we don't bring people to the welfare state....

- This would mean that If US were to accept the petition above for Masters degrees an "Accredited University" industry would be created that would allow people to get Masters degrees - essentially a 10-20K/1yr for a green card. These universities would be most probably online and would very probably remind you some of today late night advertised online universities)

- This would mean that foreign students that currently can easily get a student visa would be limited/restricted at the get-go.


Work notes - loginator

Its time to move to the target app - the "loginator".
A simple application whose sole purpose in life if to allow signup, login, logout. My expectation is to
- use passport
- use sessions

When I am done after that I want to see how easy it will be to make the app a facebook connect like js plugin for other apps of mine.

By now creating heroku, github etc is pretty straightforward - I don't even need to read my old notes:
Here is the list of relevant links:

- Here is the github repo : https://github.com/ogt/loginator
- Here is the heroku app : http://secret-sea-3866.herokuapp.com (20+ sec delay at first fetch)
- Here is the blog post about this : http://otdump.blogspot.com/2013/02/work-notes-authentication.html

Here is what the app should look like:





typealone.com

I realize that several of my posts (all the work notes for example) (and the posts of a friend I follow) are in the form of capturing what I do, so as someone else (or me at a later point) can follow what I do, why I did it etc.

However, as a reader I am missing an important thing : the actual timing of the event.
Given that these work notes are being written in draft form in real time and then published - either when  reaching a milestone or in my case published several times - the blog could have captured the timing of the progress. Thinking it again what I need is something like skype,  where everytime I type I get the timestamp. I chose what I will include as a single chat message (one timestamp) or multiple.
Of course skype is adding all kinds of un-necessary information and has been increasingly worsening in its use from a developer... more and more substrings become emoticons, copy-ing and pasting from skype is a disaster (unless you do it in a very specific way ) etc etc.
Campfire was nice - it also had the nice property for auto-paste-bin-ing any large multi-line paste.


So, this is the service that I would need
typealone.com


Features
 - Condensed, customizable timestamping
 - Real ACE-like editor while writing every text message
 - Auto-save for every message.
 - Edit of any prior text - without messing up the timestamp
 - Option to time both the beginning of text typing , time of first submission vs time of last edit.
 - Developer friendly copy/paste
 - When pasting large things - ask for paste-bin-ing (configurable pastebin/gist etc). allow choice of # of lines displayed embedded etc
 - Allow any selection to be code formatted - using language specific highlight - do auto-guess of that for pastes
 - Allow unguessable urls that display any fragment of the typealone
 - Allow public urs to any point in the typealone tape.
 - Allow wiki-like anchor links (so as you can point from one place to another in the tape..

Hmm, I think I went from a simple utility to allow me to write work-note like posts (that are eventually copy-pasted to your blog) to a standalone service... Not clear what is the purpose of typealone anymore...
Anyway that was all I thought about it.

Monday, February 18, 2013

Twisted code

This is a piece of code from the node.js connect framework:


Note that function:

function app(req, res, next){ app.handle(req, res, next); }

Any guess what the it does?
It took me and my friend half an hour...
You define a function which the only thing that it does is call a non-existent function on the fuction's own pointer passing its parameters to it!!.

utils.merge is a generic array merge function
proto is the result of a require('proto').
Ah and right after the function above the code does

createServer.createServer = createServer;

The answer is that proto is a module that defines a set of functions that are each attributes of an object.
like

exports = module.exports = {
  use = function (foo) { },
  handle = function (boo) { }
};
As a result what the merge does ... is a dynamic blessing of on object to obtain the methods of an predefined interface : it assigns to the function pointer methods like "use" and "handle" that the function mentioned at definition time - but still its not execution time yet... this delay doesn't mean anything.

Of course, still knowing what the functions does... doesn't mean that we really know what it does ... but I am a step closer now.
In particular I don't understand how someone decides to put some part of the code
in a function method (e.g. handle and use) vs function body "function app(...) {   } "
and why the definition of app isn't in the proto file itself.

Work notes - using middlewares

Ok,
It seems that my simplistic web server is the perfect vehicle to help better understand middlewares in node.js. I understand all its pieces, and its obvious that every part is minimalistic/not sufficient for a production site,
 - logging,
 - mapping of url space to local filesystem directories,
 - handling of default files,
 - handling of content types,
 - handling of error responses,
 - handling of HTTP headers.

Each one of these represent a few lines of code in the 50-lin web.js files.
So what I think is an interesting exercise is to incrementally replace each one of those things with a connect middleware and see what changes need to happen in the process and what is left over in the end. What I am expecting to get from this exercise is
 - a more robust, production-level hello world
 - a better understanding of connect, middlewares
 - a system that I can add in the next step basic authentication, session management to build my simple utility app that I set as my goal.

Before proceeding a decision,  should I continue working on the existing repository?
Hm, the blog points to the files, but I can move the files as "examples". But the heroku setup (package.json, etc ) is what it is because we have no dependencies. Hm., it seems that in node.js/heroku the natural unit is the repository. Then I guess I will have many repositories, possibly one per blog post.
I should probably go back to the last post and leave a link to the repo + a link to the heroku app.
Done - Added links both in the repo's readme and in the blog

Creating a new repo - I guess the folder's name is important - it will be the repo's name using our hub create method.... copying all files in. and back into connect documentation.
Actually lets first try and make sure that everything is working fine before any changes - not very confident yet that I have mastered the create repo/github/heroku thing....
Ok following the previous steps

> # created a copy of the folder files with new folder name... 
> # from inside that folder

> npm install
> git init .
> git add . ; git commit -m 'init'
> hub create
> hub push -u origin master
> heroku login
> #test foreman start..  open ...
> heroku create
> git push heroku master
> #test open ...

I have now :

Here is the github repo : https://github.com/ogt/helloworld-js-heroku-depends
Here is the heroku app : http://guarded-stream-2218.herokuapp.com/  (20+ sec delay at first fetch)
Here is the blog post about this : http://otdump.blogspot.com/2013/02/work-notes-using-middlewares.html

First step see what it takes to use the connect createServer without any of the middlewares.
Hopefully it will be exactly the same as using the http's createServer method.
Making the following changes in two files (not very sure about what version I should use for connect..)

then running
> npm install connect
> #test foreman start.. open
> git add . ; git commit -m 'replaced http with connect'
> git push origin master
> git push heroku master
> #test open ..

and everything is still perfect besides the massive upload of dependencies to our github repo.
Next step, lets replace the loggin command in web.js with the logging middleware.


I will actually use  logger('dev') formatting option to get the color highlighting in my terminal
Next step, lets try to remove the error handling code.

Hm.. the error code seems intertwined with the file service code... may be I should do that first.
Apparently I will need to move my index.html file under public and set public as my static file serving folder.  Ok, I did that and added

+ connect.static(__dirname + '/public')

as well. Things work, and it seems that they serve off the public folder. But it worked so smoothly.. I am not sure. I start removing lines from the web.js and keep on testing it.
 - removed the contenttype code , still it works
 - removed the error handling code, still it works
 - removed the index.html defaulting, as well as the mapping to file path code... still it works
 - removed the complete function we added to createServer... still it works

At this point I started having doubts... could I be testing the wrong site - it seems to be working no matter what I do. I renamed index.html in the folder. I get an error. Maybe I should add an image to my hello world to make sure that the content type is set correctly.. did that still it works.
With every fetch I keep on getting the error code for the favicon - I haven't done anything about it... so I know the error handling works. Also I see a 304 ... what is that... it seems that the static middleware is "smart" and returns a "not changed" status code instead of resending the file every time..


Could that be it? I refresh the browser with Shft-Command-R and I get 200s!! Perfect. Everything works perfectly.

Maybe I should just fix the favicon as well. I think I saw a middleware for that.

I add it. The error disappears in the log. But no other difference. I should be seeing the "default connect icon". Don't see it. Maybe I should set a custom one. How to do that... found an online convertor.. convert my portrait to an icon and save it as favicon.ico. No diference. Maybe its because its in my localhost? I push it in heroku. Refresh and now I see it. I have been looking at the wrong place....all this time - the favicon is at the browser tab - not left of the url input box.. What was I thinking...

I push everything to github (commit).

I think I am almost done. Maybe I should add some decent css.
Need to use something modern.. Was it blueprint? compass? bootstrap? I browse a bit before I conclude   to bootstrap..  download the files copied them under public and with a couple small changes in the index.html file


we are done at last!!  (commit)

Sensing gravity

As I am standing up typing, I notice the usual back and on forth swaying on top of my feet. It is not fully intentional, neither tiring - but the more I focus on something the more it happens.
So I think that it happens for a reason:
When you sway your body does the following game : it lets your body completely loose to slowly follow a  locked-knee free fall but it fully monitors the body's inclination not from the ear's labyrinth (my head is locked - aligned with what I am focusing on) but from the extension of the feet muscles. Then when it reaches a certain point of imbalance  (calculated based on muscle memories) it tense the necessary muscles to rebalance the body.
It seems that the ear's signal is much more coarse in nature, (I can tell 1cm movements of my head, with my eyes closed, ie 1*360/(180cm * 2* pi) = less than 1/3rd of a degree in angular position from the vertical. A small organ (labyrinth) that relies on sensors millimeters apart (hair cells) seem improbably to be able to detect that.

It is also interesting that while the ear's balance signal is coarser - it indicates grander imbalances and thus when the brain gets two conflicting signal (feet muscles saying we are in balance, and ear saying we are falling (when you rotate fast and lose your balance for example), then the brain listens to the ear - not the the muscles (and  thats why we lose our balance and fall after self-rotating).

Sunday, February 17, 2013

Work notes - a minimal node.js heroku app


Here are the final instructions: (prerequisites brew instal node npm hub, and minimal web server )
(trying to see if embedded gists are better ... they look better but its too much work for each little piece of code....)  

Here is the github repo : https://github.com/ogt/helloworld-js-heroku/
Here is the heroku app : http://calm-taiga-3864.herokuapp.com/  (20+ sec delay at first fetch)
Here is the blog post about this : http://otdump.blogspot.com/2013/02/minimal-nodejs-heroku-app.html

Here is how I found them:

In my machine here is what it take to run the most minimal node.js app:

> mkdir ~/Dropbox/Home/code/node/helloworld
> cd !$
> cat > index.html
<html>
<body>
hello world!!!
</body>
</html>
> node ../simplewebserver/web.js &
Server running at http://127.0.0.1:8081/
> open http://127.0.0.1:8081/

Pretty simple (given that I have already brew installed node/npm).
Now you may ask what the heck is simplewebserver/web.js? Its the simplest no-dependency requiring file serving node.js code I have found from some prior node.js play-attempts of mine.
Here is the code:

> cat ../node/simplewebserver/web.js 
var http = require('http');
var fs = require('fs');
var path = require('path');

http.createServer(function (request, response) {

    console.log(request.url)
     
    var filePath = '.' + request.url;
    if (filePath.match('/[^.]*$')) filePath += '/'
    if (filePath.match('/$')) filePath += 'index.html'
         
    var extname = path.extname(filePath);
    var contentType = 'text/html';
    switch (extname) {
        case '.js':
            contentType = 'text/javascript';
            break;
        case '.css':
            contentType = 'text/css';
            break;
        case '.jpeg':
            contentType = 'image/jpeg';
            break;
    }
     
    path.exists(filePath, function(exists) {
     
        if (exists) {
            fs.readFile(filePath, function(error, content) {
                if (error) {
                    response.writeHead(500);
                    response.end();
                }
                else {
                    response.writeHead(200, { 'Content-Type': contentType });
                    response.end(content, 'utf-8');
                }
            });
        }
        else {
            response.writeHead(404);
            response.end();
        }
    });
     
}).listen(8000);

console.log('Server running at http://127.0.0.1:8000/');

Ok, What does it take to get that minimal hello world app running on heroku?

Following the instructions at github
> mkdir ~/Dropbox/Home/code/node/heroku-helloworld
> cd !$
> cp ../helloworld/index.html .
> cp ../simplewebserver/web.js .

> heroku login
> cat > package.json
{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
  },
  "engines": {
    "node": "0.8.x",
    "npm": "1.1.x"
  }
}
> npm install
npm WARN package.json node-example@0.0.1 No README.md file found!
> cat README.md
Simplest possible hello world heroku node.js app
> npm install
> ls
/                    README.md             package.json
../                  index.html            web.js
> cat > Procfile
web: node web.js
> foreman start
12:19:11 web.1     | started with pid 35582
12:19:11 web.1     | Server running at http://127.0.0.1:8000/

> open http://127.0.0.1:8000/

...
12:19:30 web.1     | /index.html
12:19:30 web.1     | path.exists is now called `fs.exists`.
12:19:30 web.1     | /favicon.ico
^C

# edit web.js and replace path.exists with fs.exists
#refresh browser

...
12:20:42 web.1     | /index.html
12:20:42 web.1     | /favicon.ico

ok things work normal locally
lets add to git 


> cat > .gitignore
.*
!/.gitignore
> git init
> git add .
> git commit -m "init"
> heroku create
Creating calm-taiga-3864... done, stack is cedar
http://calm-taiga-3864.herokuapp.com/ | git@heroku.com:calm-taiga-3864.git
Git remote heroku added
> git push heroku master
..... (lots of stuff)
http://calm-taiga-3864.herokuapp.com deployed to Heroku

To git@heroku.com:calm-taiga-3864.git
 * [new branch]      master -> master
> heroku ps:scale web=1
Scaling web processes... done, now running 1
> heroku open
Opening calm-taiga-3864... done

And here I get a crash
Logs show just that the app crashed.

> heroku logs
2013-02-17T20:29:29+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=calm-taiga-3864.herokuapp.com fwd="50.0.42.114" dyno= queue= wait= connect= service= status=503 bytes=

I repeat while running heroku logs tail

> heroku logs --tail
> heroku ps:scale web=1
> heroku open

and I find the offending entry :

..
2013-02-17T20:28:54+00:00 app[web.1]: Server running at http://127.0.0.1:8000/
2013-02-17T20:28:54+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 8000, should be 10472 (see environment variable PORT)
..

So it seems that my simple web server with the hardcoded port is not what heroku likes. The heroku environment wants to have control of the ports... Makes sense given that open heroku sends to port 80 so someone will need to redirect to a pre-known by heroku port. I grab the code from the suggested hello world ap and add it to my web.js

> grep -in PORT web.js
4 :var port = process.env.PORT || 8081; 
47:}).listen(port);
49:console.log('Server running at http://127.0.0.1:'+port+'/');


I git update, git push to heroku and everything works perfectly this time !
Last step is to push my git a githib repo so as I can point to the various files from this blog post.

# fixup the enclosing dir - so as it matches the repo name (to make hub happier)
> mv ../heroku-helloword ../helloworld-js-heroku
> hub create -d 'hello world app in node.js for heroku'
> git push -u origin master
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (11/11), 1.41 KiB, done.
Total 11 (delta 2), reused 0 (delta 0)
To git@github.com:ogt/helloworld-js-heroku.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.


Done!!

Saturday, February 16, 2013

Micro-appartments

I just started reading this post about micro-appartments



and I remembered a friend that was telling me that he hopes for a future where University-like dorms would be the norm.

Here are the elements he was looking for
 - he doesn't want to think about eating and food - besides the selection of a walking distance restaurant or menu item
  => no real need for kitchen
 - he doesn't want to have complex accounting, taxes, tax exemption, brokers wills etc
  => he doesn't want to own he would rather rent - without a long term lease..
 - he doesn't want to think about house upkeeping, whether this is fixing plumbing or even the weekly cleaning chores
  => he wants an apartment as opposed to a house, and ideally one whose maintenance is straight forward
  => when you take out major appliances, and leave practically a small studio maintenance becomes much simpler and cleaning more efficient
  => the moment that you eat out storage needs drop significantly
  => the moment that you opt to rent you have less options of customizing less owning things => less storage
 - he wants to have at close proximity with variety of areas that provide silence, views, good food, good coffee, concentration, social interaction, lively-ness.
  => The more tightly you pack people and the more you remove these spaces from the living quarters the more they emerge as shared areas that still provide all the requirements but get better use and are more efficient in their upkeep

After reading the article's first line I think that the future that he (and at least in theory I - since in practice I live the exact opposite suburban life) hopes for is nearer.

Friday, February 15, 2013

Meteorites and nuclear bombs

As I was reading about the meteorite in Russia



I read few things.

  • That it was a rock probably from iron weighing about 10 metric tons
  • That it was flying at 17Km/sec
  • That the energy unleashed was comparable to that of a small nuclear bomb
  • That in spite of earlier reports it was not the near-miss "olympic pool-size, 40-sth meters" bigger meteorite that passed 20-30K kilometers away from the earth
So, again using just memory,  from middle school physics kinetic energy is 1/2 * mass * velocity^2.
That means that 1 kg flying at that speed would have 1/2 * 17^2 about 150.MJoules.
and 10Ton => 1.5TJoules

Now, one thing one can remember is that when we talk about nuclear weapons  we talk in terms of kilotons or megatons. That means kilotons of a conventional equivalent bomb. Now, one thing that I didn't know but I am making from now forward a permanent datum that will not forget is that the formula is practically identical to calories - that I do know!
1 calorie ~ 4200Joules  (actually 1 calorie being the energy needed to raise 1 gram of water 1 celcius is 4.2 Joules, but the calories that everyone is talking about 2000 Calories per day etc, these are really KCals.)
Anyway the point is that 1 gram of TNT bomb is also the same as 4200 Joules
which means that 1 kg => 4MJoules
which means that 1ton => 4GJoules
which means that 1kton => 4TJoules.

If my memory recalls well whenever I hear about nuclear weapons I think I remember kilotons (maybe megatons).  If this meteorite were a 10 metric tons in size, its kinetic energy would be 1.5TJ ie, about 1/3rd of a kiloton bomb- so the "small nuclear weapon" comment seems about right.

What would have been the impact of the olympic pool 2^3 vs 40^3 thats a difference 10^4.
ie the pool-sized meteorite would carry energy (assuming same speed) of 3Megaton instead of .3Kton.

  • Cheliabink Meteorite : .3 kton
  • Small Nuclear bombs : .3 kton
  • Hirosima bomb: 10kton
  • Olympic Pool Near miss meteorite 3Mton
  • Large Nuclear Bombs : 5-10Mton
  • Tunguska event meteorite : 10-15Mtons
  • Surface energy of 2004 tsumani earthquake 25Mton
  • Largest ever nuclears : 50-100Mton
  • Dinosaur extinction meteorite :  100 million megatons of TNT.

Its impressive how big our nuclear weapons are - if I havent done a mistake they are ahead of major natural disaster events... It is also impressive every 10-times up (in terms of diameter), thats obviously 3 orders of magnitude more energy, and from a 2-m diameter cheliabink meteorite, the 20-meter size would have been an tugunska like event (like a mega nuclear bomb somewhere), and a 200 meter sized could have been something that would take humanity decades or more to recover, and a 2K meter event could have brought extinction.

But now the other question, about the olympic pool meteorite :  30000 Kmeters (about 3x the earth's diameters) really seems a tiny distance.  Why isn't it being pulled by the earth's gravity? Can we figure this out by memory?
and the 17Km/sec seems terribly close to my memories of "escape velocity" (11Km/sec? )

Ok geo-synchronous satelites cause .2-.3sec internet delaying => 30-40K kms distance from earth (light speed = 300K km/sec). That gives us measure to compare against without having to remember the hard to remember gravity constant. Ie sth that flies at the same distance as the geo-synchronous satelites would need to be flying faster to escape or less to be captured. And given that the geosynchronous are geosynchronous we can calculate their speed....40M meters from earth's center time 2 time pi is the circumference and 86400 is the period 40K x 2pi / 86 = 1K/pi = 300meter/sec!... (that looks so slow!!)
so clearly 17Km/sec  is too fast to be captured by the earth's gravity... and that also explains why we don't in general capture big stuff flying by... they need to be much closer...

Tuesday, February 12, 2013

The philosophy of nothing and school interviews

I just called my sister to congratulate her for her son's acceptance in a hard to get british school (6th grade kid) and she told me kind of bragging
"good thing I persuaded my son to not use nothing as his school interview discussion topic and use the olive branch thing instead".

I got kind of stuck:
Preparation and topics for 7th grade school interviews? (The school interview part I had already accepted - my son just did his too for a high school) And what is this "nothing thing".
My sister went ahead and explained that her son was fascinated with the philosophy of nothing, big bang, the impossibility and intrinsic logical inconsistencies that the concept of nothing entails and so on.
I was both excited and envious in some ways.
Kids (or at least some kids) can get interested/excited in concepts like that.
And what starts as philosophical debate quickly turns into scientific parallel and research.
I explained her that I spend some time a few years ago concluding that nothing doesn't exist.
And that if you use this as an axiom or  an equivalent axiom the universe always existed (ie is infinite) you end up (using layman's logic) to an alternative universe theory that doesn't have big bangs dark matters or funny forms of energy, where a constant steady inflation counteracts gravity and explains most of the astrophysics  in a way that can be understood by a elementary school kid.


My sister, contrary to most other people instead of debating with me and tell me I am out of my mind, asked me to find time and talk with her son :-).
And she went on explaining the final topic that her son picked. The olive branch. And its inherent contradiction of being chosen by ancient greeks as both the symbol of piece and the symbol of victory. And carried through time from Roman emperors and Pax Romana, the american dove? and Yasser Arafat holding the branch and a gun and saying provocatively "don't make me drop the branch..."... All that prepared by a 6th grader. The interviewer send a card to him a few days later saying "This is first I met a geek that is a greek!".  And told him he was accepted with honors.

Global chatbox for web apps

A friend that is writing a web app, that is getting pretty heavy usage, just fixed an error that was plaguing several users. And he commented in his blog:
I wish I had a global chatbox so as I can tell to all this users why they were getting the error and that the error was fixed.

My first reaction was to tell him to try to look for a site-wide message library. But then he is writing everything in javascript - it would probably make more sense to find something like that as disqus-like plugin.
Also, a site wide message may not be the right approach - a small number of the users encountered the error.. Maybe site-wide-message libraries have mechanisms to define user subsets that the message gets broadcasted to.
Still, a broadcast popup seems to be big of an alert for something that is a notification by nature.
What he really needs is disqus-like message/inbox plugin that allows the user to interact with the system. Possibly tickets/notifications, back and forth threads can be captured/archived there.
Or it may just as well be a more realtime js plugin that offers chat - between the application (owner/it/support) and the user.
Any of the above can be one-to-one (essentially the administrator multi-casting a message in peoples inboxes/chatboxes or a group thing where people can also interact with other users in that group.

The common thread here, is that any web app would benefit from having a "systray" (think of a bottom bar like in facebook) always there whose implementation is not the responsibility of the web app but it brings things that any web app may need. These things above are all kinds of functionality that make sense for any web app. As soon as you have that you have the ability in an out-of-band way add in the "sys tray" of the user functionality that is not in your app - either you (the application owner) by controlling the app-specific part of the systray (through options available to registered web-app administrators in some systray provider web service) or the user by controlling any personalization customization options might exist in the systray provider web service.

Do I feel like an inventor or a discoverer?

A friend at work corrected me when I talked about a new product feature that he did, he came up with.
I had used the phrase "what you discovered made a big difference"
and he corrected me saying "I would use the word invented not discovered".

My first reaction was to not pay attention, but a background thread was forked - there was something that my brain was rejecting.
I tried to understand what I didn't like.

I have never used that word for my own work. Somehow, I always felt that my work is more incremental in nature, whatever may be novel in things that I come up with are really re-trying things that have already been thought, just in different context, or for a different problem. Our textbook memories for inventors have put old fashion inventors at a much higher pedestal. But even those I often reject, as either successful corporation history rewrite/image-making (bell/edison) or just plain "people want to hear a nice story" so the most popular version of a historical record wins - independently of whether it is the most accurate... So what I mean without saying it aloud, I actually reject the old -fashioned inventors as well. I found very interesting the mathematician that solved one of the millenium problems - he rejected the award saying that the award is an insult to every one else that has added the other parts to the proof that he relied on - why the last part is more important ? why he should get 100% of the award and them get nothing?  I liked and admired that attitude.


Friday, February 8, 2013

Should you leave your keys around?

Looking to more ways to outsource work in an online way I recently thought that it would be cool to not have to take your keys to Ace hardware for copies.
And apparently there is a company that does that.
You take a few photos of your key with their iphone app and voila your key comes in the mail a few days later : dittokey.com
DittoKey Logo
The interesting thing is that this idea will force another type of progress.
It will make clear that keys are plaintext passwords that provide access to your most valuable assets : your home, family, car etc.
Anyone can grab a photo of your keys in your keychain and when that becomes part of the plot of a popular movie... people will start looking for better alternatives than the old world keys.

I also found it interesting that the filament used in RepRap etc is sturdy enough that it can be used for key creation as well . Here is a post about it.

What to wear


A friend just mentioned that he got a subscription to bombfell.com . And people in the office realized that they had recently been complementing him for improving his dress style, apparently as a result of the bombfell's "personal consultant's" taste.
I think its pretty cool not having to worry about what to wear. My only fear is whether the increased choice of options in the closet will make it harder and harder to pick what to wear. I have been personally looking for a "subscription" model for identical clothing replacement. Amazon doesn't have subscription for some of the "commodity" clothing items:
I have been always wearing a particular fit of Levis jeans, and my only sport shoe has been an Adidas model that has been around for 30 years. I buy them in batches and when they become too old, I grab a new one from the box - if its the last box I reorder. 
I have a problem with the non-sport shoes - there is now way to find/point to the specific Timberland brand/model I have been wearing even though its practically the same for the last 10+ years. As for shirts, I had big supply of black company logo-ed shirts bought with a coupon from marketing... But unfortunately marketing changed the logo and they are not happy with me any more wearing the old ones...The new ones have no black, and thats too big of a cloth change for me for my winter jeans+black shirt outfit. Socks etc, are being replenished automatically by themselves. (my wife)


Losing weight - something that works

Continuing on a previous blog post about losing weight (ignoring the fact that it shows that I am actually more obsessed about it than what I want to think).

I think I found a method that I can reliably lose as much weight as I want.
As always losing weight has nothing to do with "diets" and chosing what food to eat.
It has to do with giving tools to the left side of your brain, your planner, to win more battles
against the right side of your brain, your reactor. So, I think I have found the right toolset.

The key is to understand that even though there are times where the reactor would win,
the important thing is to show to the planner that it is the dominant guy in a provable (to him) way and the occasional battle defeats  do not represent actual change of who is the dominant but pre-planned strategic pull backs.

Ok the theory may sound fuzzy - the methodology is very clear.
All you need is a spreadsheet.

You create a planned reduction of weight at your prefered pace. I put it at 1lb per week. Why 1lb?
- Because since my college years I added about a pound every year and climbed from 150s in my early twenties to almost 180 in my late fourties!..
- Because 1lb a week, given my sedentary lifestyle - 2K calories a day use, ie 0.5lb of fat per day use, is 3.5lbs of fat a week which means 1/3.5 reduction, ie approximately eating 1200 calories instead of 2K.  Signicant food reduction but still something that I can do in a long term, as opposed more starvation style diets. By the way not eating for a day kills 0.5lb of fat-equivalent (physics) while eating a good 4K meal a day doesn't add 1lb of fat-equivalent - human digestive systems aren't as perfectly-efficient - they can't convert 100% of the energy content of the food as you eat more and more...
Ok back to the methodology.
You pick a morning that you really would't want to see yourself on the scale. One of those days. And you weigh yourself.
You put that day down and that weight down in the spreadsheet.
You add 20 rows below with date=date+7 and weight = weight - 1. They represent your milestone goals as well as the only  history of what happens.
The first weeks goals the weight seems still something you wouldn't be proud of.
A few weeks/rows further down the weight loooks like your old diet goals
20 weeks down your weight looks like you don't even dream of. Its your weight 20 years ago. When you were young. Young and light.

So what is the trick?
You play the following game.
To make your goal for a particular date, all you need to beat that goal any of the prior 7 days, ie if my next date goal is 2/10/2013,  160lbs all I have to do is be below 160lbs between 2/3/2013 and 2/10/2013.
As soon as that happens you can proudly replace the formula "goal", with the real number.
Then you have a few days to celebrate. You actually have more than a week before the prospect of the new deadline weight appraches.

This is how mine looks so far:




I started the "method" right after new years - at what is typically my annual peak.
I have here the complete download of weight history from my old google health account.
(its probably a uniquely identifying fingerprint.... should I worry about that? nope)
The 6 bold readings (6 last dots in the chart) are the ones from the methodology - I mean they have actually happen. They appear perfectly spaced because in some way they are fabricated. I post them at week intervals even though each may have happened a few days before, or they may even lower in reality.
But I am ok with that conservative history rewrite. My planner is. The future #s are obviously just goals/formulas.



Again, the reason that this works is that often context, environment, emotional state, a dinner with friends, someone making your favorite food, make the "reactor" strong - impossible to beat that day.
But the planner has control most of the time and all it has to do to win the game is find a time when the reactor is weak, take advantage of a "good" day or two and obtain the proper reading.
The more wins are accumulated the reactor becomes more defeatist the planner more confident.
My planner is already sure (under the illusion?) that this really works! He is writing a blog post about it for crying out loud!. And in reality the game is "setup" the first weeks are very easy - very easy for the planner to win - normal weight flunctuates several pounds based on when eating , drinking etc..
The more you go into the game the harder it gets but the planner has already developed a winner's attitude/confidence. And the planner does have dirty tricks to play. I know that worst case I can starve for 24-36 hour prior to the deadline and the resulting liquid reduction can create an low to save me.  (for  me 24 hrs with no food brings me down ~4lbs, the next day a couple more.)

So it works. I am absolutely sure about it.

Coughs


Its hard to focus when you hear your kid having a nasty cough through the night - second night in a row.

I am trying to see if it gets better or worse - sometime it sounds worse - should I do something? What? More syrop? Many times I long having a grandpa, grandma in the house with home remedies and a calming/soothing having seen it all voice.

Maybe I should keep a log of the coughs as I hear them from the living room

12:31
12:32
12:32
12:39
12:40
12:40
12:41
12:43
12:45

They do seem to come in groups.  Now silence!  Could it be she managed to fall asleep?


Sunday, February 3, 2013

Superbowl and Nobel laureates

I realized yesterday (from all the cars that were having these plastic flags in their car windows) that a bay area team was again in the finals. I thought that this just happen a few months ago.
I have been embarrassing myself when talking with friends by confusing the two teams 49ers and Giants but if I recall correctly the Giants were in their own final a few months ago.
I guess it is cool to be in the bay area then if you are a sports fun.
For that matter my soccer-playing kid was telling me that the soccer team of san jose was in (final?) playoffs with Galaxy the LA team. And even though hockey has been on strike for a year (I knew that) Sharks seem to be doing pretty well lately as well. I guess in every single sport bay area is rising to the top!. And wasn't it a month ago that someone made fun of me when Stanford beat my own college team in Roseball?

A: All this seems to be more than a coincidence.
B: Of course if you look for patterns you can always find ones.

A: But look at that:
The crown of the largest company by market cap moved to the Bay Area due to Apple.
It was before in Texas (XOM), Connecticut (GE), Seattle (MSFT)  (I confirmed the locations from wikipedia the top cap companies by memory)
Big Money => Big Sponsors => Stronger teams.

I still have in my todos to create a treemap of the public companies by location, something that would put some more clear evidence in my feeling that the $1T of value between decade-old companies like Apple, Google, Ebay, Yahoo, Facebook, Linkedin, Netflix, Workday, Salesforce, Netsuite, Groupon, Zynga,  (I follow these), while the massive decline of east coast Financial companies or anywhere else Telecom companies must be creating a various obvious trend/pattern.

The bay area, and with that I mean, innovation and startups is becoming the primary economic muscle of the global economy.  (I made a leap from America and the rest of the world - but anyone that finds US beating in technological innovation the rest of the world they should attempt the same comparison taking out of the equation the bay area. I don't think that US is winning. The Bay Area model is wining. And in that sense, any place that is creating a similar environment could very well "beat" the older world.
(For the record (and this may sound counter intuitive , I am always upset/offended when I talk to Bay Area folks that have the arrogance/illusion that they have a defacto monopoly in innovation by being in the bay area but thats another post )

So what about the Nobel laureate mentioned in the title?
A few weeks we heard about a Nobel Laureate leaving Harvard to join Stanford and we contemplated what is the ideal place for a future Nobel Laureate to do their research - the east coast Harvard? or the bay area Stanford. The answer was that several of the interesting new trends are happening here and are studied here. Stanford has already people excited about them - Harvard becomes aware of them after the fact.

So Stanford has a key advantage.

Moving from SQL to R

I wanted to get to see the distribution of dataset, something that would show whether there is something abnormal in one of my datasets.
I decided to use R for that.
I have already R installed in my mac - using more like a scientific calculator than anything else.

First question getting the data into R. I found some examples that show how to do that from csv files but I decided that it would be better to be able to run the queries right from R.

Apparently R doesn't have any builtin support for databases so you need to install additional packages for that.
After following a few wrong posts, I found that there is already a CRAN (like CPAN) with all the R packages, where I found the name of the postgreSQL one.
Trying install it gave me dependency errors. I couldn't find some way to ask R to install anything that it needs recursively. Here is the resulted manual list:


----Adding  DB Drivers
Add MySQL, Postgres drivers
> r
install.packages("rJava")
install.packages("RJDBC")
exit
> R CMD javareconf

> r
install.packages("RMySQL")
install.packages("RPostgreSQL")

I had to exit and run the javareconf command - otherwise it wouldn't work. Still after that 30 minute exercise I had both postgres and mysql drivers.

library('RPostgreSQL')
drv <- dbDriver('PostgreSQL')
db <- dbConnect(drv, host='some_host', user='some_user', dbname='some_db', port='some_port')
dat <- dbGetQuery(db, 'select 1')

The next problem I faced was that my queries are pretty long 20-30 lines of sql code full of quotes and double quotes. What is the simplest  way to paste a 30 line text in R. I couldn't find any quoting mechanism for long literals like """ for python. The only way I saw was a method for inline standard input with scan(). However, this has the unfortunate side-effect of adding every single individual line of the standard input as part of your command history.  So I ended up deciding that the most normal way would be to use a standard "scratchpad" file where I paste the queries and I read  and execute:

s <- paste(scan('~/Dropbox/Home/tmp_query.sql', sep = "\n", what = "character"), collapse = " ")
dat <- dbGetQuery(db, s)

Ok, at last I have the data in R. The data are lots of row, where each row has a numeric column that I want to see the distribution of. Something that I expect to look like a bell-shaped curve. 

The first problem is that the query brought more columns than needed and the result is actually having 4 data sets in it denoted by a column whose values are CELL_A,..CELL_D for the four datasets (its the result of a group by). I can start doing all the filtering/selection in SQL but it would be nicer if I learn how to do this in R.
It seems that there isn't any best way of doing it.
I tried first matrix manipulation option:
dat[dat$cell in ('CELL_B') & dat$total_charge > 0, ]


but that results in lots of NAs and removing them makes the expression even noisier:

dat[dat$cell %in% ('CELL_B') & dat$total_charge > 0 &!is.na(dat$total_charge), ]

Using the subset operator creates a more compact expression:

subset(dat, total_charge>0 & cell == 'CELL_B')

and after that picking the right columns seems very natural:

subset(dat, total_charge>0 & cell == 'CELL_B')[,c('total_charge')]

So, at last we have a single vector with all the right values. The next step is to create the chart.

Lets just try hist on it:
> hist(subset(dat, total_charge>0 & cell == 'CELL_B')[,c('total_charge')])


maybe applying a log function on the data before plotting them would make them look better:
> hist(log(subset(dat, total_charge>0 & cell == 'CELL_B')[,c('total_charge')]))


Better!.
After playing with a few of the parameters I got what I was looking for:
> hist(log(subset(dat, total_charge>0 & cell == 'CELL_B')[,c('total_charge')]), xlim=c(0,10),ylim=c(0,14),breaks=100)


Unfortunately, it is still rather discrete. And I would like to be able to place it against the 'Control' data set



Looking at the dataset doesn't give me a clue for what I was looking for. Besides a stronger intuition that the CELL_B dataset is too small to allow meaningful eye-balling understanding.

Need to read more.