Skip to content

Instantly share code, notes, and snippets.

View Bamblehorse's full-sized avatar
🙃
Coding | Writing | Meditating 🙂

Jon Wood Bamblehorse

🙃
Coding | Writing | Meditating 🙂
View GitHub Profile
const templates = {
index: name => `// @flow
import React from 'react';
import './${name}.css';
// TODO: write rest of ${name} component
const ${name} = () => (
<div className="${name.toLowerCase()}">
<span>rest of component</span>
@Bamblehorse
Bamblehorse / autoComponent.js
Last active March 2, 2023 16:06
Call this script with 'node autoComponent.js' - nodemon works well too
const chokidar = require("chokidar");
const fs = require("fs");
const templates = {
index: name =>
`// @flow
import React from 'react';
import './${name}.css';
@Bamblehorse
Bamblehorse / .babelrc
Last active December 15, 2019 11:30
Create React App - flow / eslint / prettier / babel
{
"presets": [
"react",
"flow"
],
"retainLines": true
}
@Bamblehorse
Bamblehorse / index.js
Created June 14, 2018 17:06
Insult and Compliment giver
function getRandomInt(max) { // From MDN
return Math.floor(Math.random() * Math.floor(max));
}
const length = array => array.length
const verbs = ['smell', 'fart', 'look', 'move', 'eat', 'walk', 'talk', 'sleep', 'smile']
const presentSimpleVerbs = ['worries', 'sings', 'cooks', 'fidgets', 'wriggles', 'dances', 'runs', 'sets stuff on fire']
const nouns = ['house', 'dog', 'poop', 'worm', 'lawyer', 'little girl', 'piece of cheese', 'french poodle']
const timeRelatedAdverbs = ['always', 'never', 'sometimes', 'often', 'rarely', 'occasionally']
@Bamblehorse
Bamblehorse / m.js
Created April 23, 2018 20:57
Memoize
// https://mostly-adequate.gitbooks.io/mostly-adequate-guide/ch03.html#the-case-for-purity
const memoize = (f) => {
const cache = {};
return (...args) => {
const argStr = JSON.stringify(args);
cache[argStr] = cache[argStr] || f(...args);
console.log(cache) // added for checking out the cache
return cache[argStr];
};
window.c = (type, text) => {
let e = document.createElement(type)
e.innerText = text
return e
}
window.i = (c) => document.body.insertBefore(c,document.body.firstChild)
i(c('style', `*{animation: FadeIn 0.5s} @keyframes FadeIn{0% {opacity: 0;transform: translateX(-20px);}}`))