Skip to content

Instantly share code, notes, and snippets.

@JackyYin
JackyYin / sort.c
Created December 14, 2020 03:39
5 sorting algorithems includes bubble sort, selection sort, insertion sort, merge sort and quick sort
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
void _swap (int *arr, size_t i, size_t j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
@JackyYin
JackyYin / docker-compose.yml
Created December 23, 2019 07:34
docker-compose for local mongoDB
version: '3.5'
services:
mongo:
image: mongo
ports:
- '27017:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
@JackyYin
JackyYin / jwt.js
Created August 6, 2019 15:54
a JWT factory with blacklist and refresh function
const jwt = require('jsonwebtoken');
module.exports = (redisC) => {
const secret = process.env.JWT_SECRET;
const accessExpiresIn = 60 * 15;
const refreshExpiresIn = 60 * 60;
const sign = ({ payload = {}, options = {}, type = 'access' }) => {
payload = {...payload, type};
options = options.expiresIn ? options : {
@JackyYin
JackyYin / sequential-promise.js
Last active August 2, 2019 01:26
Imagine we have an array of 10000 promises, how do we process them one by one ?
// Imagine we have an array of 10000 promises,
// How do we process them one by one ?
// Here is a general version g and a recursive version r
let input = [];
for (let i = 1; i <= 10000; i++) {
input.push(Promise.resolve(i));
}
@JackyYin
JackyYin / ldap.js
Created July 22, 2019 01:06
a node.js ldap service use IIFE implementation
const ldapjs = require('ldapjs');
const url = process.env.LDAP_URL;
const LDAP_BIND_DN = process.env.LDAP_BIND_DN;
const LDAP_BIND_PWD = process.env.LDAP_BIND_PWD;
const SEARCH_DN = process.env.SEARCH_DN;
module.exports = (() => {
let client;
@JackyYin
JackyYin / gb.sh
Created July 22, 2019 00:58
parse my git branch
#!/bin/sh
parse_git_branch() {
git branch -a | sed -e "/^[^*]/d" -e "s/* \(.*\)/ $(echo '\033[1;31m')\1/"
}
echo $(parse_git_branch)
@JackyYin
JackyYin / fibonacci.js
Created July 10, 2019 06:44
recursion v.s. iteration
const recursion = n => {
if (n === 0) return 0;
if (n === 1) return 1;
return recursion(n - 1) + recursion(n - 2);
};
const iteration = n => {
if (n === 0) return 0;
if (n === 1) return 1;
@JackyYin
JackyYin / object.js
Created June 26, 2019 05:47
測試javascript複製object的行為
// ref:
// https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
// https://medium.com/@jobboy0101/js%E5%9F%BA%E7%A4%8E-primitive-type-v-s-object-types-f88f7c16f225
let a = {
pro1: 'aaa',
pro2: {
pro22: 'aaaa'
}
};
@JackyYin
JackyYin / docker-clean.sh
Last active April 10, 2019 03:59
檢查硬碟空間, 並清除prometheus docker volume
#!/bin/bash
usage()
{
echo ""
echo "Usage: $0 [ -d ][ -p ] "
echo -e "\t-d desired docker disk path"
echo -e "\t-p desired project path"
}
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH