Skip to content

Instantly share code, notes, and snippets.

View lehni's full-sized avatar

Jürg Lehni lehni

View GitHub Profile
@marxangels
marxangels / express-hot-reload.js
Last active September 10, 2023 03:59
A simple module-level hot-reload for my express web application with less than 200 lines of code.
import fs from 'fs'
import vm from 'vm'
import path from 'path'
/*
* cli command
* node --experimental-vm-modules express-hot-reload.js
*/
const ModuleCache = new Map()
@samthor
samthor / safari-nomodule.js
Last active February 14, 2024 02:54
Safari 10.1 `nomodule` support
// UPDATE: In 2023, you should probably stop using this! The narrow version of Safari that
// does not support `nomodule` is probably not being used anywhere. The code below is left
// for posterity.
/**
* Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will
* load <script nomodule> anyway. This snippet solve this problem, but only for script
* tags that load external code, e.g.: <script nomodule src="nomodule.js"></script>
*
* Again: this will **not** prevent inline script, e.g.:
@JacobDB
JacobDB / inline-svg-function.scss
Created January 26, 2017 17:45 — forked from B-iggy/inline-svg-function.scss
Inline SVG function [SASS]
// Replace letters
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@xiaolai
xiaolai / nvmrc
Created June 28, 2016 08:42
bash function for load .nvmrc automatically
# for nvm
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
elif [[ $(nvm version) != $(nvm version default) ]]; then
echo "Reverting to nvm default version"
nvm use default
@sekoyo
sekoyo / node-sass-functions.js
Last active May 31, 2019 23:38
node-sass external svg to inline
'use strict';
const path = require('path');
const fs = require('fs');
const types = require('node-sass').types;
function svgContentWrapper(svgContent) {
return `url('data:image/svg+xml;charset=UTF-8,${svgContent.replace(/\r?\n|\r/g, '')}')`;
}
@coolaj86
coolaj86 / README.md
Last active September 6, 2021 20:20
Fastest uuid generator for node.js

Now published as @root/uuid

This is started out as a curiosity, pasted as a gist but now, years later, I've come back to it because there are too many of these uuid modules out there and they're too complicated.

This, however, is easy to read and understand (for me, at least). Even its tests are dependncy and build-step free.

node-uuid vs crazy-uuid vs fast-uuid

@mrsarm
mrsarm / backup-pgbarman.sh
Created December 15, 2014 19:00
Script to backup PostgreSQL with Barman
#!/bin/bash
#
# Script to backup PostgreSQL with Barman.
#
# After the backup is performed, this script
# also delete the oldest backup found.
#
# See the `PG Barman` home page for more information:
# http://www.pgbarman.org
#