Skip to content

Instantly share code, notes, and snippets.

View JustenRickert's full-sized avatar

jsasz JustenRickert

View GitHub Profile
import React from 'react';
function HexagonSvg({ attrs = {}, position: [x0, y0], length }) {
const p1 = [-1 / 3, 0];
const p2 = [-1 / 6, -1 / 3];
const p3 = [1 / 6, -1 / 3];
const p4 = [1 / 3, 0];
const p5 = [1 / 6, 1 / 3];
const p6 = [-1 / 6, 1 / 3];
const M = ([x, y]) => `M ${x0 + length * x} ${y0 + length * y}`;
module.exports = {
'*.js': absolutePaths => {
return `jest ${absolutePaths.map(filename => filename.slice(0, -3) + '.test.js').join(' ')}`
}
}
import fs from "fs";
import { uniq } from "lodash";
import { parse } from "@babel/parser";
import traverse from "@babel/traverse";
const getRelevantFiles = (filename, relevantFiles = []) => {
if (relevantFiles.includes(filename)) return relevantFiles;
const ast = parse(fs.readFileSync(filename, "utf-8"));
traverse(ast, {
ImportDeclarations(path) {
{
"scripts": {
"test": "jest"
},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
},
class WorkRunner {
constructor(fork, { actionCreator, messageCreator }) {
this.fork = fork;
this.actionCreator = actionCreator;
this.messageCreator = messageCreator;
this.fork.on("message", this.actionCreator);
}
send(msg) {
@JustenRickert
JustenRickert / leibnizAndE.ts
Last active April 13, 2019 22:19
Leibiz formula for pi
import { isArray, isString, isFunction } from "lodash";
const { performance } = require("perf_hooks");
type Parameters<Fn> = Fn extends (...args: infer T) => any ? T : never;
const trampoline = <Fn extends (...args: any[]) => any>(
fn: Fn,
...args: Parameters<Fn>
) => {
public class RoachPopulation {
private static double initialPopulation;
RoachPopulation(double initialPopulation) {
this.initialPopulation = initialPopulation;
}
public void waitForIt() {
initialPopulation *= 2.0;
}

updateIn/updateInto

By Procedure

const byProcedure = <T>(arrays: T[][], update: { i: number; j: number; value: T }) => {
  const retArr: T[][] = [];
  for (const i in arrays) {
    retArr.push([]);
    for (const j in arrays[i]) {
      if (Number(i) === update.i && Number(j) === update.j) {
@JustenRickert
JustenRickert / selector-testing.md
Last active July 19, 2018 16:45
jest running problem

The Problem

JavaScript doesn't want to support mutual recursion within our testing environment. So, the below function fails while running our test suite.

const selectPersistedContext = (state: RootState) => {
  const advisors = selectAdvisors(state); // selectAdvisors undefined
  const context = selectPersistedContext(state); // selectPersistedContext undefined
  const { fmid } = context;
  if (fmid) {
    const advisor = advisors.find(advisor => advisor.fmid === fmid);
(setq org-capture-templates
'(("n" "Task" entry (file+headline "~/life/org/inbox.org"
"Inbox")
"* TODO %? \n%i - Task created on %U \\\\" :empty-lines 1)
("j" "Journal" entry (file+datetree "~/life/org/journal.org")
"* %<%H:%M> %?\n" :empty-lines 1)))