Skip to content

Instantly share code, notes, and snippets.

View MaximStone's full-sized avatar

Maxim Kosterin MaximStone

View GitHub Profile
@MaximStone
MaximStone / migrationUtils.js
Last active January 15, 2023 15:32
More flexable db migrations for Strapi. In my case several strapi instances were working as Kuber service. Migration should be executed only once.
/*
// Simple example (for similar situations I suggest to use sql-queries instead of js-based migrations)
//
// migrationUtils.js should be in [strapi-project]/database folder for this example. But it's up to you.
// Below the content of file: [strapi-project]/database/migrations/2023.01.15.correct-hotel-stars.js
const { prepareMigration } = require('../migrationUtils')
const path = require('path')
const migration = (knex) => {
const fs = require('fs');
const path = require('path');
const targetDir = 'D:\\FTP\\';
const patternToExcludeInName = 'text_to_delete_in_name_of_dir_or_file';
const fileNameToDeletePattern = 'file_to_delete_if_found'
const walkSync = function (dir, filelist) {
var files = fs.readdirSync(dir, {withFileTypes: true});
filelist = filelist || [];
files.forEach(function (file) {
@MaximStone
MaximStone / resize.js
Last active September 7, 2019 09:56
Resize images from current folder with transliterate to output folder
// script that resize
// npm install -g sharp
// npm install -g cyrillic-to-translit-js
const targetWidth = 900; // null - if need to fit size by height
const targetHeight = null; // null - if need to fit size by width
const targetFolder = 'output';
const withTransparentTrim = true;
#cloud-config
package_upgrade: true
package_reboot_if_required: true
runcmd:
- apt-get update
- curl -fsSL https://get.docker.com/ | sh
- curl -fsSL https://get.docker.com/gpg | sudo apt-key add -
@MaximStone
MaximStone / function.js
Created October 8, 2018 12:03
Рефакторинг функции
function lastIndexOfTwo(str, value1, value2) {
return Math.max(str.lastIndexOf(value1), s.lastIndexOf(value2));
}
@MaximStone
MaximStone / functions.js
Created October 7, 2018 21:02
Deep copy function
function deepCopy(obj) {
let result = {};
for (var key in obj) {
if (typeof obj[key] === 'object') {
result[key] = deepCopy(obj[key]);
} else {
result[key] = obj[key];
}
}
@MaximStone
MaximStone / function.js
Created October 7, 2018 20:22
Function to analyze braces syntax
function checkBraces(str) {
let temp = str.replace(/[^()\{\}<>[\]]/g, '');
let rule = /\(\)|\[\]|\{\}|<>/g;
while(rule.test(temp)) {
temp = temp.replace(rule, '');
}
return +(temp != '');