Skip to content

Instantly share code, notes, and snippets.

@tilleps
tilleps / gist:805d9144090b13cf1c161e38532af0e8
Last active October 2, 2023 17:37
Convert .env files to Docker .env
VAR_QUOTED="FOOBAR"
VAR_QUOTED_WITH_HASH="FOO#BAR"
VAR_QUOTED_WITH_HASH_SPACE="FOO #BAR"
VAR_QUOTED_WITH_COMMENT="FOOBAR" # COMMENT
VAR_QUOTED_WITH_COMMENT_NOSPACE="FOOBAR"# COMMENT
VAR_UNQUOTED=FOOBAR
VAR_UNQUOTED_WITH_HASH=FOO#BAR
#VAR_COMMENTED_OUT="FOO"
#VAR_COMMENTED_OUT_WITH_COMMENT="FOO" # BAR
@tilleps
tilleps / gist:185c81baa4b943f81d101a8b2a6b547b
Created September 7, 2023 09:37
PassportJS promise support workaround
//
// Add Promise support for PassportJS: req.logIn() and req.logOut()
//
import { promisify } from "node:util";
import passportHttpRequest from "passport/lib/http/request.js";
// Workaround: Convert to promises before passport.initialize()
app.use(function (req, res, next) {
req.logIn = promisify(passportHttpRequest.logIn);
req.logOut = promisify(passportHttpRequest.logOut);
@tilleps
tilleps / log-formatter.js
Created June 24, 2022 15:00
Log formatter
#!/usr/bin/env node
const EventEmitter = require("events");
const stdin = new EventEmitter();
stdin.on("line", console.error);
let buff = "";
<html>
<head>
<style>
* {
margin: 0;
}
</style>
</head>
<body>
<div style="display: flex; flex-direction: column; min-height: 100vh;">
@tilleps
tilleps / gist:d79a5213f59d4931c7cfc0e977477b3e
Last active February 29, 2020 06:17
Alternative to Git Squash
# https://stackoverflow.com/a/3143485/2424549
# create a new branch
git checkout -b new_clean_branch
# apply all changes
git merge original_messy_branch
# forget the commits but have the changes staged for commit
git reset --soft master
<body>
<div style="display: flex; flex-direction: column; min-height: 100vh; ">
<div style="flex-shrink: 0; overflow: auto;">
HEADER
</div>
<div style="flex-shrink: 0; overflow: auto;">
<div style="margin: 0 auto; align-self: center; overflow: auto; max-width: 420px; padding: 1rem 2rem; border-radius: 0.5rem; background: #eee;">
BANNER
</div>
</div>
@tilleps
tilleps / strict-routing.js
Created January 13, 2020 06:30
ExpressJS strict routing workaround
/*
Enforcing strict routing
https://github.com/expressjs/express/issues/2281
Use cases:
GET /strict -> noslash
GET /strict/ -> noslash (expect slash)
GET /strict// -> noslash (expect 404)
function test(a = foo(arguments)) {
console.log(a, typeof a);
}
function foo(args) {
console.log('foo', args)
}
console.log(test(undefined, undefined, undefined));
@tilleps
tilleps / gist:77c0721485a105e0e37230d8c867c66d
Created April 28, 2016 18:20
VueJS data() being called twice on load
var Component = Vue.extend({
template: "<div>Hello world</div>",
data: function () {
console.log('Component data()');
return {};
},
ready: function () {
@tilleps
tilleps / whiteboard-cleaner.sh
Created February 9, 2015 00:22
Whiteboard Cleaner Script
#!/bin/bash
# Whiteboard cleaner: http://ipestov.com/one-cool-gist-whiteboardcleaner/
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2