Sunday, October 20, 2013

Javascript techniques


Module pattern

function Answer(questionID, text) {
    this.questionID = questionID;
    this.text = text;
}

Working with arrays

var list1 = Array();
list1.push(currSec);


jQuery Append to element
$('#addLink').append('<B>test</B>');


Opener
http://www.webreference.com/js/tutorial1/opener.html

Thursday, October 17, 2013

Together Native and Html5

Peter Traeg of Universal Mind has written an article at Smashing Magazine about mixing together Native and Html5 .
Exposing a portion of the user experience through HTML and JavaScript means that some of the experience can be served from the Web and thus be dynamic. As we saw earlier, it’s possible for this Web-served content to invoke native code in your application via a “bridge” that you create.
Apple allows JavaScript code to be downloaded and executed as long as it runs within the context of the UIWebView control in your iOS application. This is the only situation in which code “downloading” is allowed in iOS.
The UIWebView in iOS and its associated UIWebViewDelegate provide the mechanism that allows native code and JavaScript to communicate with each other.

https://github.com/ptraeg/html5-in-mobile-apps

Tuesday, October 15, 2013

Responsive Web Bootcamp with Jonathan Stark


JSConf: Douglas Crockford


Learn It on Web

Now a days there are so many ways to learn things on the web. Over the past year or so I have found a few site to help me improve my skills. Most of these are free resources but not all. This will be a dynamic list and will be updated periodically ...

Saturday, October 12, 2013

MongoDB Week 1

I started the MongoDB for Java developer course this week.

The lead developer of the java driver Jeff Yemin along with Andrew Erlichson are the instructors.


Non relational algebra

Json store

Json documents - collection of documents


Key values



Mongoshell - tcpconnects to mongodb

Sparq java - routes to urls
Freemarker mvc









Copy files in bin dir to c:\mongodb226

Make data dir under c drive, Under data mkdir db

Go to bin dir

c:\mongodb226>mongod
mongod --help for help and startup options
Tue Oct 08 22:44:36 [initandlisten] MongoDB starting : pid=1696 port=27017 dbpath=\data\db
\ 64-bit host=CSGRALLT10
Tue Oct 08 22:44:36 [initandlisten] db version v2.2.6, pdfile version 4.5


c:\mongodb226>mongo
MongoDB shell version: 2.2.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
> 

Or
mongo localhost

> db
test


      
> show collections
> db.mycollections.insert({text:'hello world'})
> show collections
mycollections
system.indexes
> db.mycollections.find()
{ "_id" : ObjectId("5254c64c2488183e2c3d49f8"), "text" : "hello world" }
> 



c:\>cd data

c:\data>cd db

c:\data\db>dir
 Volume in drive C is Windows
 Volume Serial Number is 1CEC-CA9A

 Directory of c:\data\db

10/08/2013  10:58 PM    <DIR>          .
10/08/2013  10:58 PM    <DIR>          ..
10/08/2013  10:58 PM    <DIR>          journal
10/08/2013  10:50 PM                 6 mongod.lock
10/08/2013  10:58 PM        67,108,864 test.0
10/08/2013  10:58 PM       134,217,728 test.1
10/08/2013  10:58 PM        16,777,216 test.ns
10/08/2013  10:58 PM    <DIR>          _tmp
               4 File(s)    218,103,814 bytes
               4 Dir(s)  49,962,684,416 bytes free





> mvn archetype:generate

enter 308 at prompt
    308: remote -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which
ven project.)



              308

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 308:
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1

Choose a number: 6: 6
 mvn compile exec:java -Dexec.mainClass="org.mongodb.App"



           <dependency>
              <groupId>org.mongodb</groupId>
              <artifactId>mongo-java-driver</artifactId>
               <version>2.10.1</version>
            </dependency>
import com.mongodb.DB; 
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

public class HelloMongoDB {

public static void main( String[] args ) throws UnknownHostException
{
MongoClient mongoStyleClient = new MongoClient(new ServerAddress("localhost", 27017));
           DB db = mongoStyleClient.getDB("test");
           System.out.println( "Hello World!" );
  DBCollection coll = db.getCollection("mycollections");
  DBObject document1 = coll.findOne();
  System.out.println(document1); }
}}
 Hello World!
{ "_id" : { "$oid" : "5254c64c2488183e2c3d49f8"} , "text" : "hello world"}

Spark Web Application Framework

http://www.sparkjava.com/

<repositories>
      <repository>
          <id>Spark repository</id>
          <url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
      </repository>
  </repositories>


<dependency>
      <groupId>spark</groupId>
      <artifactId>spark</artifactId>
      <version>0.9.9.4-SNAPSHOT</version>
     </dependency>


import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;


public class HelloWorldSparkStyle {

public static void main( String[] args )
    {
   
      //http://localhost:4567/
        Spark.get(new Route("/") {

@Override
public Object handle(Request arg0, Response arg1) {

return "Hello Spark World!";
}
});
     
    }

}

Hello Spark World!

Template library
http://freemarker.org/

.ftl files combined with data map


      <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>2.3.19</version>
     </dependency>



Spark - Http Get , Http Post


Freemarker looping




Freemarker ...

Spark.post(new Route("/favorite_fruit")

Schemaless Mongodb example (can add columns on fly)

json - arrrays, dictionaries (associated maps)




MongoPosts

16meg limit on document