Skip to content

Instantly share code, notes, and snippets.

View cvle's full-sized avatar

Vinh cvle

View GitHub Profile
@cvle
cvle / parseMarkup.ts
Last active January 13, 2020 22:49
Make Fluent work in IE11
// Wait for this to land: https://github.com/zloirock/core-js/pull/732
// Then use this custom markup parser in <LocalizationProvider> as <template> doesn't work in IE11.
const parser = new DOMParser();
function parseMarkup(str: string) {
const doc = parser.parseFromString(`<body>${str}</body>`, "text/html");
return Array.from(doc.body.childNodes);
}
### Keybase proof
I hereby claim:
* I am cvle on github.
* I am cvle (https://keybase.io/cvle) on keybase.
* I have a public key ASCX-4HrgTiKXO9jvtvQvDJMuYrj0YV5KHpuAaotBuoRkgo
To claim this, I am signing this object:
@cvle
cvle / expectAndFail.js
Last active May 31, 2019 17:44
Workaround for Jest Assertions not failing tests in a try/catch block
// Jest assertions will not fail if they live inside a try-catch block due to
// https://github.com/facebook/jest/issues/3917.
// This file returns a version of `expect` that fails
// the test immediately when an exception is thrown.
/**
* isPromise detects whether given object is a promise or not.
*/
const isPromise = obj =>
import React from "react";
type Omit<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>;
type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
<P extends TInjectedProps>(
component: React.ComponentType<P>
) => React.ComponentType<Omit<P, keyof TInjectedProps> & TNeedsProps>;
type DefaultingInferableComponentEnhancer<TInjectedProps> =
@cvle
cvle / http-mitm-proxy-example.js
Last active May 23, 2018 21:37
http-mitm-proxy example
const Proxy = require('http-mitm-proxy');
const proxy = Proxy();
const port = 8081;
const host = '0.0.0.0';
function appendToBody(chunk, s) {
return new Buffer(chunk.toString().replace(/<\/body>/g, s + '</body>'));
}
proxy.onError(function(ctx, err) {
@cvle
cvle / gist:283195454f02da4301d76bf08e8baff8
Created August 22, 2017 20:17
Search and Replace in files
find folder/ -type f -name '*.js' | xargs sed -i 's/addNotification/notify/g'
@cvle
cvle / gist:a911bec79eb3ab476403716d44cade55
Created July 20, 2017 20:47
Coral Talk Introspection
{
"data": {
"__schema": {
"queryType": {
"name": "RootQuery"
},
"mutationType": {
"name": "RootMutation"
},
"subscriptionType": {
@cvle
cvle / kvf-complex-example.sh
Last active July 28, 2016 13:59
kube-volume-freezer complex example.
#!/bin/bash
# This script performs a live snapshotting of 3 Volumes from 3 different deployments simultaneously.
set -Eeuo pipefail
GCLOUD=gcloud
KUBECTL=kubectl
KVFCTL="docker run --net host --rm wikiwi/kube-volume-freezer kvfctl"
NAMESPACE=default