Skip to content

Instantly share code, notes, and snippets.

View alexy4744's full-sized avatar
🍥

Alex alexy4744

🍥
View GitHub Profile
@alexy4744
alexy4744 / closure-table.repository.ts
Last active February 27, 2024 08:19
MikroORM Closure Table Repository
import { Constructor } from "@mikro-orm/core";
import { EntityRepository, Knex } from "@mikro-orm/postgresql";
type Node = string;
export interface ClosureTableRepository<Entity> extends EntityRepository<Entity> {
containsDescendant(parent: Node, descendant: Node): Promise<boolean>;
findDescendants(parent: Node): Knex.QueryBuilder;
insertLeafNode(leaf: Node, parent: Node): Promise<void>;
insertRootNode(root: Node): Promise<void>;
@alexy4744
alexy4744 / closure-table-operations.sql
Last active April 12, 2021 01:40 — forked from kentoj/closure-table-operations.sql
Closure Table operations SQL fragments
-- Retrieve descendants
-- ====================
-- retrieve descendants of #4
SELECT c.*
FROM Comments AS c
JOIN TreePaths AS t ON c.comment_id = t.descendant
WHERE t.ancestor = 4;
-- Retrieve ancestors
@alexy4744
alexy4744 / merge.java
Created April 21, 2020 16:25
merge 2 sorted arrays
public static int[] merge(int[] a, int[] b) {
int[] c = new int[a.length + b.length];
int i = 0;
int j = 0;
int k = 0;
while (i < a.length && j < b.length) {
if (a[i] < b[j]) c[k++] = a[i++];
else c[k++] = b[j++];
@alexy4744
alexy4744 / settings.json
Last active June 24, 2019 02:08
VSCode operator mono ligatures + eslint settings
{
/* EDITOR SETTINGS */
"editor.detectIndentation": true,
"editor.fontSize": 18,
"editor.fontFamily": "Operator Mono Lig",
"editor.fontLigatures": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.tokenColorCustomizations": {
"textMateRules": [