Skip to content

Instantly share code, notes, and snippets.

View evenfrost's full-sized avatar

Aliaksei Kislou evenfrost

View GitHub Profile
@evenfrost
evenfrost / JsonArrayType.ts
Last active January 26, 2022 10:37
Custom MikroORM type for Postgres 'jsonb[]'
import { Type, ValidationError } from '@mikro-orm/core';
export default class JsonArrayType extends Type<Record<string, any>[], string> {
convertToDatabaseValue(value: Record<string, any>[]): string {
if (!Array.isArray(value)) {
throw ValidationError.invalidType(JsonArrayType, value, 'JS');
}
const resultValue = JSON.stringify(value)
.replace(/"/g, '\\"')
import { Migration } from '@mikro-orm/migrations';
export class Migration20211022164646 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "Brands" drop constraint "Brands_clientId_fkey"');
this.addSql('alter table "Brands" add constraint "Brands_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete cascade;');
this.addSql('delete from "Brands" where "clientId" is null');
this.addSql('alter table "DynamicContentItems" drop constraint "DynamicContentItems_clientId_fkey"');
this.addSql('alter table "DynamicContentItems" add constraint "DynamicContentItems_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete cascade;');
@evenfrost
evenfrost / formZendeskInterface.js
Last active September 9, 2021 07:43
Form TS interface from Zendesk API page
function formInterface() {
const categoryName = document.querySelector('[class^="contentHeader__Container"] h1').textContent.slice(0, -1);
const table = document.querySelector('[class^="documentContent__DocumentContent"] [class^="renderToHtmlWithGarden__TableContainer"] table');
const getTsType = zendeskType => {
let tsType = null;
switch (zendeskType) {
case 'integer':
tsType = 'number';

Hello Aleksey,

We’d like to provide open source modular theming examples accessible on GitHub sometime in the future, but hopefully this will answer your question in the short term.

1. The Handlebars Partials File

The contents of the community-posts module’s partials.js file are as follows:

const communityPostsListItem = `
@evenfrost
evenfrost / mongo.sh
Created May 4, 2019 09:30
Some MongoDB commands
# dump database from Docker container
docker run --rm --link mongo:mongo -v /var/dumps/mongo:/backup mongo bash -c 'mongodump --gzip --archive=/backup/dump-$(date +%Y%m%d%H%M%S).gz --host=mongo:27017'
@evenfrost
evenfrost / svgo.sh
Last active December 30, 2022 17:38
svgo --pretty --indent=2 --disable=removeViewBox,mergePaths --enable=inlineStyles --config '{ "plugins": [ { "inlineStyles": { "onlyMatchedOnce": false } }] }' icon.svg
@evenfrost
evenfrost / reset-gnome-screensaver.sh
Last active February 12, 2019 10:04
Reset GNOME screensaver
killall gnome-screensaver
@evenfrost
evenfrost / highlight.ts
Last active November 6, 2024 18:39
Fuse.js with highlight
const highlight = (fuseSearchResult: any, highlightClassName: string = 'highlight') => {
const set = (obj: object, path: string, value: any) => {
const pathValue = path.split('.');
let i;
for (i = 0; i < pathValue.length - 1; i++) {
obj = obj[pathValue[i]];
}
obj[pathValue[i]] = value;
@evenfrost
evenfrost / func.js
Created October 11, 2018 16:26
Just simple JS function
function isGreater(a, b, cb) {
var greater = false;
if (a > b) {
greater = true;
}
cb(greater);
}
@evenfrost
evenfrost / backup_restore.sh
Last active March 5, 2018 16:14
Backup and restore Posgtres from/to Docker container
# backup from Docker container
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
# restore to Docker container
cat dump.sql | docker exec -i postgres-container-id psql -U postgres