Skip to content

Instantly share code, notes, and snippets.

View alecmerdler's full-sized avatar

Alec Merdler alecmerdler

View GitHub Profile
@alecmerdler
alecmerdler / web-worker.ts
Last active July 16, 2018 20:54
Functional Web Worker Utilities
/**
* Service worker utilities.
* Inspired by https://github.com/deebloo/worker.
*/
export type $worker = (fn: (event: MessageEvent) => void) => Worker;
export const $worker: $worker = fn => {
const blob: Blob = new Blob(['self.onmessage=', fn.toString(), ';'], {type: 'text/javascript'});
const url: string = URL.createObjectURL(blob);
const worker: Worker = new Worker(url);
@alecmerdler
alecmerdler / async.spec.ts
Last active September 1, 2017 07:37
Async React Component in TypeScript
import * as React from 'react';
import { mount, ReactWrapper } from 'enzyme';
import { AsyncComponent } from '../../../public/components/utils/async';
describe('AsyncComponent', () => {
let wrapper: ReactWrapper;
const Foo = (props: {className: string}) => <div id={fooId} className={props.className} />;
const fooId = 'fooId';
const loadingBoxSelector = '.cos-status-box';
@alecmerdler
alecmerdler / component.tsx
Created March 22, 2018 16:50
Does TSX suck?
import * as React from 'react';
import h = React.createElement;
export const TestComponentTSX: React.SFC<TestComponentProps> = (props) => {
return <div className="col-md-3">
{ props.items.map((item, key) => <span key={key}>
Item {key + 1}: {item.name}
</span>) }
<input />
<button onClick={() => console.log('Clicked!')}>Create</button>
git filter-branch -f --env-filter '
if test "$GIT_AUTHOR_EMAIL" != "$GIT_COMMITTER_EMAIL"
then
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
fi
if test "$GIT_AUTHOR_NAME" != "$GIT_COMMITTER_NAME"
then
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
fi' master..HEAD
const { execSync } = require('child_process');
/**
* Create a bunch of configmaps for load testing.
*/
new Array(10000).fill(0).forEach((_, i) => {
const configMap = {
apiVersion: 'v1',
kind: 'ConfigMap',
metadata: {
@alecmerdler
alecmerdler / cluster.crd.yaml
Last active August 29, 2018 15:07
Operators packaged for OLM
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: clusters.rook.io
spec:
group: rook.io
version: v1alpha1
scope: Namespaced
names:
kind: Cluster
@alecmerdler
alecmerdler / couchbasecluster-suggestions.md
Created October 12, 2018 17:25
Problems with CouchbaseCluster CRD

Issues with CouchbaseCluster CRD

Noticing some inconsistencies with the CRDs of other Operators, which makes it difficult to integrate cleanly with the OLM UI.

  1. status.members should look like:
status:
 members:
@alecmerdler
alecmerdler / clusterloggings.v0.0.1.clusterserviceversion.yaml
Last active November 9, 2018 16:46
Creation of Cluster Logging Operator and Elasticsearch Operarator SVCs
apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
metadata:
name: clusterlogging.v0.0.1
namespace: placeholder
spec:
displayName: Cluster Logging Operator
description: |
The Cluster Logging Operator for OKD provides easy means for configuring and managing your aggregated logging stack.
@alecmerdler
alecmerdler / app.ts
Created November 5, 2018 04:05
Playing around with Deno
/**
* Opaque type that can have a meaning.
*/
enum Subject {
life = 'life',
dreams = 'dreams',
}
export const meaningFor = (subject: Subject) => {
switch (subject) {
@alecmerdler
alecmerdler / typescriptify-redux.md
Created November 30, 2018 20:32
TypeScript-ify Redux Store

Description

Defines the app's Redux store using TypeScript to add type safety and improve developer documentation.

The general strategy to get TypeScript to work nicely with ImmutableJS is to:

  1. Define ReducerNameStateData type (the raw, JSON-serializable state)
export type MyReducerStateData = {
  currentUser: string;
 data: {