Tuesday, April 29, 2014

Postgres on Windows...

Yeah, why did I do this to myself? Well, I'm usually on a Mac, but Apple is dumb in that it doesn't support JEE6, which is what I used to write the sign-out app.

So, I needed to get the database onto the Windows machine where I wrote the sign-out app in JEE6.
So, I downloaded Postgres in a one-click exe file. Then it took me forever how to inflate a database from a pg_dump.

Well, after about 30 minutes of tinkering, here's how

how to run it from command line:

"\Program Files\PostgreSQL\9.3\bin\psql.exe" -U postgres ...



http://www.postgresql.org/docs/8.1/static/backup.html#BACKUP-DUMP-RESTORE

23.1.1. Restoring the dump

The text files created by pg_dump are intended to be read in by the psql program. The general command form to restore a dump is
psql dbname < infile
where infile is what you used as outfile for the pg_dump command. The database dbname will not be created by this command, you must create it yourself from template0 before executing psql (e.g., with createdb -T template0 dbname). psql supports options similar to pg_dump for controlling the database server location and the user name. See psql's reference page for more information.

Thursday, April 10, 2014

Using Sencha CMD 4.0.2 Architecture for ST2

So you have a ST2 project that's all big and uncompiled, and you want to minify it with CMD and even port it to XCode.

Here's how.

You should already have an MVC architecture, with models, views, and controllers separated into separate folders.

Get Sencha CMD4 and perform
sencha -sdk /path/to/sdk generate app AppName /app/folder/

If everything's working, cmd should create an app under /app/folder with a ton of goodies in it.
Check out it's folder structure and stuff. To change themes, access the hidden .sencha folder.

Just for satisfaction, run
sencha app build

There should now be a build folder in your project directory. Go look inside and find the minified code. Hooray!
Now, simply migrate your MVC code into the /app folder generated by cmd.
Run the app build command again. Given your code is structured correctly, and you have made all the proper changes to the app.js file, everything should work.

You now have a minified js and css file! Awesome!

For the phonegap component: check out this website http://www.sencha.com/blog/getting-started-with-sencha-touch-2-build-a-weather-utility-app-part-3
For the tl;dr version, do
sencha app build production 
sencha phonegap init <APP-ID> <APP-NAME>

Now, you should have a phonegap folder, and config.xml file. Check out the config.xml and read it, and make all the obvious changes that you need to make.

Finally, run a
sencha app build native

You should find the /phonegap/platforms/ios folder, inside of which will be an xcode project.

Please comment if you have questions!

Wednesday, April 2, 2014

Mavericks update woes continue.

Now, in Python, the up arrow key give me the previous command in the interactive session.

This is crap.

Here is a link to the solution. You need to recompile Python...
http://stackoverflow.com/questions/893053/python-shell-arrow-keys-do-not-work-on-remote-machine

Updating to OSX mavericks...

Mavericks is pretty horrible... meh.

For one, everything is now slower. Just to get XCode5 dev tools and multiple tabs in the finder, this is not really worth it.

On another note, I continually got this error in Python.

>>> import networkx as nx
>>> nx.Graph()

Segmentation fault: 11

This is ridiculous. Why would they break python?

I found the fix. 


Pretty much, do this stuff. Who knows what it does? It works.

cd /Library/Frameworks/Python.framework/Versions/3.3
cd ./lib/python3.3/lib-dynload 
sudo mv readline.so readline.so.disabled

Sunday, March 23, 2014

ooph... getting owned by asynchronicity...

You thought I would have learned how asynchronous stuff works after claiming to be a javascript fan.

Well, I guess I haven't tried putting callbacks inside javascript for loops... **it doesn't work**!!


Here is a nice post on how to do it.
http://www.richardrodger.com/2011/04/21/node-js-how-to-write-a-for-loop-with-callbacks/#.Uy9m1uddXWN

What you need to do is

var array = [...];
repeater(i){
    if(i < array.length){
        asynch(array[i], function(){
            //do your stuff here...
            repeater(i++);
        }
    }
}
repeater(0);

Pretty tricky indeed!

Sunday, March 9, 2014

Hot Code Loading in Node.js




Source: http://romeda.org/blog/2010/01/hot-code-loading-in-nodejs.html




Reading through Fever today, this post by Jack Moffitt caught my eye. In it, he discusses a hack to allow a running Python process to dynamically reload code. While the hack itself, shall we say, lacks subtlety, Jack's post got me thinking. It's true, Erlang's hot code loading is a great feature, enabling Erlang's 99.9999999% uptime claims. It occurred to me that it wouldn't be terribly difficult to implement for node.js' CommonJS-based module loader.
A few hours (and a tasty home-made Paella later), here's my answer: Hotload node branch.

Umm… What does it do?

var requestHandler = require('./myRequestHandler');

process.watchFile('./myRequestHandler', function () {
  module.unCacheModule('./myRequestHandler');
  requestHandler = require('./myRequestHandler');
}

var reqHandlerClosure = function (req, res) {
  requestHandler.handle(req, res);
}

http.createServer(reqHandlerClosure).listen(8000);
Now, any time you modify myRequestHandler.js, the above code will notice and replace the local requestHandler with the new code. Any existing requests will continue to use the old code, while any new incoming requests will use the new code. All without shutting down the server, bouncing any requests, prematurely killing any requests, or even relying on an intelligent load balancer.

Awesome! How does it work?

Basically, all node modules are created as sandboxes, so that as long as you don't use global variables, you can be sure that any modules you write won't stomp on others' code, and vice versa, you can be sure that others' modules won't stomp on your code.
Modules are loaded by require()ing them and assigning the return to a local variable, like so:
var http = require('http');
The important insight is that the return value of require() is a self-contained closure. There's no reason it has to be the same each time. Essentially, require(file) says "read file, seal it in a protective case, and return that protective case." require() is smart, though, and caches modules so that multiple attempts torequire() the same module don't waste time (synchronously) reading from disk. Those caches don't get invalidated, though, and even though we can detect when files change, we can't just call require() again, since the cached version takes precedence.
There are a few ways to fix this, but the subtleties rapidly complicate matters. If the ultimate goal is to allow an already-executing module (e.g., an http request handler) to continue executing while new code is loaded, then automatic code reloading is out, since changing one module will change them all. In the approach I've taken here, I tried to achieve two goals:
  1. Make minimal changes to the existing node.js require() logic.
  2. Ensure that any require() calls within an already-loaded module will return functions corresponding to the pre-hot load version of the code.
The latter goal is important because a module expects a specific set of behaviour from the modules on which it depends. Hot loading only works so long as modules have a consistent view of the world.
To accomplish these goals, all I've done is move the module cache from a global one into the module itself. Reloading is minimised by copying parent's caches into child modules (made fast and efficient thanks to V8's approach to variable handling). Any module can load a new version of any loaded modules by first removing that module from its local cache. This doesn't affect any other modules (including dependent modules), but will ensure that any sub-modules are reloaded, as long as they're not in the parent's cache.
By taking a relatively conservative approach to module reloading, I believe this is a flexible and powerful approach to hot code reloading. Most server applications have a strongly hierarchical code structure; as long as code reloading is done at the top-level, before many modules have been required, it can be done simply and efficiently.
While I hope this patch or a modified one will make it into node.js, this approach can be adapted to exist outside of node's core, at the expense of maintaining two require() implementations.