Skip to content

Instantly share code, notes, and snippets.

View functional core, imperative

1. Separation of immutable and mutable logic

Quite a lot of different people have been on the same trail of thought. Gary Bernhardt's formulation of a "functional core, imperative shell" seems to be the most voiced.

"Boundaries" - Gary Bernhardt

"Imperative shell" that wraps and uses your "functional core".. The result of this is that the shell has fewer paths, but more dependencies. The core contains no dependencies, but encapsulates the different logic paths. So we’re encapsulating dependencies on one side, and business logic on the other side. Or put another way, the way to figure out the separation is by doing as much as you can without mutation, and then encapsulating the mutation separately. Functional core — Many fast unit tests. Imperative shell — Few integration tests

khoahuynhdev / corona.vim
Last active Mar 30, 2020
Check corona update in Vim
View corona.vim
function! s:corona_stats() abort
let l:lines = []
let l:keys = [
\ ['country', 'Quốc gia'],
\ ['cases', 'Số ca'],
\ ['todayCases', 'Số ca (hôm nay)'],
\ ['deaths', 'Tử vong'],
\ ['todayDeaths', 'Tử vong (hôm nay)'],
\ ['recovered', 'Hồi phục'],
khoahuynhdev /
Created Jun 12, 2019 — forked from vitorbritto/
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
khoahuynhdev / download.js
Last active May 25, 2019
download file with axios
View download.js
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
View server.js
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('./file.pem'),
cert: fs.readFileSync('./file.crt')
var serverPort = 443;
khoahuynhdev / database.js
Created Apr 20, 2019 — forked from hagemann/database.js
Promisified MySQL middleware for Node.js
View database.js
const util = require('util')
const mysql = require('mysql')
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
password: 'password',
database: 'my_database'
khoahuynhdev / util.txt
Last active May 6, 2019
useful methods to handle some situations
View util.txt
// If you’ve accidentally checked in node_modules before, that’s okay. You can remove it like this:
echo 'node_modules' >> .gitignore
git rm -r --cached node_modules
git commit -am 'ignore node_modules'
// create dump data for mysql
mysqldump -u YourUser -p YourDatabaseName > wantedsqlfile.sql
// Use utf8 in CMD Windows
khoahuynhdev / QSetup.js
Last active Apr 3, 2019
Quick and easy to use
View QSetup.js
// Pseudo Jquery
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
// convert a number in decimal to binary
8..toString('2') // '1000'
khoahuynhdev / HttpListenerDemo.cs
Last active Jan 23, 2021
simple HttpListener in C#
View HttpListenerDemo.cs
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace HttpListenerExample
class Program
public static HttpListener listener;