ultimate node.js countdown - doag deutsche oracle ... · oracle-db https grunt socket.io ......
TRANSCRIPT
Ultimate Node.js countdown
Alan Arentsen
the coolest APEX examples
http://10.30.4.108
please logon to:
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run across distributed devices.
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run across distributed devices.
http websocket
rest
oracle-db
https
grunt
socket.io
python uglify-js
soap-q
gulp
mysql
filbert
moment
q-superagent
async jshint
browserify
stylus
cheerio hapi
less
forever
chalk redis
underscore
mocha
sails
mongoose
commander
express
connect
nodemailer
mongodb-q mkdir
bower
awesome passport
optimist lodash
colors
q jade
validator
dropbox
window.WebSocket = window.WebSocket || window.MozWebSocket;
if (!window.WebSocket) {
console.log('There is no websocket API available.');
}
} else if (typeof(ws_connection) !== 'undefined') {
console.log('There is a websocket live connection.');
}
else {
ws_connection = new WebSocket('ws://192.168.56.12:4880/&APP_USER.‘
,'echo-protocol');
ws_connection.onmessage = function(message) {
}
}
function reportrefresh_Callback(staticID) {
$('#' + staticID).trigger('apexrefresh');
};
var intervalID = window.setInterval(reportrefresh_Callback('EMP'), 5000);
function reportrefresh_Callback(staticID) {
$('#' + staticID).trigger('apexrefresh');
};
var intervalID = window.setInterval(reportrefresh_Callback('EMP'), 5000);
Event: Custom
Custom Event: refresh_emp
Selection Type: JavaScript Expression
Javascript Expression: document
declare
v_id number;
begin
begin
select usr.id
into v_id
from unc_users usr
where usr.username <> 'ADMIN'
and usr.userkey is not null
and usr.selfie is not null
order by dbms_random.value;
exception
when no_data_found
then v_id := null;
end;
apex_util.set_session_state('P6_RANDOM_ID', v_id);
end;
declare
v_id number;
begin
begin
select usr.id
into v_id
from unc_users usr
where usr.username <> 'ADMIN' and usr.userkey is not null
and usr.selfie is not null
order by dbms_random.value;
exception
when no_data_found
then v_id := null;
end;
apex_util.set_session_state('P6_RANDOM_ID', v_id);
end;
oracle = function() {
this.oracledb = require("oracledb");
};
oracle.prototype.insertUser = function(p_username, p_remoteaddress, p_userkey) {
this.oracledb.getConnection({
user: this.db_user,
password: this.db_password,
connectString: this.db_connectionstring
},
function(err, connection) {
//put your code to handle the callback here
});
};
oracle = function() {
this.oracledb = require("oracledb");
};
oracle.prototype.insertUser = function(p_username, p_remoteaddress, p_userkey) {
this.oracledb.getConnection({
user: this.db_user,
password: this.db_password,
connectString: this.db_connectionstring
},
function(err, connection) {
//put your code to handle the callback here
});
};
oracle = function() {
this.oracledb = require("oracledb");
};
oracle.prototype.insertUser = function(p_username, p_remoteaddress, p_userkey) {
this.oracledb.getConnection({
user: this.db_user,
password: this.db_password,
connectString: this.db_connectionstring
},
function(err, connection) {
//put your code to handle the callback here
});
};
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.action = "insertUser";
connection.module = process.title;
var sqlstatement = "merge into unc_users usr \
using (select :username username \
,:remoteaddress remoteaddress \
,:userkey userkey \
from dual) usr1 \
on (usr.username = usr1.username) \
when matched then \
update set usr.userkey = usr1.userkey \
when not matched then \
insert (username, remoteaddress, userkey)
values (usr1.username, usr1.remoteaddress, usr1.userkey)";
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.action = "insertUser";
connection.module = process.title;
var sqlstatement = "merge into unc_users usr \
using (select :username username \
,:remoteaddress remoteaddress \
,:userkey userkey \
from dual) usr1 \
on (usr.username = usr1.username) \
when matched then \
update set usr.userkey = usr1.userkey \
when not matched then \
insert (username, remoteaddress, userkey)
values (usr1.username, usr1.remoteaddress, usr1.userkey)";
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.action = "insertUser";
connection.module = process.title;
var sqlstatement = "merge into unc_users usr \
using (select :username username \
,:remoteaddress remoteaddress \
,:userkey userkey \
from dual) usr1 \
on (usr.username = usr1.username) \
when matched then \
update set usr.userkey = usr1.userkey \
when not matched then \
insert (username, remoteaddress, userkey)
values (usr1.username, usr1.remoteaddress, usr1.userkey)";
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.action = "insertUser";
connection.module = process.title;
var sqlstatement = "merge into unc_users usr \
using (select :username username \
,:remoteaddress remoteaddress \
,:userkey userkey \
from dual) usr1 \
on (usr.username = usr1.username) \
when matched then \
update set usr.userkey = usr1.userkey \
when not matched then \
insert (username, remoteaddress, userkey)
values (usr1.username, usr1.remoteaddress, usr1.userkey)";
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.action = "insertUser";
connection.module = process.title;
var sqlstatement = "merge into unc_users usr \
using (select :username username \
,:remoteaddress remoteaddress \
,:userkey userkey \
from dual) usr1 \
on (usr.username = usr1.username) \
when matched then \
update set usr.userkey = usr1.userkey \
when not matched then \
insert (username, remoteaddress, userkey)
values (usr1.username, usr1.remoteaddress, usr1.userkey)";
connection.execute(sqlstatement
,[p_username, p_remoteaddress, p_userkey]
,{autoCommit: true}
,function(err, result) {
if (err) {
console.error(err.message);
return;
}
});
}
apex_web_service.make_rest_request(
p_url => 'http://192.168.56.12:4880/',
p_http_method => 'PUT',
p_body => '{"task" : "dbms_job_ready"
,"payload": {"job": job_identifier}}'
);
apex_web_service.make_rest_request(
p_url => 'http://192.168.56.12:4880/',
p_http_method => 'PUT',
p_body => '{"task" : "dbms_job_ready"
,"payload": {"job": job_identifier}}'
);
req.on('data', function(data) {
var body = JSON.parse(data.toString());
if (body.task == 'dbms_job_ready') {
//code to send dbms_job_ready event to clients
} else if (body.task == 'dbms_job_status') {
var msgStringOut = JSON.stringify({task : body.task
,payload: {job : body.payload.job
,perc: body.payload.percentage}
});
for(var i in clients){
clients[i].sendUTF(msgStringOut);
};
resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients‘
}));
};
);
req.on('data', function(data) {
var body = JSON.parse(data.toString());
if (body.task == 'dbms_job_ready') {
//code to send dbms_job_ready event to clients
} else if (body.task == 'dbms_job_status') {
var msgStringOut = JSON.stringify({task : body.task
,payload: {job : body.payload.job
,perc: body.payload.percentage}
});
for(var i in clients){
clients[i].sendUTF(msgStringOut);
};
resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients‘
}));
};
);
req.on('data', function(data) {
var body = JSON.parse(data.toString());
if (body.task == 'dbms_job_ready') {
//code to send dbms_job_ready event to clients
} else if (body.task == 'dbms_job_status') {
var msgStringOut = JSON.stringify({task : body.task
,payload: {job : body.payload.job
,perc: body.payload.percentage}
});
for(var i in clients){
clients[i].sendUTF(msgStringOut);
};
resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients‘
}));
};
);
req.on('data', function(data) {
var body = JSON.parse(data.toString());
if (body.task == 'dbms_job_ready') {
//code to send dbms_job_ready event to clients
} else if (body.task == 'dbms_job_status') {
var msgStringOut = JSON.stringify({task : body.task
,payload: {job : body.payload.job
,perc: body.payload.percentage}
});
for(var i in clients){
clients[i].sendUTF(msgStringOut);
};
resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients‘
}));
};
);
req.on('data', function(data) {
var body = JSON.parse(data.toString());
if (body.task == 'dbms_job_ready') {
//code to send dbms_job_ready event to clients
} else if (body.task == 'dbms_job_status') {
var msgStringOut = JSON.stringify({task : body.task
,payload: {job : body.payload.job
,perc: body.payload.percentage}
});
for(var i in clients){
clients[i].sendUTF(msgStringOut);
};
resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients‘
}));
};
);
req.on('data', function(data) {
var body = JSON.parse(data.toString());
if (body.task == 'dbms_job_ready') {
//code to send dbms_job_ready event to clients
} else if (body.task == 'dbms_job_status') {
var msgStringOut = JSON.stringify({task : body.task
,payload: {job : body.payload.job
,perc: body.payload.percentage}
});
for(var i in clients){
clients[i].sendUTF(msgStringOut);
};
resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients‘
}));
};
);
dropbox = function() {
this.dropbox_pkg = require("dropbox");
this.dropbox_client = new dropbox_pkg.Client({"key" : this.db_key
,"secret" : this.db_secret
,"token" : this.db_token
,"sandbox": false});
};
dropbox = function() {
this.dropbox_pkg = require("dropbox");
this.dropbox_client = new dropbox_pkg.Client({"key" : this.db_key
,"secret" : this.db_secret
,"token" : this.db_token
,"sandbox": false});
};
dropbox.prototype.getAccountInfo = function(callback) {
this.dropbox_client.getAccountInfo(function(error, accountInfo) {
if (error) {
callback(error, null);
return;
}
callback(null, accountInfo);
});
};
dropbox.getAccountInfo(function(error, accountInfo){
//put your code to handle the callback here
});
dropbox.prototype.getAccountInfo = function(callback) {
this.dropbox_client.getAccountInfo(function(error, accountInfo) {
if (error) {
callback(error, null);
return;
}
callback(null, accountInfo);
});
};
dropbox.getAccountInfo(function(error, accountInfo){
//put your code to handle the callback here
});
dropbox.prototype.getAccountInfo = function(callback) {
this.dropbox_client.getAccountInfo(function(error, accountInfo) {
if (error) {
callback(error, null);
return;
}
callback(null, accountInfo);
});
};
dropbox.getAccountInfo(function(error, accountInfo){
//put your code to handle the callback here
});
https://www.chromeexperiments.com/experiment/world-wide-maze
http://dinahmoelabs.com/plink
Some fun stuff to look at