Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mongo-db opplegg.

  • Loading branch information...
commit fe693f584f73ed5cf5b8360dfc3d97aacaf92181 1 parent 822ad21
Andreas Heim authored
Showing with 29,580 additions and 28 deletions.
  1. +34 −19 index.js
  2. +29,470 −0 lib/zips.json
  3. +35 −0 public/index.html
  4. +41 −9 public/lib/pres.js
53 index.js
View
@@ -1,7 +1,3 @@
-/**
- * term.js
- * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
- */
var http = require('http')
, express = require('express')
@@ -10,23 +6,17 @@ var http = require('http')
, terminal = require('term.js')
, redis = require('redis');
-/**
- * term.js
- */
process.title = 'term.js';
/**
- * Dump
- */
-
-
-/**
* Open Terminal
*/
-var buff = []
+var redis_buff = []
+ , mongo_buff = []
, socket
+ , mongo_term
, redis_term;
//term = pty.fork(process.env.SHELL || 'sh', [], {
@@ -40,16 +30,35 @@ redis_term = pty.fork("redis-cli" || 'sh', [], {
});
redis_term.on('data', function(data) {
-
return !socket
- ? buff.push(data)
+ ? redis_buff.push(data)
: socket.emit('redis-term', data);
});
+
+mongo_term = pty.fork("mongo" || 'sh', [], {
+ name: require('fs').existsSync('/usr/share/terminfo/x/xterm-256color')
+ ? 'xterm-256color'
+ : 'xterm',
+ cols: 80,
+ rows: 24,
+ cwd: process.env.HOME
+});
+
+mongo_term.on('data', function(data) {
+ return !socket
+ ? mongo_buff.push(data)
+ : socket.emit('mongo-term', data);
+});
+
+console.log(''
+ + 'Created redis-term with pty master/slave'
+ + ' pair (master: %d, pid: %d)',
+ redis_term.fd, redis_term.pid);
console.log(''
- + 'Created shell with pty master/slave'
+ + 'Created mongo-term with pty master/slave'
+ ' pair (master: %d, pid: %d)',
- redis_term.fd, redis_term.pid);
+ mongo_term.fd, mongo_term.pid);
/**
* App & Server
@@ -119,13 +128,19 @@ io.sockets.on('connection', function(sock) {
redis_term.write(data);
});
+ socket.on('mongo-term', function(data) {
+ mongo_term.write(data);
+ });
socket.on('disconnect', function() {
// redisClient.unsubscribe();
socket = null;
});
- while (buff.length) {
- socket.emit('redis-term', buff.shift());
+ while (mongo_buff.length) {
+ socket.emit('mongo-term', mongo_buff.shift());
+ }
+ while (redis_buff.length) {
+ socket.emit('redis-term', redis_buff.shift());
}
});
29,470 lib/zips.json
View
29,470 additions, 0 deletions not shown
35 public/index.html
View
@@ -600,6 +600,41 @@
- Gå igjennom store mengder data og hente ut og bearbeide enkelte eller flere felter
- Eksempel:
- Nettbutikk: Hente ut en sortert liste over de produktkategoriene som flest produkter blir kjøpt i.
+ - Sosialt nettverk: Hvor mange nye medlemmer får vi pr. måned?
+
+---
+name: mongo-term
+class: cols two
+# <span>MongoDB</span>
+
+<div id="mongo-term"></div>
+<div style="clear: both"></div>
+
+
+<div class="col">
+ <h3><span>Query</span></h3>
+ <a href="#" class="mongo-cmd">db.zips.findOne()</a><br />
+ <a href="#" class="mongo-cmd">db.zips.find({state: "AL"})</a><br />
+ <a href="#" class="mongo-cmd">db.zips.find({state: "AL"}).count()</a><br />
+ <a href="#" class="mongo-cmd">db.zips.find({state: "AL" , pop: {$gt: 10000}}).count()</a><br />
+ <br />
+ <br />
+ <br />
+ <br />
+ <br />
+ <a href="#" class='pushed' id="resume">Resume</a>
+</div>
+<div class="col">
+ <h3><span>Aggregation</span></h3>
+ <pre>
+ <a href="#" class="mongo-cmd">
+db.zips.aggregate(
+{ $group :
+ { _id : "$state",
+ totalPop : { $sum : "$pop" } } },
+ { $match : {totalPop : { $gte : 10000000 } } } )</a><br />
+ </pre>
+</div>
---
name: Redis
50 public/lib/pres.js
View
@@ -1,7 +1,7 @@
var slideshow = remark.create({highlightStyle: "solarized"});
slideshow.on('showSlide', function(slide) {
- if(slide.properties.name == "redis-term") {
+ if(slide.properties.name == "redis-term" || slide.properties.name == "mongo-term") {
slideshow.pause();
}
});
@@ -11,9 +11,6 @@ document.getElementById('resume').onclick = function (e) {
e.preventDefault();
};
-var processed = [];
-
-
window.onload = function() {
var socket = io.connect();
@@ -25,8 +22,20 @@ window.onload = function() {
socket.emit('redis-term', command + "\r");
e.preventDefault();
});
+ $('.mongo-cmd').click(function (e) {
+ var command = $(e.target).text();
+ console.log(command);
+ //redis_term.write(command);
+ socket.emit('mongo-term', command + "\r");
+ e.preventDefault();
+ });
socket.on('connect', function() {
+ /*
+ *
+ * Redis term
+ *
+ */
var redis_term = new Terminal({
cols: 80,
rows: 20,
@@ -38,21 +47,44 @@ window.onload = function() {
socket.emit('redis-term', data);
});
+ socket.on('redis-term', function(data) {
+ redis_term.write(data);
+ });
redis_term.open(document.getElementById('redis-term'));
+ /* Redis-websocket */
+ socket.on('redis', function(data) {
+ $("#redis-list").append('<li>' + data + '</li>');
+ });
- socket.on('redis-term', function(data) {
- redis_term.write(data);
+ /*
+ * Mongo-term
+ */
+ var mongo_term = new Terminal({
+ cols: 80,
+ rows: 20,
+ useStyle: true,
+ screenKeys: true
+ });
+
+ mongo_term.on('data', function(data) {
+ socket.emit('mongo-term', data);
+ });
+
+
+ mongo_term.open(document.getElementById('mongo-term'));
+
+ socket.on('mongo-term', function(data) {
+ mongo_term.write(data);
});
+ /* drep alt ved disconnect */
socket.on('disconnect', function() {
+ mongo_term.destroy();
redis_term.destroy();
});
});
- socket.on('redis', function(data) {
- $("#redis-list").append('<li>' + data + '</li>');
- });
};
Please sign in to comment.
Something went wrong with that request. Please try again.