Skip to content

Instantly share code, notes, and snippets.

View vvanghelue's full-sized avatar

Vincent Van Ghelue vvanghelue

View GitHub Profile
bl_info = {
"name": "Add Cube",
"description": "Adds a cube to the 3D View",
"author": "Your Name",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Add > Mesh",
"category": "3D View",
}
@vvanghelue
vvanghelue / mongo-is-dumb.js
Last active May 22, 2024 11:47
mongo-is-dumb.js
// dont works
[
{
$addFields: {
quotation: {
$arrayElemAt: ["$quotations", 0],
},
},
},
{
@vvanghelue
vvanghelue / postgres-dev-docker-compose.yml
Created February 1, 2024 08:25
postgres-dev-docker-compose.yml
version: "3.1"
services:
dev_db:
container_name: dev_db
image: postgres
restart: always
environment:
POSTGRES_USER: db_admin
POSTGRES_PASSWORD: wasspord
@vvanghelue
vvanghelue / bsk-handler-proposal.js
Last active January 18, 2024 09:30
bsk-handler-proposal.js
{
type: "html",
props: {
html: `
<div class="mt-5 mr-5 ml-5 mb-5">
<label>My label</label>
<select handle:change="myHandler">
<option>foo</option>
<option>bar</option>
</select>
@vvanghelue
vvanghelue / import-export-cookies-localstorage.js
Created January 4, 2024 13:03
import export cookies + localstorage
window.export_cookies = function () {
var cookieData = document.cookie.split(";").map(function (c) {
var i = c.indexOf("=");
return [c.substring(0, i), c.substring(i + 1)];
});
cookieData = JSON.stringify(JSON.stringify(cookieData));
console.log(cookieData);
};
window.import_cookies = function (json_string) {
var cookieData = JSON.parse(json_string);
@vvanghelue
vvanghelue / json-nester-filters-demo.js
Last active December 13, 2023 12:49
json-nester-filters-demo.js
function filterOuput(inputObject, tree) {
const hierarchy = tree.split(".");
function filterChildren(parent, hierarchyLevel) {
const key = hierarchy[hierarchyLevel];
for (const childKey of Object.keys(parent)) {
if (childKey === key || key === "*") {
if (hierarchy[hierarchyLevel + 1]) {
if (Array.isArray(parent[childKey])) {
for (const c of parent[childKey]) {
filterChildren(c, hierarchyLevel + 1);
@vvanghelue
vvanghelue / node-promisified-and-named-mysql2.js
Last active August 29, 2023 18:20
node-promisified-and-named-mysql2.js
/*
Usage :
import db from "./db.js"
await db.query("select 1+:test", { test: 123 })
*/
import mysql from "mysql2";
import toUnamedFactory from "named-placeholders";
const toUnamed = toUnamedFactory();
@vvanghelue
vvanghelue / code-nested-promises-controller.js
Created November 12, 2022 13:35
code nested promises controller
// allow usage of Promise.all without vars remapping and lost scope
const createPromisesController = () => {
const items = [];
return {
add(promise, fn) {
items.push({ promise, fn });
},
async flushPromises() {
const values = await Promise.all(items.map((item) => item.promise));
for (let i = 0; i < items.length; i++) {
@vvanghelue
vvanghelue / deduplicate-array-on-criteria.js
Created June 22, 2022 19:33
Deplucate array of items
function deDuplicate(arr, getUnique) {
return [
...new Set(
arr.map((i) => getUnique(i))
),
].map((i) =>
arr.find((a) => getUnique(a) === i)
);
}
@vvanghelue
vvanghelue / so-you-want-frontend-pagination.js
Created November 22, 2021 11:28
so-you-want-frontend-pagination.js
export class Page {
constructor({ active, index }) {
this.active = false;
this.items = [];
this.index = 1;
this.active = active;
this.index = index;
}
}
export class Pagination {