Skip to content

Instantly share code, notes, and snippets.

View lenconda's full-sized avatar
💻
Working and studying hard

Peng Hanlin lenconda

💻
Working and studying hard
View GitHub Profile
@lenconda
lenconda / publisher.js
Last active February 8, 2019 15:51
Another producer consumer model
// /src/publisher.js
const amqp = require('amqp')
const {
MQ_HOST,
MQ_PORT,
MQ_LOGIN,
MQ_PASSWORD,
MQ_TIMEOUT,
MQ_QUEUE } = require('../../config')
@lenconda
lenconda / child.js
Created February 25, 2019 01:17
Node.js child_process.fork()
console.log(`Child process running with ${process.pid}`)
setInterval(() => {
process.send(`Worker got time: ${Date.parse(new Date())}`)
}, 1000)
@lenconda
lenconda / distinct.js
Last active March 8, 2019 05:39
A MongoDB script to remove duplicates
db.NEW_COLLECTION.ensureIndex({ 'KEY_TO_DISTINCT': 1 }, { 'unique': true, 'dropDups': true });
db.DUMMY_COLLECTION.find().forEach(function(doc) {
db.NEW_COLLECTION.insert(doc);
});
@lenconda
lenconda / vhost.conf
Created March 8, 2019 11:50
Nginx config file to make a Node.js backend proxy
# © Lenconda
# When the path is //path.example.com/api/path/to/interface, redirect to http://localhost:3000/api/path/to/interface
# Backend should add a route prefix of '/api'
server {
listen 80;
server_name path.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
@lenconda
lenconda / checker.js
Last active March 11, 2019 05:10
Check if remote service is available
const tcpp = require('tcp-ping')
const _ip = Symbol('ip')
const _port = Symbol('port')
class TCPChecker {
/**
* @constructor
* @param {string} address
@lenconda
lenconda / consumer.ts
Created March 20, 2019 14:46
A producer-consumer model for RabbitMQ and test scripts
import config from '../../config/rabbitmq'
import { Consumer } from '../message_queue'
const consumer = new Consumer(config)
consumer.on('message', message => {
console.log(message)
})
@lenconda
lenconda / Parallel_Tools_fix_for_Ubuntu_19.04.md
Created September 12, 2019 06:07 — forked from mag911/Parallel_Tools_fix_for_Ubuntu_19.04.md
Parallel Tools fix for Ubuntu 19.04

First off, credit goes to github.com/rudolfratusinski for leading the way here.

https://gist.github.com/rudolfratusinski/a4d9e3caff11a4d9d81d2e84abc9afbf

In a very similar approach, copy the files from the Parallels installation media and drop them in a folder somewhere (eg. ~/parallels_fixed)

Go to the kmods directory (cd ~/parallels_fixed/kmods) and extract the files (tar -xzf prl_mod.tar.gz)

Remove prl_mod.tar.gz file from that directory (rm prl_mod.tar.gz)

@lenconda
lenconda / promisible.js
Last active January 15, 2020 08:37
promise implementation
function Promisible(executor) {
var _this = this;
_this.status = 'pending';
_this.result = null;
_this.reason = null;
_this.resolvedCallbacks = [];
_this.rejectedCallbacks = [];
function resolve(result) {
if (_this.status === 'pending') {
@lenconda
lenconda / meta
Last active March 16, 2020 15:25
site-description
{
"subtitle": "code. for. life."
}
@lenconda
lenconda / cloudSettings
Created September 18, 2020 03:12
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-18T03:12:55.547Z","extensionVersion":"v3.4.3"}