Skip to content

Instantly share code, notes, and snippets.

View jtmthf's full-sized avatar

Jack Moore jtmthf

View GitHub Profile
@jtmthf
jtmthf / encrypt_decrypt.ts
Last active April 18, 2021 13:20 — forked from csanz/encrypt_decrypt.js
Simple String Encryption & Decryption with Node.js
import {createCipheriv, createDecipheriv} from "crypto";
const ALGORITHM = "aes-256-cbc";
const ENCODING = "utf8";
const DEFAULT_INITIALIZATION_VECTOR = "0";
const DEFAULT_SYMMETRIC_KEY = "d6F3Efeq";
function encrypt(value: string, key = DEFAULT_SYMMETRIC_KEY, iv = DEFAULT_INITIALIZATION_VECTOR) {
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
let crypted = cipher.update(value, ENCODING, "base64");
@jtmthf
jtmthf / index.ts
Created September 25, 2017 15:16
Object.observe Proxy polyfill
type ChangeType = 'add' | 'update' | 'delete' | 'reconfigure' | 'setPrototype' | 'preventExtensions';
interface ChangeObjectBase<T> {
object: T;
type: ChangeType;
}
interface ChangeObjectUpdateDelete<T> extends ChangeObjectBase<T> {
name: keyof T | '__proto__';
type: 'update' | 'delete' | 'setPrototype';
@jtmthf
jtmthf / semantic-ui-react.tsx
Created May 5, 2018 19:53
Semantic UI React Augmentation
import { Link } from 'react-router-dom'
<Menu>
<Menu.Item as={Link} to='/home'>
Home
</Menu.Item>
</Menu>
class Any<T = 'div'> extends Component<Props<T>> {
public static ofType<T>() {
return Any as Constructor<Any<T>>;
}
public render() {
const { is: Cmp = 'div', innerRef, ...props } = this.props as any;
return <Cmp ref={innerRef} {...props} />;
}
}
type TagProps<Tag extends keyof JSX.IntrinsicElements> = {
is: Tag;
innerRef?: JSX.IntrinsicElements[Tag]['ref'];
} & JSX.IntrinsicElements[Tag];
type StatelessComponentProps<P> = {
is: SFC<P>;
} & P;
type ComponentClassProps<T, P> = {
type Props<T> = T extends 'div'
? JSX.IntrinsicElements['div']
: T extends keyof JSX.IntrinsicElements
? TagProps<T>
: T extends ComponentType<infer P>
? ComponentProps<P> : never;
type Props<T> = T extends 'div'
? JSX.IntrinsicElements['div']
: T extends keyof JSX.IntrinsicElements
? TagProps<T>
: T extends Component<infer P>
? ComponentClassProps<T, P>
: T extends SFC<infer P> ? StatelessComponentProps<P> : never;
// rendering a plain div
<Any />; // -> <div />
// using props defined on a div
<Any style={{ color: 'red' }} />; // -> <div style={{ color: 'red' }} />
// Declaring a new Input type
const Input = Any.ofType<'input'>();
// Failure to pass literal 'input' to is will be a type failure
import * as React from 'react';
import { Component, ComponentClass, SFC } from 'react';
type Constructor<T = {}> = new (...args: any[]) => T;
type TagProps<Tag extends keyof JSX.IntrinsicElements> = {
is: Tag;
innerRef?: JSX.IntrinsicElements[Tag]['ref'];
} & JSX.IntrinsicElements[Tag];
const next = jest.fn();
const baseAction = {
type: OrderDetailsActionConstants.INITIATE_ORDER_DETAILS_RETRIEVAL,
orderId: 'orderId',
patientId: 'patientId',
encounterId: 'encounterId'
};
const action = Object.assign({}, baseAction, toRemove: 'toRemove');
serializeInitiateOrderDetailsRetrievalAction()(next)(action);