Skip to content

Instantly share code, notes, and snippets.

View matteocng's full-sized avatar
😀

matteocng

😀
View GitHub Profile
@viT-1
viT-1 / how-to-jest-esm.md
Last active April 9, 2023 20:50
#gist-bookmark #jest #test #esm #alias #js
@jeroenvollenbrock
jeroenvollenbrock / aws-cloudfront-basic-auth.js
Last active April 8, 2024 15:51
AWS-CloudFront-basic-auth
var USERS = {
protecteddir: [{
username: 'user',
password: 'pass',
}],
};
//Response when auth is not valid.
var response401 = {
statusCode: 401,
@Electroid
Electroid / rollup.config.js
Created February 12, 2021 23:45
Rollup config for ESM Cloudflare Workers
import commonjs from '@rollup/plugin-commonjs'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import copyAssets from 'rollup-plugin-copy-imported-assets'
import nodePolyfills from 'rollup-plugin-node-polyfills'
import nodeGlobals from 'rollup-plugin-node-globals'
// https://rollupjs.org/guide/en/#configuration-files
export default {
@qwtel
qwtel / cf-storage-area.ts
Last active November 8, 2021 01:28
kv-storage implementation for Cloudflare Workers
import { Base64Encoder, Base64Decoder } from 'base64-encoding';
const PREFIX = 'data:application/octet-stream;base64,';
const b64e = new Base64Encoder();
const b64d = new Base64Decoder();
const encodeKey = (key: string | BufferSource) => typeof key !== 'string' ? PREFIX + b64e.encode(key) : key;
const decodeKey = (key: string) => key.startsWith(PREFIX) ? b64d.decode(key.substr(PREFIX.length)) : key;
@mzpqnxow
mzpqnxow / noip6.ovpn
Last active April 21, 2023 08:22
OpenVPN client when IPv6 is disabled
# If your system has IPv6 disabled, OpenVPN will error out when receiving
# route6 and ip6 information from the server (assuming it supports IPv6)
# Add the following to your OpenVPN configuration to allow the connection
# to succeed by ignoring them
#
# You'll see the following in your error messages after the session is established
# if you're having this issue. It is fatal and the tunnel will fail to come up
#
# ...
# do_ifconfig, tt->did_ifconfig_ipv6_setup=1
@yiays
yiays / openssh-for-windows-proxyjump-guide.md
Last active March 25, 2024 06:21
How to setup OpenSSH for Windows for ProxyJumping

ProxyJumping

Introduction

ProxyJumping is a method used to get access to a terminal in a private network via SSH.

First, you SSH into a JumpGate (a SSH server exposed to the internet), and then use that JumpGate to pass through a SSH connection to a machine on the JumpGate's local network. By the end of this guide, you should be able to seamlessly connect to a remote private host through a JumpGate with one parameter in a ssh command.

Security should always be paramount when establishing connections like this because the password of a JumpGate can and will be brute-forced by bots on the internet constantly.

Compatiblilty notes

The provided client-side commands are intended for PowerShell. Open PowerShell by right-clicking on the start menu button and selecting Windows Powershell.

@rstacruz
rstacruz / README.md
Last active April 23, 2024 00:19
Setting up Jest with ESM

Setting up Jest with ESM

Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.

Method A: Native Node.js support

Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules flag.

Install cross-env:

const HandlerRunner = require("serverless-offline/dist/lambda/handler-runner/index").default;
class OfflineInvalidate {
constructor(serverless, options) {
this.serverless = serverless;
this.hooks = {
"before:offline:start:init": (opts) => this.inject()
};
this.lastRunner = {};
}
@slikts
slikts / react-memo-children.md
Last active April 27, 2024 02:44
Why using the `children` prop makes `React.memo()` not work

nelabs.dev

Why using the children prop makes React.memo() not work

I've recently ran into a pitfall of [React.memo()][memo] that seems generally overlooked; skimming over the top results in Google just finds it mentioned in passing in a [React issue][regit], but not in the [FAQ] or API [overview][react-api], and not in the articles that set out to explain React.memo() (at least the ones I looked at). The issue is specifically that nesting children defeats memoization, unless the children are just plain text. To give a simplified code example:

const Memoized = React.memo(({ children }) => (<div>{children}</div>));
// Won't ever re-render
<Memoized>bar</Memoized>
// Will re-render every time; the memoization does nothing
@SarasArya
SarasArya / handler.js
Last active May 15, 2021 22:05
Serverless Sentry Error Handler example
// Node version 10.x AWS Lambda Serverless framework
const Sentry = require('@sentry/node'); // sentry version "@sentry/node": "^5.5.0",
Sentry.init({
dsn: 'https://randomstuff@sentry.io/1234567',
async beforeSend(event) {
console.log('\n Caught an exception \n');
return event;
},