This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getting connection from mysql.js file | |
// creating new mysql connection and checking it | |
const mysqlConnection = require('./model/mysql'); | |
const mysql = require('mysql'); | |
app.get('/testmysql', function(req, res) { | |
console.log(mysqlConnection.name); | |
mysqlConnection.createConnection().then((connection) => { | |
let query = "select * from zeus_user"; | |
let table = []; | |
query = mysql.format(query, table); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source https://www.youtube.com/watch?v=cKxRvEZd3Mw | |
from sklearn import tree; | |
# 0 for bumpy | |
# 1 for smooth | |
features = [[140,1], [130,1], [150,0], [170,0]] | |
#0 for apple | |
#1 for orange | |
labels = [0 ,0, 1, 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for examples goto https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function | |
// this function will return a promise | |
function multiplication(a, b) { | |
return new Promise((resolve, reject) => { | |
resolve(a * b) | |
}) | |
} | |
// whn you write async before function it allows you to return promise which was being returned from other function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source : https://www.npmjs.com/package/jsonwebtoken | |
// check token information at : https://jwt.io/ | |
const jwt = require('jsonwebtoken'); | |
// secret key | |
const secretKey = 'some secret key'; | |
// this is for verifying and creating token middleware | |
app.use((req, res, next) => { | |
// if the requested URL is login then create token otherwise verify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* this class helps us to make http calls | |
*/ | |
public class HttpCaller { | |
private Context context; | |
//private ProgressDialog pDialog; | |
private HttpProgressDialog httpProgressDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// traditional way of writing code | |
const router = require('express').Router(); | |
router.get('/check', check); | |
module.exports = router; | |
async function check(req, res) { | |
someOtherFunction().then((a) => { | |
somethingElseFunction().then((b) => { | |
res.status(200).json({a: a, b: b}); | |
}).catch((error) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function check(req, res) { | |
someOtherFunction().then((a) => { | |
somethingElseFunction().then((b) => { | |
res.status(200).json({a: a, b: b}); | |
}).catch((error) => { | |
res.send("error"); | |
}) | |
}).catch((error) => { | |
res.send("error"); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function check(req, res) { | |
try { | |
const a = await someOtherFunction(); | |
const b = await somethingElseFunction(); | |
res.send("result") | |
} catch (error) { | |
res.send(error.stack); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getData(){ | |
const a = await someFunction().catch((error)=>console.log(error)); | |
const b = await someOtherFunction().catch((error)=>console.log(error)); | |
if(a && b ) console.log("some result") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
const expressjwt = require('express-jwt') | |
const jsonwebtoken = require('jsonwebtoken'); | |
// this will verify the token before going to actual requested route (middleware) | |
// except the "/login" route every request needs token in header which will look like "Authorization:Bearer eyJh..........." refer image in story | |
app.use(expressjwt({secret: "some key"}).unless({path: ['/', '/login']})) |
OlderNewer