Skip to content

Instantly share code, notes, and snippets.

View tridungle's full-sized avatar

Trí Dũng Lê tridungle

  • Independent
  • Ho Chi Minh
View GitHub Profile
package com.gd.ashylin.crawler.service;
import com.gd.ashylin.crawler.CrawlerResult;
import com.gd.ashylin.crawler.CrawlerResults;
import com.gd.ashylin.crawler.CrawlerStatus;
import com.gd.ashylin.crawler.Sorting;
import com.gd.ashylin.crawler.logic.Crawler;
import java.util.Collections;
import java.util.HashMap;
parameters:
mad.crawler.client.config:
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0 FirePHP/0.7.4"
base_url: %crawler.base.url%
mad.crawler.config:
crawler_sleep: 5;
item_sleep: 0.5
mad.crawler.main_url_list: [ %crawler.base.url% ]
@tridungle
tridungle / dtlab_query.png
Created May 11, 2021 07:27 — forked from navicore/dtlab_query.png
dtlab query with graph helper
dtlab_query.png
@tridungle
tridungle / node_pm2_update.md
Created April 14, 2021 09:25 — forked from suhas-karanth/node_pm2_update.md
Upgrading node and pm2 using nvm

Update node using nvm

nvm install 6.3
nvm alias default 6.3
nvm use 6.3

Install and Update pm2

npm install pm2@latest -g ; pm2 update
@tridungle
tridungle / passport_node_acl_example.js
Created March 26, 2021 07:15 — forked from danwit/passport_node_acl_example.js
Authentication and authorization with passportjs + node_acl + mongo + express
/**
* Simple authentication and authorization example with passport, node_acl,
* MongoDB and expressjs
*
* The example shown here uses local userdata and sessions to remember a
* logged in user. Roles are persistent all the way and applied to user
* after logging in.
*
* Usage:
* 1. Start this as server

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@tridungle
tridungle / react-rendering.md
Created March 24, 2021 04:15 — forked from tuhuynh27/react-rendering.md
A (Mostly) Complete Guide to React Rendering Behavior

Translated from https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/, author: Mark Erikson (from Redux team)

A (Mostly) Complete Guide to React Rendering Behavior

Bài viết cung cấp chi tiết về cách mà React render hoạt động, và việc sử dụng Context và Redux ảnh hưởng thế nào tới quá trình render của React.

"Render" là gì

Rendering is the process of React asking your components to describe what they want their section of the UI to look like, now, based on the current combination of props and state.

@tridungle
tridungle / random.md
Created March 15, 2021 07:38 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@tridungle
tridungle / eslint-typescript.md
Created March 12, 2021 04:44 — forked from pedrouid/eslint-typescript.md
Eslint + Prettier configuration for Typescript 3.7+ (2020)

Eslint + Prettier configuration for Typescript 3.7+ (2020)

  1. Install required dependencies
npm install --save-dev @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-standard prettier

# OR

yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-standard prettier
@tridungle
tridungle / gist:738915b9415e577e6ee2961aa2072aab
Created January 15, 2021 06:09 — forked from joerx/gist:ea16b9af330e0c346155
Stubbing email sending in tests
// This is the simplest possible approach - use a custom module to wrap a single, pre-configured
// mail transport instance and then use sinon.js to stub out that modules sendmail()
// This approach has its limitations, but it is still better than having 'if(NODE_ENV === 'test')'
// all over the code base.
// -- app/sendmail.js --
var nodemailer = require('nodemailer');
var config = require('config').email;