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 / elasticsearch.js
Created May 28, 2018 04:39
unit test with sinon, mochai, chai, supertest
const app = require('../../app');
const request = require('supertest');
const sinon = require('sinon');
const { expect } = require('chai');
const ElasticSearch = require('../../models/elasticsearch');
const url = '/api/search?q=money&page_id=333&lang=en';
describe('GET /api/search', () => {
let sandbox;
@lastday154
lastday154 / debug_lambda.js
Created June 1, 2018 04:20
debug lambda vscode
- package.json
"scripts": {
"start": "./node_modules/.bin/serverless offline -s dev",
"debug": "export SLS_DEBUG=* && node --inspect ./node_modules/.bin/serverless offline -s dev",
"test": "mocha"
},
- serverless.yml
plugins:
- serverless-offline
@lastday154
lastday154 / async.js
Created June 4, 2018 14:15
async/await loops
'use strict';
const delay = () => new Promise((resolve) => setTimeout(resolve, 300));
const delayedLog = async (item) => {
await delay();
console.log(item);
};
const processArray = (array) => {
@lastday154
lastday154 / csv.js
Created June 6, 2018 02:14
busboy parse multi-part form lambda
'use strict';
const csv = require('csvtojson');
const stringToRow = (csvStr) => new Promise((resolve, reject) => {
csv({
noheader: true,
output: 'csv'
})
.fromString(csvStr)
@lastday154
lastday154 / .eslintrc
Last active June 8, 2018 12:31 — forked from elijahmanor/.eslintrc
Add Prettier & ESLint to VS Code with a Create React App
{
"extends": ["react-app", "plugin:prettier/recommended"]
}
@lastday154
lastday154 / Component.jsx
Created June 8, 2018 06:52 — forked from krambertech/Component.jsx
ReactJS: Input fire onChange when user stopped typing (or pressed Enter key)
import React, { Component } from 'react';
import TextField from 'components/base/TextField';
const WAIT_INTERVAL = 1000;
const ENTER_KEY = 13;
export default class TextSearch extends Component {
constructor(props) {
super();
@lastday154
lastday154 / SearchBar.js
Created June 8, 2018 06:55
Auto complete search
import React, { Component } from "react";
export default class SearchBar extends Component {
constructor(props) {
super(props);
this.handleQueryChange = this.handleQueryChange.bind(this);
}
handleQueryChange = e => {
this.props.onQueryChange(e.target.value);
@lastday154
lastday154 / download-file.js
Created June 10, 2018 06:40 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@lastday154
lastday154 / Home.js
Created June 12, 2018 08:38
axios testing react
import Autosuggest from "react-autosuggest";
import React, { Component } from "react";
import "./Home.css";
import SuggestionValue from "./SuggestionValue";
import axios from "axios";
import { find } from "lodash";
import config from "../config";
const renderSuggestion = suggestion => suggestion.q;
'use strict';
const { intentsClient, sessionClient } = require('./config');
const { jsonToCsv, mergeIntents } = require('./dialogflowHelper');
const projectId = process.env.DIALOGFLOW_PROJECT_ID;
const detectIntent = (query, languageCode = 'en-Us') => {
// Define session path
const sessionId = Math.random().toString();