Skip to content

Instantly share code, notes, and snippets.

View jeremyben's full-sized avatar
🐔
NaN hopefully.

Jeremy Bensimon jeremyben

🐔
NaN hopefully.
  • France
View GitHub Profile
@jeremyben
jeremyben / ts-build-api.ts
Last active April 6, 2024 19:38
Typescript programmatic build with tsconfig.json (run with `ts-node -T`)
import * as path from 'path'
import ts from 'typescript'
function build(
override: {
compilerOptions?: ts.CompilerOptions
include?: string[]
exclude?: string[]
files?: string[]
extends?: string
@jeremyben
jeremyben / myapp.service
Last active February 20, 2024 06:07
systemd socket activation
# https://www.freedesktop.org/software/systemd/man/systemd.unit.html
[Unit]
Description=My App
After=network.target
# https://www.freedesktop.org/software/systemd/man/systemd.exec.html
[Service]
Type=simple
# https://www.freedesktop.org/software/systemd/man/systemd.exec.html#WorkingDirectory=
WorkingDirectory=-/srv/app/
@jeremyben
jeremyben / proper-fork-node.md
Last active August 9, 2023 02:09
Proper fork workflow for a node module repo that does'nt want to merge your perfectly fine pull request.

Fork it

Clone your fork :

git clone git@github.com:YOU/FORK
@jeremyben
jeremyben / jest-coverage-badges.ts
Last active January 26, 2022 05:38
Get shields.io badges for jest coverage.
// Make sure you have json-summary as a coverage reporter in your jest config.
// coverageReporters: ['json-summary', 'text', 'lcov']
import { readFileSync, mkdirSync, writeFileSync } from 'fs'
import { join } from 'path'
import { get } from 'https'
import { ok } from 'assert'
Promise.resolve().then(async () => {
const outputDir = join(process.cwd(), 'badges')
// https://www.typescriptlang.org/docs/handbook/advanced-types.html
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
/**
* Enlève les clés K de T (plus précis que le Omit natif).
*/
type OmitStrict<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
/**
* Récupère la version promisifiée d'une fonction.
@jeremyben
jeremyben / generators.scss
Last active October 8, 2019 08:36
Size Generators (margin, padding, font-size) #scss #stylus
// Generate class helpers for size properties such as margin, padding, font-size
// Usage :
// @include marginer(5, 60, 5)
// .mt5 will then add margin-top:5px to the element,
// and so on for each side, from 5px to 60px with a 5px step.
@mixin marginer($min, $max, $step) {
.mt#{$min} {margin-top: $min*1px}
.mb#{$min} {margin-bottom: $min*1px}
.ml#{$min} {margin-left: $min*1px}
@jeremyben
jeremyben / no-new.ts
Last active August 1, 2019 13:16
Make new keyword optional.
/**
* Gives a class constructor the possibility to be invoked
* with or without the `new` keyword, like built-in constructors.
*
* @param class_ class whose constructor will be proxified.
* @param constructorName if we need an accurate `constructor.name` property.
*/
export function makeNewOptional<C extends new (...args: any[]) => any>(class_: C, constructorName?: string) {
type NoNew<T extends C> = (...args: ConstructorParameters<T>) => InstanceType<T>
{
"$id": "https://lerna.js.org/",
"type": "object",
"properties": {
"version": {
"$id": "/properties/version",
"type": "string",
"description": "The current version of the repository.",
"examples": [
"1.1.3"
/**
* Defines a getter on a specified object that will be created upon first use.
*
* https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/XPCOMUtils.jsm#defineLazyGetter()
* https://dxr.mozilla.org/mozilla-central/source/js/xpconnect/loader/XPCOMUtils.jsm#120
*/
function defineMemoizedGetter(object: any, prop: string, fn: Function) {
let redefining = false
Object.defineProperty(object, prop, {
@jeremyben
jeremyben / _functions.scss
Created December 11, 2018 11:33
Sass Functions
/**
* Clamp number between min and max
*/
@function clamp($value, $min, $max) {
@return if($value > $max, $max, if($value < $min, $min, $value));
}
/**
* Get a list from all possible abbreviations of a string
* Ex : abbr(yolo) => (y, yo, yol, yolo)