Thursday, February 2, 2017

ExpressJS HTTPS Firebase Auth Restful Webservices Framework

So, if you've read through my blog you'd, know by now, that I do make Restful web services for Java / PHP and I've recently started working with Node.JS and Firebase. Hence, I've decided to create my own HTTPS Restful web services framework that is built on express for Firebase. As follows.


var express = require('express');// Enable Express
var app = express();

var fs = require('fs');//Enable Https
var https = require('https');


var cors = require('cors'); // Add CORS for browser requests


var firebase = require('firebase');// Enable Firebase
  firebase.initializeApp({
  serviceAccount: 'Something.json here', // Add Firebase key JSON
  databaseURL: 'Firebase db endpoint here' // Add Firebase endpoint
});


// Add endpoint for CORS
app.use(cors({origin: 'Script origin here'}));


// Create Https Server
https.createServer({
      key: fs.readFileSync('key.pem'),
      cert: fs.readFileSync('cert.pem')
    }, app).listen(8081);



app.post("/YOUR_ENDPOINT_NAME", function (req, res) {

firebase.auth().verifyIdToken(req.body.Token).then(function(decodedToken) {

  var uid = decodedToken.uid;
  if(uid ===req.body.uid){
   /*
    *
    *
    *
* Do your work here.
*
*
*
*
*/

  }else{

// If token UID doesnt Match
var info={
message:"Bad Token",
success:false
}
        res.json(info);
  }
}).catch(function(error) { // If theres a Token Error
var info={
message:(error.code + ' - '+ error.message),
success:false
}
res.json(info);
});
});



This is a simple Node.JS Restful framework that is built on expressJS and uses HTTPS.
It has been built to simplify Firebase web services deployment and demonstrate secure Restful web service creation with Firebase.
Ideally, it is geared towards Firebase developers who need to create backend web services, as a mechanism for fast deployment.

Dependencies:

Node.JS
ExpressJS
CORS
https
fs
Firebase


Resources:

Firebase - https://www.firebase.com/docs/
Express - https://expressjs.com/
Cors - https://www.npmjs.com/package/cors
HTTPS - http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/
FS - http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/

Deployment:

You will need to create a node project and add the dependencies to your node project and configure the package,json accordingly.
Further you will need to create and add the HTTPS certificate to the service, for this it is advisable to read up on the HTTPS resource blog post
by Minko Gechev here - http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/

Note *** your request body should contain the following fields.

Token: From Firebase session
uid: From Firebase session

Happy Coding :)

Github - https://github.com/bkraad47/ExpressJS-HTTPS-Firebase-Auth-Restful-Framework

Monday, October 24, 2016

NodeJS, Firebase & Github

I've recently been working NodeJS (Express, Braintree & Ember), with Firebase Tools (Amazing Auth, No-SQL DB etc.) and a few other projects.



To have a look at the projects go to my Github  -  Click here

Wednesday, August 17, 2016

JCUDA - ITTERATIVE SOFT THRESHOLDING(IST) FOR SPARSE NUCLEAR MAGNETIC RESONANCE(NMR)

So I decided to look back at one of the projects I completed at ANU and decided to give it a CUDA update.

Project Link-https://cs.anu.edu.au/courses/csprojects/15S1/Reports/Badruddin_Kamal_Report.pdf

Git-https://github.com/bkraad47/JCUDA_SPASE_NMR_IST

Wednesday, July 20, 2016

Own the power of a super computer for just 200$'s (As of 5/6/2016)



So, I have always been an NVIDIA fanboy (No secret- I have owned AMD products before, don't really degrade them, but its just been a tradition. And yes was flipping over the GTX 1080), but AMD's RX480 (Still haven't used one, but hope to get one soon) just seems to have hit a home run. It costs 200$'s and delivers 5 TFLOPs, that's almost 40$ per TFLOP (https://en.wikipedia.org/wiki/FLOPS), that does make a very persuasive argument. I moved away from gaming for a few years now and I mostly use GPU's now to do calculations, and 40$'s per TFLOP makes a very persuasive argument to move to AMD and OpenCL, compared with NVIDIA's 77.8$'s per TFLOP.

Tuesday, April 12, 2016

Basic Introduction to HPC and Parallel Computing.

So, I've been pursuing my Masters at ANU for the last 2 years and have been doing some really neat stuff which might interest you. It involved doing some C/C++ programming and got to use the supercomputer there. I also got to do some advanced AI, Neural Networks, HCI stuff as well as HPC & Parallel computing. If you are looking to speed up your code or Algorithm's the HPC & Parallel computing, techniques may be quite useful.
So first and foremost you must understand Amdahl's law. - https://en.wikipedia.org/wiki/Amdahl%27s_law
Speed up =(1/ (1-P))+ (P/N)
Where, P = Parallel portion of code and (1-P) is the sequential portion of the code.
         N = No. of Processors.

Vector Processing using SSE (Liks Below)
One of the things I've been looking at is SIMD processor programming. I've fallen in love with MPI and CUDA, There are some really cool blogs on this out there, I'll post a few, I found useful here.
If you want to try CUDA, SSE or MPI. I highly recommend trying respective documentation and software as it come's in great detail.
CUDA- https://developer.nvidia.com/cuda-zone(Has amazingly good documentation)
And to analyze performance PAPI Profiler - https://icl.cs.utk.edu/projects/papi/wiki/Main_Page
Hope this helps.
Cheers
Raad

Friday, January 17, 2014

Install intel ssd on Hp Envy 15 (2013)

Boot backups wont work.

Had to use Acronis(Intel Drive Migration Tool) to copy drives, then just installed and booted my original windows and files.



Best Java Enterprise Scheduler (Quartz) with auto-start and stop on deployment

The best Java Enterprise scheduler I've used so far is quartz.

Its very proper and comes with all the needed class modules. And definitely have seen it being used professionally to extremes.


How to



Note* - Use log4j classes

Auto Start Stop

This is done by adding custom lines to ContextListener. By simply deploying and undeploying packages quartz can be start and stopped.

public class Config implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {
        ***Code to initialize quartz thread pool***
    }

    public void contextDestroyed(ServletContextEvent event) {
        ***Code to stop quartz thread pool***

    }

}
and register it as a <listener> in web.xml.
<listener>
    <listener-class>com.example.Config</listener-class>
</listener>