Skip to content

Instantly share code, notes, and snippets.

View wmertens's full-sized avatar

Wout Mertens wmertens

View GitHub Profile
@genki
genki / uint8array_serializer.ts
Last active February 28, 2024 07:11
The Uint8Array serializer over valid UTF-16 string.
// pack bytes into valid UTF-16 string
//
// strategy:
//
// * using ESC as the escape character
// * if there is ESC in the bytes, double it
// * if there is unmatched surrogate pair, mark it by the escape character
//
// 0x007f: escape, because it's rare but still only one utf-8 byte.
// To escape itself, use 0x007f 0x08ff (two bytes utf-8)
@wmertens
wmertens / wrap-sqlite-backup.sh
Last active October 6, 2022 09:52
Wrap a command with an SQLite read lock on given files so they can safely be backed up
#!/usr/bin/env bash
#
# This script wraps a command with a read lock on given SQLite databases
# Example: wrap-sqlite-backup.sh *.sqlite3 -- tar cvzf backup.tgz *.sqlite3
#
# Note that it doesn't check for errors, so it really only works in WAL mode.
# Updates that read from ${COPROC[0]} to check errors welcome.
#
# Wout.Mertens@gmail.com
# https://gist.github.com/wmertens/4df207197074f9cb93f003c1cb723b4c
@wmertens
wmertens / node-require-debug.js
Created February 8, 2022 22:36
spy on NodeJS require stack
// Require this in your program, or load it with node's -r flag
const Mod = require('module')
const req = Mod.prototype.require
let indent = ''
const rootRE = new RegExp(process.cwd(), 'g')
const stack = []
Mod.prototype.require = function() {
try {
const request = arguments[0]
@wmertens
wmertens / ssh-crypt.bash
Last active February 2, 2024 10:01
ssh-crypt: bash function to encrypt using ssh-agent and openssl
#!/usr/bin/env bash
#
# ssh-crypt
#
# Bash function to encrypt/decrypt with your ssh-agent private key.
# Requires the commands gzip, ssh-add, ssh-keygen and openssl.
#
# Uses bash-specific extensions like <<<$var to securely pass data.
#
# Wout.Mertens@gmail.com 2021-11-11 - MIT Licensed
@wmertens
wmertens / use-id.js
Created July 22, 2019 22:04
Hook for consistent auto-incrementing ids between SSR and browser. To use, wrap your app with <IdProvider> and call useId or useGetId
import React, {createContext, useContext, useRef} from 'react'
import PropTypes from 'prop-types'
const Id = createContext()
const useIdGetter = (prefix = 'id') => {
const ref = useRef()
if (!ref.current) {
const me = {id: 0, get: () => `${prefix}-${me.id++}`}
ref.current = me
@SaraVieira
SaraVieira / gist file.md
Last active December 5, 2023 11:59
The Origin of Furries

In this talk we will be all discussing the origin of the furry fandom. How we will thogheter create a new furry-in-js framework. We will going over how they have changed the current fandom world, our hearts and the js world in 5 very awesome minutes! This talk is to prove a point that stars mean nothing in this case.

https://reactiveconf.com/

@wmertens
wmertens / graphqlExpress.js
Created September 7, 2017 13:59
Add dataloaders to graphql context
import DataLoader from 'dataloader'
import {graphqlExpress} from 'graphql-server-express'
import schema from './schema'
import db from './database'
const contextFromReq = req => {
const {session} = req
const loaders = {}
const getLoader = (id, makeGetter) => {
export default function withMutation({name, args}) {
let mutation;
if (args) {
const args1 = _.map(args, (type, name) => `$${name}: ${type}`); // e.g. $url: String
const args2 = _.map(args, (type, name) => `${name}: $${name}`); // e.g. $url: url
mutation = `
mutation ${name}(${args1}) {
${name}(${args2})
@wmertens
wmertens / router.jsx
Last active August 10, 2017 11:14
Wrapper for react-router v4 with an API more to my tastes
import React, {Component, PropTypes} from 'react'
import {Link, Route as OrigRoute, Switch, Redirect, BrowserRouter as Router, withRouter} from 'react-router-dom'
// Subscribes a child to history updates, passing the current location as a prop
// This is needed to work around the React context API not updating all children
// See https://github.com/ReactTraining/react-router/issues/4629#issuecomment-284218493
export class LocationListener extends Component {
static contextTypes = {
history: PropTypes.object,
}
@tzmartin
tzmartin / m3u8-to-mp4.md
Last active April 16, 2024 22:32
m3u8 stream to mp4 using ffmpeg

1. Copy m3u8 link

Alt text

2. Run command

echo "Enter m3u8 link:";read link;echo "Enter output filename:";read filename;ffmpeg -i "$link" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $filename.mp4