Skip to content

Instantly share code, notes, and snippets.

View gtindo's full-sized avatar

gtindo gtindo

View GitHub Profile
import fs from "node:fs/promises";
import path from "node:path";
import crypto from "node:crypto";
import { PGlite } from "@electric-sql/pglite";
import { PrismaPGlite } from "pglite-prisma-adapter";
import { PrismaClient } from "@prisma/client";
/**
* Create a PgLite instance, then create tables in the db from prisma migrations
*/
@gtindo
gtindo / elements.js
Created November 18, 2024 22:18
Web components utils
function createReactive(initialValue, sideEffect) {
const proxy = new Proxy(
{ value: initialValue },
{
set(target, prop, newValue) {
const outcome = Reflect.set(...arguments);
if (outcome) sideEffect(newValue);
return outcome;
},
get(target, prop, receiver) {
@gtindo
gtindo / FileUpload.js
Last active June 10, 2022 21:55
File Upload Web Component
class FileUpload extends HTMLElement {
constructor(){
super();
this.handleDropEvent = this.handleDropEvent.bind(this);
this._root = this.attachShadow({mode: "open"});
this._root.addEventListener("drop", this.handleDropEvent);
@gtindo
gtindo / occ.cpp
Last active February 26, 2021 21:43
occ.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
//freopen("input.txt", "r", stdin);
string word;
map<string, int> occ;
string max_w;
@gtindo
gtindo / tree.js
Created February 5, 2021 17:12
Category Tree js
class Node{
constructor(value){
this.value = value;
this.children = [];
}
}
class CategoryTree{
constructor() {
this.roots = [];
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAuthenticated, AllowAny, IsAdminUser
from blog.models import Post
from blog.serializers import PostSerializer
class CustomModelViewset(viewsets.ModelViewSet):
"""
A class that inherits from ModelViewset and allow to add custom permissions on your views
@gtindo
gtindo / merge_pdf.py
Created December 4, 2020 23:06
Script for merging all pdf inside a folder as a single pdf
"""
Script for merging all pdf inside a folder as a single pdf
Requirement: PyPDF2
usage: python merge_pdf.py -d <input_directory> -o output.pdf
Author: Gtindo Dev (https://gtindo.dev)
License: ISC
"""
@gtindo
gtindo / Can.tsx
Created September 15, 2020 08:54
Can component renders his children if user has permissions listed in permissions prop
import * as React from "react";
import { LoginContext } from "../components/login"
type CanPropsType = {
permissions: string[],
children: React.ReactNode
}
const hasPerms = (userPermissions: string[], componentPermissions: string[]): boolean => {
for(let permission of componentPermissions){
@gtindo
gtindo / mp4_to_mp3.py
Created June 28, 2020 22:57
Small script for converting mp4 files inside a directory to mp3 into an output folder.
"""
Small script for converting all mp4 files inside a folder to mp3 into an output folder
Requirement : ffmpeg, python30
Usage : python mp4_to_mp3.py -d <input_directory> -o <ouput_directory>
Author: Gtindo.dev
Licence: ISC
"""
import subprocess
@gtindo
gtindo / validate_operation.js
Created April 29, 2020 18:16
validate operation
function isCorrect(expr){
const n = expr.length;
const numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
const beforeOperator = [...numbers, ")"]
const afterOperator = [...numbers, "("]
const operators = ["+", "-", "/", "*", "."];
const authorisedsChars = [...numbers, ...operators, "(", ")"];
let leftParenthesis = [];
for(let i = 0; i < n; i++){