Pages

Monday, April 16, 2012

Redis

Not a mainstream database, its syntax reminds me of old console programs. Nothing superfluous, only the command, and arguments separated by spaces.

Though it's pronounced RED-iss, I like calling it ruh-DISS.

Unfortunately I haven't found many resources. Here's one:

http://rediscookbook.org/

Thursday, April 12, 2012

Android SDK

So far I'm not impressed. Eclipse is unresponsive, and the default installation lacks a file needed for virtual device creation. And installing anything is slow as molasses.

http://www.vogella.com/articles/Android/article.html


Thursday, March 15, 2012

stealth35 saves the day

After some poking around I found that in PHP 5.4, arrays can be written like this:
$array = [
    
"foo" => "bar",
    
"bar" => "foo"];
and I tried finding a WAMP supporting PHP 5.4, which led to discovering this PHP version was released in early March.

I "updated" Ampps by replacing its PHP folder with an unzipped 5.4 folder. Other than a few warnings, it worked.

Then, the MongoDB driver refused to work. From Stack Overflow, I found a link to stealth35's compiled driver dll. Now, everything works!
Right now, I'm not liking the PHP driver for MongoDB. Take a look at this example from http://www.php.net/manual/en/mongo.updates.php:

<?php/** suppose documents look like:
 * {"username" : "...", "password" : "...", "email" : "..."}
 *
/
$coll-> update(array("username" => "joe"), array("userId" => 12345
"info" => array("name" => "joe""twitter" => "@joe4153""email" => "..."),
"likes" => array()));

array(" I " => "want my JavaScript back")

Wednesday, March 14, 2012

mongo command line shell

> show dbs
Lists existing databases

> use [database-name]
Changes database. By default, test is opened.

> db.[collection-name].find()
Displays the collection's documents

Tuesday, March 13, 2012

Ajax jQuery style


I am trying out the comma-first style for my objects. I got errors many times when I added a new pair to an object list because I didn't add a comma to the last pair.


Although curl gives a more informative message, I cannot get the same information out of statusCode 412.


<html>
<head>
<script type="text/javascript" src="jquerymin.js"></script>
<script type="text/javascript">
  function initialize() {
    $.ajax({
      type: "PUT"
    , url: "http://127.0.0.1/couchdb/albums"
    , success: function(data) {
        alert(data);
      }
    
    , statusCode: {
        412: function(jqXHR, textStatus, errorThrown) {
          alert(textStatus);
        }
      }
    });
  }
</script>
</head>
<body onload="initialize()">


</body>
</html>

Simple CouchDB actions with Ajax

With rozky's most useful answer on how to make an Ajax script communicate with your CouchDB server,


  • configure Apache (apache_home/conf/httpd.conf)
    • uncomment LoadModule proxy_module modules/mod_proxy.so
    • uncomment LoadModule proxy_http_module modules/mod_proxy_http.so
    • add ProxyPass /couchdb http://127.0.0.1:5984 (as top level property like ServerAdmin)
    • restart Apache
  • modify index.html
    • replace http.open('GET', 'http://127.0.0.1:5984/_all_dbs', true); with http.open('GET', '/couchdb/_all_dbs', true);

I can execute some simple database commands as described in the Definitive Guide, replacing curl with some JavaScript code:

<html>
<head>
<script type="text/javascript">
  function initialize() {
    request=new XMLHttpRequest();
    request.open('GET','http://127.0.0.1/couchdb/_all_dbs',true);
    request.send(null);
    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        if (request.status == 200) {
          alert(request.responseText);
        }
      }
    };
  }
</script>
</head>
<body onload="initialize()">
</body>
</html>