Skip to content

Instantly share code, notes, and snippets.

View lastday154's full-sized avatar

Steve Hoang lastday154

  • NIT Warangal, India
View GitHub Profile
@lastday154
lastday154 / binaryToInteger.js
Created March 5, 2019 03:31
binaryToInteger
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function binaryToInteger(A) {
let sum = 0;
for (let i = 0; i < A.length; i++) {
sum += A[i] * Math.pow(-2, i);
}
return sum;
@lastday154
lastday154 / length.js
Created March 4, 2019 04:42
length of linked list
function solution(A) {
const len = A.length;
if (len <= 1) {
return len;
}
let K = 0;
let size = 0;
while (K != -1) {
K = A[K];
console.log("K: ", K);
@lastday154
lastday154 / promise_reduce.js
Created January 30, 2019 08:44
Sequential execution of Promises using reduce()
const compose = function(...tasks) {
return function(acc) {
return tasks.reduce(
(promise, task) => promise.then(task),
Promise.resolve(acc)
);
};
};
return compose(
@lastday154
lastday154 / parser.js
Created January 17, 2019 02:51
paser csv
'use strict';
const Busboy = require('busboy');
const getContentType = (event) => {
const contentType = event.headers['content-type'];
if (!contentType) {
return event.headers['Content-Type'];
}
return contentType;
@lastday154
lastday154 / update.md
Created November 29, 2018 08:04
update elastic search
curl -XPOST 'https://localhost:9200/test/_update_by_query' -H 'Content-Type: application/json' -d '{
    "query" : {
        "match_all" : {}
    },
    "script" : "ctx._source.isActive = 'true'"
}'
@lastday154
lastday154 / backup.js
Created September 28, 2018 10:06
backup ElasticSearch
# Backup ES
## Step 1: Create new index for index you want to backup
PUT /backup_test
```json
{
"mappings": {
"faq": {
@lastday154
lastday154 / setup.js
Created September 26, 2018 05:02
EC2 - Express - Github
https://medium.com/digitalcrafts/how-to-set-up-an-ec2-instance-with-github-node-js-and-postgresql-e363cb771826
https://medium.com/@Keithweaver_/setting-up-mern-stack-on-aws-ec2-6dc599be4737
@lastday154
lastday154 / client.js
Created September 20, 2018 07:06
S3 presigned url
var React = require('react');
var Dropzone = require('react-dropzone');
var axios = require('axios');
exports = module.exports = React.createClass({
_onDrop: function (files) {
var file = files[0];
axios.get(ENDPOINT_TO_GET_SIGNED_URL, {
filename: file.name,
@lastday154
lastday154 / closes.js
Created September 5, 2018 03:14
min distance
function compare(a,b) {
if (a.distance < b.distance) {
return -1;
}
if (a.distance > b.distance) {
return 1;
}
return 0;
}
function ClosestXdestinations(numDestinations, allLocations, numDeliveries)
@lastday154
lastday154 / optimalUtilization.js
Last active September 7, 2018 02:26
optimalUtilization
function optimalUtilization(maximumOperatingTravelDistance,
forwardShippingRouteList, returnShippingRouteList)
{
// WRITE YOUR CODE HERE
let currentMax = 0;
const result = [];
forwardShippingRouteList.forEach((forwardDistance) => {
returnShippingRouteList.forEach((returnDistance) => {
let distance = forwardDistance[1] + returnDistance[1];
if (currentMax <= distance && distance <= maximumOperatingTravelDistance) {