Skip to content

Instantly share code, notes, and snippets.

const ESCAPE_REGEXP = new RegExp(String.raw`[.*+?^=!:\${}()|[\]\/\\]`, 'g');
const escapeRegexp = (string: string) => string.replace(ESCAPE_REGEXP, '\\$&');
export const mkTrimMargin = (marginPrefix: string) => {
const whiteSpaceOtherThanLfRegexp = String.raw`[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]`;
const headingWhitespacesRegexp = new RegExp(
String.raw`^${whiteSpaceOtherThanLfRegexp}*\n`,
'',
@dayflower
dayflower / decryptOpenSSL.ts
Last active November 7, 2023 00:49
Decrypt files encrypted by OpenSSL in TypeScript
import crypto from 'crypto';
import { openSslKdf } from './openSslKdf.ts';
export const decryptOpenSslEncryptedBuffer = async ({
data,
secret,
digestAlgorithm,
keySize,
ivSize,
algorithm = 'AES-CBC',
@dayflower
dayflower / index.ts
Last active May 1, 2023 10:11
node-fetch with proxy
import { HttpProxyAgent } from 'http-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch from 'node-fetch';
function proxyAgent(targetUrl: string, proxyUrl: string) {
const url = new URL(targetUrl);
if (url.protocol.toLowerCase() === 'https:') {
return {
agent: new HttpsProxyAgent(proxyUrl),
};
@dayflower
dayflower / index.test.js
Created May 27, 2022 14:01
Jest: Use async/await in describe()
/**
* @template T
* @param {() => Promise<T>} func
* @returns {() => T}
*/
function beforeAllAsync(func) {
let r;
beforeAll(async () => {
r = await func();
@dayflower
dayflower / monitor.js
Last active July 9, 2020 07:45
PM2 print metrics
const pm2 = require('pm2');
pm2.connect(true, (err) => {
if (err) {
console.error(err);
process.exit(2);
}
pm2.Client.executeRemote('getMonitorData', {}, (err, list) => {
if (err) {
@dayflower
dayflower / gist:0b8fd99554bb6a6443578f53837dd9bc
Last active March 21, 2020 12:17
Real smart tab for CodeMirror
// https://github.com/codemirror/CodeMirror/issues/988#issuecomment-549644684
extraKeys: {
Tab: (cm) => {
if (cm.getMode().name === 'null') {
cm.execCommand('insertTab');
} else {
if (cm.somethingSelected()) {
cm.execCommand('indentMore');
} else {
cm.execCommand('insertSoftTab');

Keybase proof

I hereby claim:

  • I am dayflower on github.
  • I am dayflower (https://keybase.io/dayflower) on keybase.
  • I have a public key ASCJze5TXfpmf23dPZGqW4BIluxOuDb2uU61SJs-civVRAo

To claim this, I am signing this object:

import com.nimbusds.jose.crypto.DirectDecrypter
import com.nimbusds.jwt.EncryptedJWT
import com.nimbusds.jwt.JWTParser
import org.jose4j.jwe.JsonWebEncryption
import org.jose4j.jwk.JsonWebKey
import org.jose4j.jwt.JwtClaims
import java.util.Base64
import javax.crypto.spec.SecretKeySpec
const val SECRET = "Fdh9u8rINxfivbrianbbVT1u232VQBZYKx1HGAGPt2I"
@dayflower
dayflower / ab-ver.pl
Last active September 17, 2017 13:23
Update version section of Android backup file
#!perl
=head1 DESCRIPTION
Update version of Android backup file in-place.
=head1 SYNOPSIS
% ab-ver.pl [-s <version>] <Android backup file> ...
body {
background-color: #eeffcc;
}
a,
.btn-link {
color: #6cc644;
}
.pagehead,