Skip to content

Instantly share code, notes, and snippets.

@hieulm
hieulm / token-generator.js
Created June 13, 2019 04:19 — forked from ziluvatar/token-generator.js
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
@hieulm
hieulm / Dockerfile
Created June 4, 2019 09:44
Nodejs Dockerfile
FROM node:10.15.3-alpine
WORKDIR /opt
ENV NODE_ENV=development
ENV HOST=localhost
ENV PORT=8000
ENV MONGO_URL=mongodb://localhost:27017/sample-service
ENV RABBIT_URL=amqp://rabbit:rabbit@rabbitmq:5672/example
@hieulm
hieulm / Dockerfile
Last active May 7, 2019 04:54
comspaces deployment with docker-compose
FROM node:10.15.3-alpine
WORKDIR /opt
ENV PORT=8000
ENV HOST=localhost
ENV NODE_ENV=development
ENV RABBIT_URL=amqp://rabbit:rabbit@localhost/comspaces
ENV POSTGRES_URL=postgres://postgres:secret@localhost:5432/user-service
ENV MONGO_URL=mongodb://mongodb-host:27017/user-service
@hieulm
hieulm / handler.js
Created April 18, 2019 14:32
part sort object from query string in javascript
const records = await eventColl
.aggregate([
{
$match: {
company_id,
soft_delete: false,
},
},
{
$sort: sortObj,
@hieulm
hieulm / babun-Hyper-Win.md
Created October 12, 2018 07:40 — forked from silo/babun-Hyper-Win.md
Babun + Hyper + Windows - Setup
@hieulm
hieulm / db.js
Created September 17, 2018 03:58 — forked from cpsubrian/db.js
Mock knex database for Jest
/* eslint-env jest */
import _ from 'lodash'
import path from 'path'
import fs from 'fs'
import callsites from 'callsites'
import knex from 'knex'
import hash from 'object-hash'
import conf from '<conf>'
// Get the db config.
@hieulm
hieulm / abstractions.md
Created July 13, 2018 08:32 — forked from arobson/abstractions.md
Rabbit.MQ + Node.js Notes

Abstraction Suggestions

Summary: use good/established messaging patterns like Enterprise Integration Patterns. Don't make up your own. Don't expose transport implementation details to your application.

Broker

As much as possible, I prefer to hide Rabbit's implementation details from my application. In .Net we have a Broker abstraction that can communicate through a lot of different transports (rabbit just happens to be our preferred one). The broker allows us to expose a very simple API which is basically:

  • publish
  • request
  • start/stop subscription
@hieulm
hieulm / MaterialReactSelect.js
Created April 23, 2018 10:05
react-select overrides for a material-ui@next feel
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { Async } from 'react-select';
// UI.
import { withStyles } from 'material-ui/styles';
import { FormControl } from 'material-ui/Form';
import { InputLabel } from 'material-ui/Input';
@hieulm
hieulm / Python-3-Django-El-Capitan.md
Created August 30, 2016 03:08 — forked from martincr/Python-3-Django-El-Capitan.md
Install Python 3 and Django on Mac OS X El Capitan (10.11.2) - and use virtualenv and virtualenvwrapper

Preamble

Background Reading

@hieulm
hieulm / gulpfile.js
Created May 11, 2016 00:50
gulpfile.js for elixir & foundation scss
var elixir = require('laravel-elixir');
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Sass
| file for our application, as well as publishing vendor resources.