Skip to content

Instantly share code, notes, and snippets.

View 1xtr's full-sized avatar
💤
Today is already tomorrow will be yesterday

Alex 1xtr

💤
Today is already tomorrow will be yesterday
View GitHub Profile
@1xtr
1xtr / mongodb.mixin.js
Created October 30, 2023 08:51
moleculer mongodb mixin
import mongoose from 'mongoose'
import { mainSchema } from '../schemas.js'
/**
* @type {import('moleculer').ServiceSchema}
*/
// eslint-disable-next-line import/prefer-default-export
export const mongoDbMixin = {
name: 'mongoDbMixin',
async started() {
@1xtr
1xtr / helpers
Last active July 15, 2023 14:50
YC IoT message
import axios from 'axios'
import winston from 'winston';
export const logger = winston.createLogger({
format: winston.format.json(),
transports: [new winston.transports.Console()],
});
export const snsClientBuilder = (token) => {
const client = axios.create({
@1xtr
1xtr / distribution.js
Created January 25, 2023 22:09
Distribution by weight with counter. (Leads, task)
const managers = [
{ name: "Manager 1", weight: 0.6, tasks: 0 },
{ name: "Manager 2", weight: 0.2, tasks: 0 },
{ name: "Manager 3", weight: 0.1, tasks: 0 },
{ name: "Manager 4", weight: 0.1, tasks: 0 }
];
// Create a cumulative weight array
let cumWeight = 0;
for (let i = 0; i < managers.length; i++) {
@1xtr
1xtr / amazon-aws-cli-install-7z.sh
Last active January 21, 2023 16:53
Install 7z on amazon/aws-cli docker image
yum update -y && amazon-linux-extras install epel -y && yum install p7zip -y
@1xtr
1xtr / Fluid font size
Last active January 27, 2022 11:16
Fluid font size
// use
// .className
// @include fluidFontSize(12, 60, 320, 1440)
//
@function calcFluidFontSize($f-min, $f-max, $v-min, $v-max)
$k: ($f-max - $f-min)/($v-max - $v-min)
$b: $f-min - $k * $v-min
$b: $b * 1px
@return calc( #{$k} * 100vw + #{$b} )
@1xtr
1xtr / arrayShuffle.txt
Last active May 18, 2021 15:02
array shuffle
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}