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
// Ví dụ về callback truyền thống, nỗi kinh hoàng của developer. | |
// link ref: https://anonystick.com/blog-developer/series-callback-javascript-phan-3-async-await-la-gi-va-su-khac-nhau-giua-promise-trong-javascript-vRwGny6a.jsx | |
const verifyUser = function(username, password, callback){ | |
dataBase.verifyUser(username, password, (error, userInfo) => { | |
if (error) { | |
callback(error) | |
}else{ | |
dataBase.getRoles(username, (error, roles) => { | |
if (error){ | |
callback(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
// Date Object CheatSheet | |
// The Date object is used to work with dates and times. | |
// More: http://www.w3schools.com/jsref/jsref_obj_date.asp | |
// 1. Instantiating a Date. | |
var date = new Date(); | |
var date = new Date(milliseconds); |
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
let regex; | |
/* matching a specific string */ | |
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello" | |
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO" | |
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes... | |
/* wildcards */ | |
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo" | |
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo" |
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
Hẳn là trong mỗi lập trình viên Javascipt đều có cho mình một lib về các func hữu ích, và nó sẽ đi theo mình suốt một dự án hay dài hơn nữa là cả cuộc đời thăng trầm. | |
Và đây tôi sẽ chia sẻ cho các bạn lib của tôi, lúc đầu tôi làm es5 nhưng sau này tôi đã chuyển về es6 để thuận tiện phù hợp cho các dự án tiếp theo. | |
Các bạn nào chưa hiểu về cấu trúc của es5 khác với es6 như thế nào thì tôi khuyên hãy đọc qua bài này. | |
Sự khác biệt cấu trúc ES5 và ES6... | |
https://anonystick.com/blog-developer/hoc-javascript-su-khac-biet-cau-truc-class-giua-es5-va-es6-sTuezjDk.jsx |
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
// array utils | |
// ================================================================================================= | |
const combine = (...arrays) => [].concat(...arrays); | |
const compact = arr => arr.filter(Boolean); | |
const contains = (() => Array.prototype.includes | |
? (arr, value) => arr.includes(value) | |
: (arr, value) => arr.some(el => el === value) |
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
// npm install elasticsearch | |
// setup nodejs client for elasticsearch | |
// documentation: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html | |
var elasticsearch = require('elasticsearch'); | |
var EsClient = new elasticsearch.Client({ | |
host: 'localhost:9200', | |
log: 'info' | |
}); |
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
// file: index.js | |
var _ = require("lodash"); | |
var express = require("express"); | |
var bodyParser = require("body-parser"); | |
var jwt = require('jsonwebtoken'); | |
var passport = require("passport"); | |
var passportJWT = require("passport-jwt"); |
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> | |
<meta charset="utf-8"> | |
<meta name="description" content="Firebase event is writing.."> | |
<meta name="keywords" content="Firebase event is writing.."> | |
<meta name="author" content="anonystick"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
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
/* | |
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674 | |
*/ | |
var fs = require('fs'); | |
// string generated by canvas.toDataURL() | |
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0" | |
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO" | |
+ "3gAAAABJRU5ErkJggg=="; | |
// strip off the data: url prefix to get just the base64-encoded bytes |
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
const people = Array.from(document.querySelectorAll('.people p')); | |
const names = peopleArray.map(person => person.textContent); | |
// --------------------------------------------------------------- | |
const names = Array.from(document.querySelectorAll('.people p'), person => { | |
return person.textContent | |
}); |
NewerOlder