Skip to content

Instantly share code, notes, and snippets.

View sylvaindethier's full-sized avatar

Sylvain Dethier sylvaindethier

View GitHub Profile
@sylvaindethier
sylvaindethier / fastify-https-anchor.ts
Created May 7, 2024 06:48
Fastify HTTPS server with @anchordotdev/cli
//@ts-expect-error no declaration files
import {createSNICallback} from "anchor-pki/auto-cert/sni-callback";
//@ts-expect-error no declaration files
import { TermsOfServiceAcceptor } from "anchor-pki/auto-cert/terms-of-service-acceptor";
import https from "node:https";
import type { FastifyServerFactory } from "fastify";
const serverFactory: FastifyServerFactory = (handler) => {
const SNICallback = createSNICallback({
@sylvaindethier
sylvaindethier / Refine.d.ts
Created April 19, 2024 16:15
Refine TypeScript utility
/**
* Refine a Type
* @example
* ```ts
* type Refined = Refine<{ foo: string, bar: unknown[] }, { foo: `${number}` }>
* // ^? { foo: `${number}`, bar: unknown[] }
* ```
*/
export type Refine<T, P extends Partial<T>> = {
[k in keyof T]: T[k] & P[k];
@sylvaindethier
sylvaindethier / solidjs-RouteDefinitionParams.d.ts
Last active April 19, 2024 19:58
SolidJS type safe for `useParam` from a `RouteDefinition`
import type { RouteDefinition } from "@solidjs/router";
/**
* Refine a Type
* @example
* ```ts
* type Refined = Refine<{ foo: string, bar: unknown[] }, { foo: `${number}` }>
* // ^? { foo: `${number}`, bar: unknown[] }
* ```
*/
@sylvaindethier
sylvaindethier / is_array.sh
Last active September 6, 2017 23:50 — forked from coderofsalvation/is_array.bash
check if variable is array, returns 0 on success, 1 otherwise
## Check if variable is array
# @param mixed
# @return integer 0 on success, 1 otherwise
#
# @example
# value=("i'm an array" "and that's my 2nd value")
# if is_array value; then
# echo 'value is an Array'
# else
# echo 'value is NOT an Array'
@sylvaindethier
sylvaindethier / server.js
Created June 26, 2017 09:36
NodeJS Express server for SPA
// Express
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const PORT = 9000;
const STATIC = path.resolve(__dirname, 'dist');
const INDEX = path.resolve(STATIC, 'index.html');
@sylvaindethier
sylvaindethier / post-merge
Last active May 20, 2016 09:19 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@sylvaindethier
sylvaindethier / release.sh
Last active July 17, 2017 21:29
NPM Release
#!/bin/bash
set -e
# -e: Exit immediately if a pipeline [...] returns a non-zero status.
# @see: https://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin-1
## prevent runing script outside the repo root
if ! [ -e scripts/release.sh ]; then
echo >&2 "Please run scripts/release.sh from the repo root"
exit 1
@sylvaindethier
sylvaindethier / gist:046daf1cc24006c7a243
Created February 1, 2016 18:18
Verifying that +sdethier is my blockchain ID. https://onename.com/sdethier
Verifying that +sdethier is my blockchain ID. https://onename.com/sdethier
@sylvaindethier
sylvaindethier / odoo8-install.md
Created December 8, 2014 22:10
Odoo8 (OpenERP) installation on Ubuntu 14.04

1. Update OS

sudo apt-get update && sudo apt-get upgrade

2. Create the Add Odoo user (own & run application)

sudo adduser --system --home=/opt/odoo --group odoo

3. Install & configure PostgreSQL

sudo apt-get install postgresql sudo su - postgres createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo

@sylvaindethier
sylvaindethier / textarea-auto-height-adjust.html
Created October 17, 2014 11:23
Auto adjust Textarea height
<textarea data-adaptheight rows="3" cols="40" placeholder="Your input" style="padding: 16px; line-height: 1.5;"></textarea>
<script>
(function() {
function adjustHeight(textareaElement, minHeight) {
// compute the height difference which is caused by border and outline
var outerHeight = parseInt(window.getComputedStyle(el).height, 10);
var diff = outerHeight - el.clientHeight;
// set the height to 0 in case of it has to be shrinked
el.style.height = 0;