Last active
August 9, 2019 12:37
-
-
Save virendra656/447cae940dea380b461c2992a7c05582 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div> | |
</div> | |
<script type="text/javascript"> | |
let code = "0100191778005509211146191293359~71450245189~1722013110S004636"; | |
let gtin = ""; | |
let exp = ""; | |
let sn = ""; | |
let bat = ""; | |
let nhrn = ""; | |
while (code != "") { | |
// let say this is starting with gtin (14) digit | |
let flag = 1; | |
// alert(code) | |
if (!gtin && code.substring(0, 2) == "01") { | |
gtin = code.substring(2, 16); | |
code = code.substring(16); | |
} | |
// let say this is starting with exp (6) digit | |
else if (!exp && code.substring(0, 2) == "17") { | |
exp = code.substring(2, 8); | |
code = code.substring(8); | |
} | |
// let say this is starting with 21 sn varlength | |
else if (!sn && code.substring(0, 2) == "21") { | |
let len = code.indexOf("~") > -1 ? code.indexOf("~") : code.length; | |
sn = code.substring(2, (len)); | |
code = code.substring(len); | |
} | |
// let say this is starting with 21 batch varlength | |
else if (!bat && code.substring(0, 2) == "10") { | |
let len = code.indexOf("~") > -1 ? code.indexOf("~") : code.length; | |
bat = code.substring(2, (len)); | |
code = code.substring(len); | |
} | |
// let say this is starting with 21 nhrn varlength | |
else if (!nhrn && ["710", "711", "712", "713", "714"].indexOf(code.substring(0, 3)) > -1 ) { | |
let len = code.indexOf("~") > -1 ? code.indexOf("~") : code.length; | |
nhrn = code.substring(3, len); | |
code = code.substring(len); | |
} | |
// deal with var length param | |
else { | |
code = code.substring(1); | |
} | |
} | |
alert(gtin); | |
alert(exp); | |
alert(sn); | |
alert(bat); | |
alert(nhrn); | |
</script> | |
</body> | |
-- -------------------------------------------------------------------------------- | |
-- Routine DDL | |
-- Note: comments before and after the routine body will not be stored by the server | |
-- -------------------------------------------------------------------------------- | |
DELIMITER $$ | |
CREATE DEFINER=`yalgo_dev`@`%` PROCEDURE `NearByOffers`( | |
in lati Decimal(10,8), in longi Decimal(10,8), | |
in radius INT, | |
in rating varchar(10), | |
in category_id varchar(1000), | |
in business_location_address_id BIGINT, | |
in business_location_id BIGINT, | |
in _user_id BIGINT | |
) | |
BEGIN | |
set @lati = lati; | |
set @longi = longi; | |
set @radius = radius; | |
-- filters | |
IF (rating != "") THEN | |
set @rating = rating; | |
ELSE | |
set @rating = NULL; | |
END IF; | |
IF (business_location_address_id != "") THEN | |
set @business_location_address_id = business_location_address_id; | |
ELSE | |
set @business_location_address_id = NULL; | |
END IF; | |
IF (business_location_id != "") THEN | |
set @business_location_id = business_location_id; | |
ELSE | |
set @business_location_id = NULL; | |
END IF; | |
IF (category_id != "") THEN | |
set @category_id = category_id; | |
ELSE | |
set @category_id = NULL; | |
END IF; | |
-- filters ends | |
SELECT | |
bo.id as business_offer_id, | |
bo.title, | |
(3959 * ACOS(COS(RADIANS(@lati)) * COS(RADIANS(bla.latitude)) * COS(RADIANS(bla.longitude) - RADIANS(@longi)) + SIN(RADIANS(@lati)) * SIN(RADIANS(bla.latitude)))) AS offer_distance, | |
bla.latitude AS offer_latitude, | |
bla.longitude AS offer_longitude, | |
bla.address AS offer_address, | |
bla.id AS business_location_address_id, | |
bo.description, | |
boi.image AS offer_image, | |
bl.id AS business_location_id, | |
bl.business_name, | |
bl.business_image, | |
bl.logo, | |
bla.rating, | |
bla.latitude AS business_latitude, | |
bla.longitude AS business_longitude, | |
coalesce((select sum(uolp.points) from user_offer_loyalty_points uolp where uolp.user_id = _user_id and uolp.business_location_id = bl.id group by uolp.business_location_id limit 1), 0) loyalty_points, | |
bc.category_name, | |
bc.category_icon, | |
bc.category_hex_code | |
FROM business_offers bo | |
JOIN business_offer_images boi | |
ON bo.id = boi.business_offer_id | |
JOIN business_locations bl | |
ON bo.user_id = bl.user_id | |
JOIN business_categories bc | |
ON bc.id = bl.business_category_id | |
JOIN business_offer_geo_data bogd | |
ON bo.id = bogd.business_offer_id | |
JOIN business_location_addresses bla | |
ON bogd.business_location_address_id = bla.id and bla.is_deleted = 0 | |
-- LEFT JOIN user_offer_loyalty_points uolp ON uolp.user_id = _user_id and bo.business_location_id = uolp.business_location_id | |
WHERE bo.status = 1 | |
AND bl.status = 1 | |
AND bl.is_approved = 1 | |
AND NOW() BETWEEN bo.start_date AND bo.end_date | |
AND bo.business_location_id = COALESCE(@business_location_id, bo.business_location_id) | |
AND bogd.business_location_address_id = COALESCE(@business_location_address_id, bogd.business_location_address_id) | |
AND bogd.business_location_id = COALESCE(@business_location_id, bogd.business_location_id) | |
AND bla.rating = COALESCE(@rating, bla.rating) | |
AND FIND_IN_SET(bc.id,COALESCE(@category_id, bc.id)) | |
GROUP BY bogd.business_offer_id, bogd.business_location_id, bogd.business_location_address_id | |
HAVING offer_distance <= @radius | |
ORDER BY offer_distance ASC; | |
END | |
</html> | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<div id="future"></div> | |
<form id="form" id="chat_form"> | |
<input id="chat_input" type="text"> | |
<input type="submit" value="Send"> | |
</form> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script> | |
</body> | |
</html> | |
<script> | |
var socket = io.connect("http://localhost:4000"); | |
socket.on('connect', function(data) { | |
socket.emit('join', 'Hello World from client'); | |
}); | |
socket.on('broad', function(data) { | |
$('#future').append(data+ "<br/>"); | |
}); | |
$('form').submit(function(e){ | |
e.preventDefault(); | |
var message = $('#chat_input').val(); | |
socket.emit('messages', message); | |
}); | |
</script> | |
import * as express from 'express' | |
import * as winston from 'winston' | |
import * as boom from 'express-boom' | |
import * as morgan from 'morgan' | |
import * as cors from 'cors' | |
import * as expressValidator from 'express-validator' | |
import { json, urlencoded } from 'body-parser' | |
import { Express } from 'express' | |
import * as routes from './routes/_index' | |
const PORT: number = 4000 | |
/** | |
* Root class of your node server. | |
* Can be used for basic configurations, for instance starting up the server or registering middleware. | |
*/ | |
export class Server { | |
private app: Express | |
constructor() { | |
this.app = express() | |
var server = require('http').createServer(this.app); | |
var io = require('socket.io')(server); | |
// Express middleware | |
this.app.use(cors({ | |
optionsSuccessStatus: 200 | |
})) | |
this.app.use(urlencoded({ | |
extended: true | |
})) | |
this.app.use(json()) | |
this.app.use(boom()) | |
this.app.use(morgan('combined')) | |
this.app.use(expressValidator()) | |
server.listen(PORT, () => { | |
winston.log('info', '--> Server successfully started at port %d', PORT) | |
}) | |
io.on('connection', function (client) { | |
console.log('Client connected...'); | |
client.on('join', function (data) { | |
console.log(data); | |
}); | |
client.on('messages', function (data) { | |
client.emit('broad', data); | |
// client.broadcast.emit('broad',data); | |
//client.broadcast.emit('broad',data); | |
}); | |
}) | |
routes.initRoutes(this.app) | |
} | |
getApp() { | |
return this.app | |
} | |
} | |
new Server() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment