Skip to content

Instantly share code, notes, and snippets.

View cellog's full-sized avatar

Gregory Beaver cellog

View GitHub Profile
@cellog
cellog / generic-inference1.ts
Created August 30, 2019 19:12
Inferring a type with a generic
// the example from typescript's docs
// The type T is never explicitly specified and can be any type that supports keyof
function getProperty<T, K extends keyof T>(obj: T, key: K) {
return obj[key];
}
let x = { a: 1, b: 2, c: 3, d: 4 };
getProperty(x, "a"); // okay
getProperty(x, "m"); // error: Argument of type 'm' isn't assignable to 'a' | 'b' | 'c' | 'd'.
@cellog
cellog / inferred.ts
Created August 30, 2019 18:56
Basic Typescript Type Inference
// basic type inference
function inferred() {
const a = 'hi'
return a
}
// inferred from interface definition
interface DefinesTypes {
inferred: (first: number, second: string) => number
}
@cellog
cellog / Mailbox.ts
Created July 17, 2019 23:41
Data Iframe Mailbox
import BlockchainHandler from './blockchainHandler/BlockchainHandler'
import {
ConstantsType,
BlockchainData,
FetchWindow,
SetTimeoutWindow,
} from './blockchainHandler/blockChainTypes'
import { isValidPaywallConfig } from '../utils/validators'
import { PaywallConfig, PurchaseKeyRequest } from '../unlockTypes'
import { IframePostOfficeWindow } from '../windowTypes'
@cellog
cellog / setupBlockchainHandler.ts
Created July 17, 2019 00:21
Proof-of-Concept - simpler blockchain Handler with no cache
import { PaywallConfig, Locks, Lock, Transactions } from '../../unlockTypes'
import { EventEmitter } from 'events'
import linkKeysToLocks from './linkKeysToLocks'
import { POLLING_INTERVAL } from '../../constants'
type Web3ProviderType = string | Object
export interface WalletServiceType extends EventEmitter {
ready: boolean
connect: (provider: Web3ProviderType) => Promise<void>
@cellog
cellog / 2nd build
Created March 11, 2019 20:47
2nd build
gregorybeaver@Gregorys-MacBook-Pro ~/Documents/GitHub/unlock (greg-1882-show-lock-int-test) $ scripts/build-image.sh unlock
Sending build context to Docker daemon 89.34MB
Step 1/53 : FROM node:8.11.4-alpine
8.11.4-alpine: Pulling from library/node
a073c86ecf9e: Pull complete
db7179d8c6cd: Pull complete
66b9cfaecc8c: Pull complete
Digest: sha256:1c38d992f89ae389450bc69799a0f2b7d1f9f2e6c445080a4648448e6449e8e4
Status: Downloaded newer image for node:8.11.4-alpine
---> 8adf3c3eb26c
regorybeaver@Gregorys-MacBook-Pro ~/Documents/GitHub/unlock (greg-1882-show-lock-int-test) $ scripts/build-image.sh unlock
Sending build context to Docker daemon 89.34MB
Step 1/53 : FROM node:8.11.4-alpine
8.11.4-alpine: Pulling from library/node
a073c86ecf9e: Pull complete
db7179d8c6cd: Pull complete
66b9cfaecc8c: Pull complete
Digest: sha256:1c38d992f89ae389450bc69799a0f2b7d1f9f2e6c445080a4648448e6449e8e4
Status: Downloaded newer image for node:8.11.4-alpine
---> 8adf3c3eb26c
@cellog
cellog / asyncActions_keyPurchaseTransactions.js
Created February 20, 2019 19:20
Version 2 - key purchase
export function makeGetTransactionInfo({
web3,
transactionHash,
mineTransaction,
failTransaction,
}) {
const getTransactionInfo = async transaction => {
if (!transactionHash) return
const [blockNumber, blockTransaction] = await Promise.all([
web3.eth.getBlockNumber(),
@cellog
cellog / asyncActions_keyPurchaseTransactions.js
Created February 20, 2019 18:16
Version 1 - key purchase
export function sendNewKeyPurchaseTransaction({
to,
from,
data,
value,
gas,
wallet,
newTransaction,
mineTransaction,
failTransaction,
@cellog
cellog / asyncActions_keyPurchaseTransactions.js
Created February 20, 2019 17:46
Current useKeyPurchaseTransaction code
export function makeGetTransactionInfo({
web3,
transactionHash,
startTransaction,
mineTransaction,
failTransaction,
}) {
const getTransactionInfo = async transaction => {
if (!transactionHash) return
const [blockNumber, blockTransaction] = await Promise.all([
@cellog
cellog / codesandbox URL to try it out yourself
Created October 7, 2018 03:01
flatten array, alternate implementations with jest tests and in-browser performance test suite
https://codesandbox.io/s/73w2kq8mvj