Skip to content

Instantly share code, notes, and snippets.

View CosmoAbdon's full-sized avatar

Cosmo Abdon CosmoAbdon

  • Crateús, Ceara
View GitHub Profile
@CosmoAbdon
CosmoAbdon / nginx-tuning.md
Created August 7, 2021 15:03 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

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.

@CosmoAbdon
CosmoAbdon / dateUtils.ts
Last active June 19, 2021 11:16
Difference between two dates
export default const timeDiff = (dateNow: number, dateEarlier: number) => {
let diffInMS = Math.abs(+dateFuture - (+dateNow)) / 1000;
const days = Math.floor(diffInMS / 86400);
diffInMS -= days * 86400;
const hours = Math.floor(diffInMS / 3600) % 24;
diffInMS -= hours * 3600;
@CosmoAbdon
CosmoAbdon / DistanceBetweenPoints.ts
Created February 9, 2021 00:26
Getting distance between 2 points using haversine
interface location {
latitude: number,
longitude: number,
}
const getDistanceBetweenTwoPoints = (user: location, company: location): number => {
const p = 0.017453292519943295; // PI/180 (Evitar re-cálculo)
const cos = Math.cos;
const deltaLatitude = ((company.latitude - user.latitude) * p);
@CosmoAbdon
CosmoAbdon / bulkUpdate.js
Created November 6, 2020 14:53
Sequelize bulkUpdate.
const bulkUpdate = async (model, dataValues, conditional) => {
const transformValue = (...values) => values.map((v) => JSON.stringify(v));
const checkValue = ([A, B]) => A === B;
const promises = dataValues.map((value) =>
model.update({ ...value }, { where: { [conditional]: value[conditional] } })
);
const results = await Promise.all(promises);
const size = results.filter((r) => checkValue(transformValue(r, [0]))).length;
const removeAmount = (str, index) => str.substring(index);
const charPosition = (str, index) => str.charAt(index);
const transformStockID = (str) =>
charPosition(str, 2) === '0'
? removeAmount(str, 3)
: removeAmount(str, 2);
const filterProducts = (productsAux) =>
productsAux.map((product) => ({
* Funcionar controle brilho da tela
Entrar no modo texto
desabilitar o modo grafico: service lightdm stop
Reconfigurar o modo grafico: X -configure
Copiar arquivo xorg.conf para /etc/X11/xorg.conf
Habilitar modo grafico: service lightdm start
Editar /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi="