Skip to content

Instantly share code, notes, and snippets.

Avatar

Nguyen Tung NguyenTungs

View GitHub Profile
View callback.js
// 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)
View date-object-cheatsheet.js
// 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);
@NguyenTungs
NguyenTungs / regexCheatsheet.js
Created Mar 7, 2019 — forked from sarthology/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
View regexCheatsheet.js
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"
View Useful is JavaScript using ES6
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
@NguyenTungs
NguyenTungs / functional-utils.js
Created Mar 6, 2019 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
View functional-utils.js
// 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)
@NguyenTungs
NguyenTungs / mongoToES.js
Created Sep 30, 2018 — forked from derickson/mongoToES.js
Example of NodeJS Loop of Mongo to Elasticsearch
View mongoToES.js
// 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'
});
@NguyenTungs
NguyenTungs / index.js
Created Aug 9, 2018 — forked from JonathanMH/index.js
JSON Web Token Tutorial: Express
View index.js
// 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");
@NguyenTungs
NguyenTungs / index.html
Created Jul 5, 2018
Firebase event is writing.. Firebase event is writing.. // source https://jsbin.com/mesuzuz
View index.html
<!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">
View base64-image-upload.js
/*
* 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
View es6-arrays.js
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
});