Skip to content

Instantly share code, notes, and snippets.

import { readFilePrms } from '../utils'
import { join } from 'path';
import { fromProgramString, IntCodeState, computeTillStop, pushInput } from '../intcode/index';
import prompt from 'prompt-promise';
type TPrepped = IntCodeState;
async function prep(input:string):Promise<TPrepped>{
return fromProgramString(input);
}
type TPart1 = number
@JoelCodes
JoelCodes / index.test.js
Created November 19, 2019 21:35
Demo of react-hooks-testing-library
import { useState, useEffect } from 'react';
import { renderHook } from '@testing-library/react-hooks';
function someHook(){
const [done, setDone] = useState(false);
useEffect(():void => {
setTimeout(():void => {
setDone(true);
}, 1000);
@JoelCodes
JoelCodes / index.js
Created September 24, 2019 21:06
Jison Demo
const {Parser} = require('jison');
const parser = new Parser(`
/* lexical grammar */
%lex
%%
\\s+ /* skip whitespace */
"var" return 'VAR'
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
import { RegionIso, CountryIso } from "./types";
export async function getCountryIsos():Promise<CountryIso[]> {
return [
{iso: "US", iso3: "USA", name: "United States"},
{iso: "CA", iso3: "CAN", name: "Canada"},
{iso: 'JP', iso3: 'JPN', name: 'Japan'}
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>DOM Events</title>
<style>
body, * {
font-size: 40px;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
@JoelCodes
JoelCodes / app.jsx
Created June 7, 2019 15:19
Incrementer Hook Example
import React, {Component} from 'react';
import {render} from 'react-dom';
// class IncrementContainer extends Component {
// constructor(props){
// super(props);
// this.state = {count: 0};
// this.increment = this.increment.bind(this);
// }
// increment(){
@JoelCodes
JoelCodes / README.md
Created June 7, 2019 15:18
Kitchen Sink Demo

Hooks Kitchen Sink

Examples of a few hooks.

  • npm install
  • npm start
import React from 'react';
export function IncrementerPresenter({count, increment}){
return <div>
<button data-pni-testid='increment' onClick={increment}>The Button</button>
{
count === 0 ? (<p>The button has not been pressed yet.</p>)
: count === 1 ? (<p>The button has been pressed once.</p>)
: (<p>The button has been pressed {count} times</p>)
}