Skip to content

Instantly share code, notes, and snippets.

View beardedtim's full-sized avatar
💭
I may be slow to respond.

Tim Roberts beardedtim

💭
I may be slow to respond.
View GitHub Profile
@beardedtim
beardedtim / createPosts.js
Created January 1, 2019 20:11
Create Markdown Posts for All markdown files in directory
const fs = require('fs')
const path = require('path')
const cheerio = require('cheerio')
const markdown = require('markdown-it')
const highlightjs = require('highlight.js')
const metaMD = require('markdown-it-meta')
const parser = markdown({
highlight: function (str, lang) {
if (lang && highlightjs.getLanguage(lang)) {
@beardedtim
beardedtim / index.md
Last active July 30, 2018 18:13
Creating a Ticket for Future Bug Fix

Creation of Tech Debt Ticket

Overview

When developing, there will comes times where we have to accept a bug in the system in order to develop and produce something else inside the system. While these times should be rare and well thought out, this document outlines the steps in order to create the ticket and capture it as future work.

Steps

  1. Create a JIRA ticket
  2. Tag with appropriate team
@beardedtim
beardedtim / promisfyMethods.js
Created July 13, 2018 15:47
Promisfy and bind methods that reference `this`
const { promisify } = require('util') // node module
/**
* Creates Promise-returning functions from Callback-taking functions
* and binds the function to the created object via creation, mapped
* via methods
*
* @example
*
* const obj = { get, set, del }
* const promisified = promisifyMethods({
@beardedtim
beardedtim / trial1.js
Created July 6, 2018 20:33
A stupid worm
const B = require('bambi')
const EARTH_WIDTH = 5
const EARTH_HEIGHT = 5
const EMPTY = 0
const FOOD = 2
const SEEN = 4
const SELF = 8
@beardedtim
beardedtim / readme.md
Created June 29, 2018 18:39
setting up a Typescript NPM Package
  • Install deps: yarn add -D typescript @types/jest jest ts-jest ts-node
  • Init Typescript: yarn run tsc --init
  • Create src directory: mkdir src
  • Edit tsconfig.json to be:
    {
    "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "sourceMap": true,
    
@beardedtim
beardedtim / index.js
Last active June 24, 2018 19:05
Buffer by some predicate, aggregate by some function
const readline = require('readline')
const fs = require('fs')
const { fromEvent, Observable } = require('rxjs')
const filepath = `./text.txt`
const rl = readline.createInterface({
input: fs.createReadStream(filepath)
})
const byLine = fromEvent(rl, 'line')

Generator Functions

What are they?

generator functions are a special type of functions in JavaScript that allows for exiting and re-entering of functions. Instead of a functions always running to completion, a generator function can be exited and re-entered many times via the yield keyword. Example:

const fn = () => {
  doSomething()
  doSomethingElse()
@beardedtim
beardedtim / Saga.md
Created June 21, 2018 18:26
Overview of Sagas

Redux Saga Overview

Why do we use it?

We need a way to do async and side-effect type things due to actions inside of a redux application. Examples would be we need to log a person into our system due to a LOG_USER_IN action or we want to ask the server for some data due to a FETCH_COMMENTS action. Redux does not offer us a clean way to do this.

What does it offer?

redux-saga offers us an interface and some helper functions for working with async and side-effect code via generator functions. Please see the generator functions docs for more information on generators in javascript.

@beardedtim
beardedtim / Outlook.md
Last active June 21, 2018 16:03
Overview of Outlook Code

Start

  • I would obviously start with README
  • Next, I would check out the file src/index.tsx as that is the start of our application
  • Look for ReactDOM.render, that is how we render a react component to a DOM element
  • We also see this thing called Office. That is some magic library that MSFT offers. I honestly know very little about it.

What is Rendered?

  • React is props => VNode
@beardedtim
beardedtim / Dockerfile
Created May 11, 2018 17:07
Basic Dockerfile/docker-compose for Nginx
# Set base image
FROM nginx
# Who run it?
LABEL MAINTAINER="Tim Roberts"
# Move nginx.conf to container
COPY ./nginx.conf /etc/nginx/nginx.conf