Skip to content

Instantly share code, notes, and snippets.

View avallete's full-sized avatar
🏠
Working from home

Andrew Valleteau avallete

🏠
Working from home
View GitHub Profile
@avallete
avallete / YbugContext.tsx
Created May 19, 2022 21:57
Minimal Ybug React integration
import * as React from "react";
import { env } from "~/config/env";
const YBUG_SCRIPT_URL = `https://widget.ybug.io/button/${env.VITE_YBUG_ID}.js`;
const YbugContext = React.createContext<YbugApi | null>(null);
type YbugApi = {
boot: () => void;
show: (opt?: "launcher") => void;
@avallete
avallete / prisma-transactions-benchmark.ts
Created April 28, 2022 14:06
Prisma transactions benchmark 3.13.0
import { prisma } from "~/config/prisma";
async function executeWithoutTransaction(data: Array<{ name: string }>) {
return await Promise.all(
data.map((d) => prisma.projects.create({ data: d }))
);
}
async function executeWithArrayTransaction(data: Array<{ name: string }>) {
return await prisma.$transaction(
import {Capacitor} from "@capacitor/core"
import { Camera, CameraDirection, CameraResultType, CameraSource } from "@capacitor/camera";
async function takePhoto() {
let cameraPermission = {camera: "granted"};
// On web, Camera.requestPermissions is not implemented, we we do it only if we are on a native platform
if (Capacitor.isNativePlatform()) {
cameraPermission = await Camera.requestPermissions({permissions: ["camera"] });
}
if (cameraPermission.camera !== "denied") {
@avallete
avallete / ag-grid-autocomplete-basic-example.html
Created April 18, 2021 09:17
An example of using agGrid and ag-grid-autocomplete-editor without npm or bundling
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ag-Grid Autocomplete Basic Example</title>
<script src="https://unpkg.com/ag-grid-community@25.1.0/dist/ag-grid-community.min.js"></script>
<!-- import AutocompleteSelectCellEditor styles -->
<link rel="stylesheet" href="https://unpkg.com/ag-grid-autocomplete-editor@2.2.1/main.css">
</head>
<body>
@avallete
avallete / shadow-dom-cdp-test.html
Created July 18, 2020 13:10
A quick test to retrieve the '#hoverme' div nodeId trough CDP
<!DOCTYPE html>
<html>
<head>
<title>Shadow DOM Fixture</title>
</head>
<body>
<div id="host"></div>
<script>
document
.getElementById('host')
@avallete
avallete / agGridCellEditorSelectorFactory.ts
Created November 8, 2019 13:48
An example of how to create and use a cellEditorFactory to extend basic cellEditor components into ag-Grid
import {IAfterGuiAttachedParams, ICellEditorComp, ICellEditorParams, IComponent, Promise} from 'ag-grid-community';
export interface ISelectorCellEditor extends ICellEditorParams {
highlightAllOnFocus?: boolean;
}
export interface ISCellEditor extends IComponent<ICellEditorParams>, ICellEditorComp {
}
export function selectorCellEditorFactory(cellEditor: new(...args: any[]) => (ISCellEditor)) {
#!/bin/bash
# Test to run the programme with all availables TERM into the terminal
# USAGE: ./script_term_test.sh "./lem-in < maps/test_2.map 1"
RED=$(printf "\e[31m")
GREEN=$(printf "\e[32m")
YELLOW=$(printf "\e[33m")
BLUE=$(printf "\e[34m")
MAGENTA=$(printf "\e[35m")
@avallete
avallete / whereValidator.js
Created April 24, 2018 12:22
Node.js sequelize pre-validate dynamic user provided 'where' clause. To avoid possible sql column injection.
const columnKeyRegexValidation = /^[a-zA-Z0-9_]+$/;
const sequelizeValidOperators = {
and: { validation: isDict },
or: { validation: isArrayOfDict },
gt: { validation: isPrimitive },
gte: { validation: isPrimitive },
lt: { validation: isPrimitive },
lte: { validation: isPrimitive },
ne: { validation: isPrimitive },
@avallete
avallete / decorator-modifier.py
Created February 9, 2017 23:07
A little script to toggle all window titlebar on ubuntu
#!/usr/bin/python
import argparse
from gi import require_version
require_version('Gdk', '3.0')
from gi.repository import Gdk
def check_args():
parser = argparse.ArgumentParser(description="Script to toggle the titlebar into Unity windows.")
parser.add_argument('-D', '--decorate', help='Decorate window.',
@avallete
avallete / youtube-minimizer.user.js
Last active June 29, 2017 09:09
Youtube-minimizer
// ==UserScript==
// @name Youtube-Minimalize
// @namespace Youtube Minimalize
// @description A little extension will keep only the player on youtube page and put it to full-browser screen.
// @version 1.0
// @match *://www.youtube.com/watch*
// @run-at document-end
// @grant none
// ==/UserScript==