Skip to content

Instantly share code, notes, and snippets.

View anhldbk's full-sized avatar
🌴
Calm

Anh Le (Andy) anhldbk

🌴
Calm
View GitHub Profile
@anhldbk
anhldbk / README.md
Last active March 3, 2024 16:36
TLS client & server in NodeJS

1. Overview

This is an example of using module tls in NodeJS to create a client securely connecting to a TLS server.

It is a modified version from documentation about TLS, in which:

  • The server is a simple echo one. Clients connect to it, get the same thing back if they send anything to the server.
  • The server is a TLS-based server.
  • Clients somehow get the server's public key and use it to work securely with the server

2. Preparation

@anhldbk
anhldbk / machine-id.js
Created August 10, 2016 04:35
Get globally unique IDs for machines
'use strict'
const os = require('os')
const crypto = require( "crypto" )
const _ = require('lodash')
// Get MAC addresses of public interfaces
// @return: List of addresses
function getPublicInterfaces(){
// get network interfaces
@anhldbk
anhldbk / wifi.md
Last active June 15, 2016 10:08
Install non-free wifi driver on my Ubuntu (Dell N4010)

Motivation

My Dell N4010's wifi driver seems not to work well on Ubuntu.

1. Run command

sudo vim /etc/apt/sources.list

2. Add following lines:

@anhldbk
anhldbk / binder.js
Last active August 22, 2022 13:55
Bind this for all methods in ES6 classes
'use strict';
class Binder {}
Binder.getAllMethods = function(instance, cls) {
return Object.getOwnPropertyNames(Object.getPrototypeOf(instance))
.filter(name => {
let method = instance[name];
return !(!(method instanceof Function) || method === cls);
});
@anhldbk
anhldbk / remove_mqtt_retained_msgs.md
Last active December 25, 2023 20:38
Remove MQTT retained messages using MQTT.js version 1.10.x
var mqtt    = require('mqtt');
var lodash = require('lodash');
var client  = mqtt.connect({ host: 'localhost', port: 1883 });

client.on('connect', function () {
  console.log('Connected')
  client.subscribe('presence');
});
@anhldbk
anhldbk / ths.md
Last active April 20, 2016 17:34
HWS

Notes for startup

@anhldbk
anhldbk / jwt.md
Last active April 7, 2016 08:36
JWT APIs

Token Based APIs

Overview

1. Token Loves Cookie

Reference: Token Based Authentication for Single Page Apps

I see a lot of discussions where cookies are pitted against access tokens. While we’ve all been burned by systems that store a session ID in a cookie, and that cookie is not secured and thus gets stolen. That sucks, but its not a reason to use tokens. Its a reason to avoid non-secure, non-https cookies.

@anhldbk
anhldbk / install.sh
Created January 25, 2016 01:49
Install zmq on Centos
sudo yum install -f libtool
cd autoconf-2.68
chmod +x configure
./configure
chmod +x build-aux/git-version-gen
sudo make
sudo make install
cd ..