Skip to content

Instantly share code, notes, and snippets.

View lh0x00's full-sized avatar
💭
do something, something great 📝

Hieu Lam lh0x00

💭
do something, something great 📝
View GitHub Profile
function splitArray(arr, k) {
const length = arr.length;
const middle = Math.floor(length / k);
const left = arr.slice(middle * k, length);
let result = [], cursor = 0;
while(cursor < middle) {
result.push(arr.slice(cursor * k, cursor * k + k))
cursor++;
}
function merge(left, right) {
let arr = [], leftIndex = 0, rightIndex = 0;
while(left.length > leftIndex && right.length > rightIndex) {
if (left[leftIndex] < right[rightIndex]) {
arr.push(left[leftIndex]);
leftIndex++;
} else {
arr.push(right[rightIndex]);
function getMaxValue(k, n, weights, values) {
let maxValue = 0;
const valueOfItems = {};
for (let i = 0; i < n; i++) {
valueOfItems[i] = values[i] / weights[i];
}
let totalWeight = 0;
const ordered = Object.entries(valueOfItems).sort((a, b) => b[1] - a[1]);
@lh0x00
lh0x00 / calculate-savings-interest.js
Last active April 13, 2020 04:18
Calculate savings interest
function calculateSavingsInterest(
numberOfMonths = 12,
assetsFirst = 50000000,
amountEachMonth = 15000000,
percentageOfInterest = 5.35,
skipFirstMonth = true,
) {
const startAt = skipFirstMonth ? 1 : 0;
let total = 0;
for (let i = startAt; i <= numberOfMonths; i++) {
#!/bin/sh
git filter-branch -f --env-filter '
OLD_EMAIL="old email"
CORRECT_NAME="new name"
CORRECT_EMAIL="new email"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
const JS_RESOURCE =
'//cdn.jsdelivr.net/gh/kenwheeler/[email protected]/slick/slick.min.js';
const CSS_RESOURCE = [
'//cdn.jsdelivr.net/gh/kenwheeler/[email protected]/slick/slick.css',
'//cdn.jsdelivr.net/gh/kenwheeler/[email protected]/slick/slick-theme.css',
];
const appendStyleToHead = () => {
const linkTags = CSS_RESOURCE.map(
url => ` <link rel="stylesheet" type="text/css" href=${url} />`,
@lh0x00
lh0x00 / nginx-tuning.md
Created May 18, 2020 04:16 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@lh0x00
lh0x00 / sysctl.conf
Created May 18, 2020 11:45 — forked from voluntas/sysctl.conf
Sysctl configuration for high performance
### KERNEL TUNING ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
function get_max_value(
k: number,
n: number,
weights: number[],
values: number[],
): number {
let max_value = 0
const ratios = {} as { [i: number]: number }
for (let i = 0; i < n; i++) {
@lh0x00
lh0x00 / index.html
Created August 8, 2021 04:51 — forked from kapral18/index.html
Native AsyncAwait vs babel regenerator vs promises (http://jsbench.github.io/#bb78a677c5850d0830ff7d818d5ac4cd) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Native AsyncAwait vs babel regenerator vs promises</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>