Skip to content

Instantly share code, notes, and snippets.

View rockchalkwushock's full-sized avatar
🦮
Walking Tommie

Cody Brunner rockchalkwushock

🦮
Walking Tommie
View GitHub Profile
package config
import (
"log"
"os"
"github.com/spf13/viper"
)
type (
import { eachYearOfInterval, getMonth } from 'date-fns'
import currentData from './current.json'
// array
// obj.bio.gender Filter on gender only F
// obj.terms (Array) Filter on type only rep
// get start/end
const app = () => {
const women = (currentData as Array<unknown>).filter(
// @ts-ignore
val => val.bio.gender === 'F'
@rockchalkwushock
rockchalkwushock / ErrorBoundary.tsx
Last active December 1, 2021 17:49
Contra code challenge
import * as React from "react";
interface Props {
fallback: React.ReactElement;
}
interface State {
error: null | string;
hasError: boolean;
}
@rockchalkwushock
rockchalkwushock / encrypt-and-decrypt.js
Created November 24, 2021 19:29
Encrypt and decrypt objects in Node
import { createCipheriv, createDecipheriv, randomBytes } from 'crypto'
const iv = randomBytes(process.env.RANDOM_INTEGER)
const cipher = createCipheriv(process.env.ALGORITHM, process.env.SECRET_KEY, iv)
export const encrypt = (object) => {
const encrypted = Buffer.concat([cipher.update(JSON.stringify(object)), cipher.final()]);
return {
content: encrypted.toString('hex'),
iv: iv.toString('hex'),
@rockchalkwushock
rockchalkwushock / example.tsx
Created November 3, 2021 16:01
Example of using a Toggler component
import * as React from 'react'
type RenderProps = {
close: () => void
isOpen: boolean
open: () => void
toggle: () => void
}
type Props = {
import * as React from 'react'
import styled from 'styled-components'
import "./styles.css";
/**
* *Step 1:*
* - Render a list of items (*ul*) from the given *API endpoint*.
* - Create **<List />** and **<ListItem />** components. *(List renders ListItems)*.
* - Each *ListItem* needs to render the **id**, **title** and an **image** with the **thumbnailUrl**.
*/
@rockchalkwushock
rockchalkwushock / gotcha.rjson
Created August 10, 2020 21:24
DraftJS gotcha
[
"//": "DraftJS will return a single object with this signature.",
"//": "If it has not text that property will be empty and that is what 'hasText()' is checking.",
"//": "The immutable data struct still exists though, so we need to blow it away using 'Draft.EditorState.createEmpty()'."
{
"blocks": [
{
"key": "djgpq",
"text": "",
"type": "unstyled",
# Name of this workspace.
name: CI
# Listens for PR's being opened and updated.
on: pull_request
jobs:
# My job
review_code:
# Environment to execute in.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Poop</h1>
<div id="content"></div>
import { ApolloError } from 'apollo-boost'
// We may not need to pass the 'endpoint' through I forget what the ApolloError exposes for information.
export const onError (error: ApolloError, enpoint: string): void => {
// Add error logging service.
console.error(`Endpoint: ${endpoint}`, error)
}