Skip to content

Instantly share code, notes, and snippets.

View visual-regression-testing.md

Visual Regression Testing with Jest

This is a walkthrough of how to set up Visual Regression Testing with Jest for an application created with create-react-app.

The following walkthrough uses React as an example, but the approach should work for any modern frontend library! I assume it can be used with Angular, Vue, Cycle.js and more.

This gist walks you through a create-react-app application as an example of how to set up Visual Regression Testing in Jest using libraries I wrote recently which enable this: jsdom-screenshot, jest-transform-css and jest-transform-file.

View gist:cd8599c5f06ff9db8335c78ba6b049ca
chrome.proxy.settings.set({
value: {
mode: 'pac_script',
pacScript: {
data:data
}
},
scope: 'regular'
}, function(){
// console.log('set pac scripts result:',arguments);
View cache-obs.ts
function cache<Query, Result>(
factory: (query: Query) => Observable<Result>,
cache: Map<Query, Result> = new Map()): (query: Query) =>
Observable<Result> {
const subject = new Subject<Result>();
return query => {
if (cache.has(query)) {
subject.next(cache.get(query));
} else {
factory(query).subscribe(results => {
@kolodny
kolodny / post.md
Created Apr 17, 2018
Swift State Machine
View post.md

Fully Exhaustive Swift State Machine

The following is a nice Swift pattern to make a vanilla Swift state machine:

class Machine {
  enum State {
    case foo
    case bar(String)
    case baz(Int)
View introduction-to-parser-combinators.md

In this tutorial we're going to build a set of parser combinators.

What is a parser combinator?

We'll answer the above question in 2 steps

  1. what is a parser?
  2. and.. what is a parser combinator?

So first question: What is parser?

View Infrastructure.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@kolodny
kolodny / cpu-percent.js
Created Nov 26, 2017 — forked from pmuellr/cpu-percent.js
get CPU usage percent for a process in node, using proposed `process.cpuUsage()` function
View cpu-percent.js
'use strict'
// see: https://github.com/nodejs/node/pull/6157
var startTime = process.hrtime()
var startUsage = process.cpuUsage()
// spin the CPU for 500 milliseconds
var now = Date.now()
while (Date.now() - now < 500)
View typings\immutability-helper\index.d.ts
// https://github.com/kolodny/immutability-helper
/** Declaration extension point */
declare namespace ImmutabilityHelper {
interface CustomOperators<T> {
/* $someShit?: T */
/* $moreShit?: T */
}
}
View args.sh
#!/bin/sh
set -euo pipefail
#declare valid arguments here
bar=
baz=
function parse_args() {
args=()
@kolodny
kolodny / closer.js
Last active Oct 23, 2016
Brace closer
View closer.js
module.exports = closer;
function closer(codeString) {
var lines = codeString.split('\n');
var lastIndent = 0;
var currentScope = { indent: 0, children: [] };
for (lineIndex = 0; lineIndex < lines.length; lineIndex++) {
var line = lines[lineIndex];
var currentIndent = /^\s*/.exec(line)[0].length;
if (/^\s*\s*$/.test(line)) {
You can’t perform that action at this time.