Skip to content

Instantly share code, notes, and snippets.

George Mauer togakangaroo

Block or report user

Report or block togakangaroo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View timer.specs.js
import { expect } from 'chai'
import { useFakeTimers } from 'sinon'
const createStopWatch = ({ setInterval, clearInterval, Date} = global) => {
const createDisplays = (main, laps = []) => ({main, laps})
let resumeTime
let nextToggle
let currentInterval = null
let prePauseMs = 0
View timer.specs.js
import { expect } from 'chai'
import { useFakeTimers } from 'sinon'
const createStopWatch = () => {
const createDisplays = (main, laps = []) => ({main, laps})
let startTime
const sw = {
displays: createDisplays(null),
toggle: () => {
sw.displays = createDisplays(0)
View timer.specs.js
import { expect } from 'chai'
import { useFakeTimers } from 'sinon'
const createStopWatch = () => {
const createDisplays = (main, laps = []) => ({main, laps})
const sw = {
displays: createDisplays(null),
toggle: () => {
sw.displays = createDisplays(0)
},
View timer.specs.js
describe(`Stopwatch`, () => {
let clock
beforeEach(() => clock = useFakeTimers())
afterEach(() => clock.restore())
describe(`new instance`, () => {
let sw
beforeEach(() => sw = createStopWatch())
it(`shows nothing on main display`, () => expect(sw.displays.main).to.equal(null))
it(`shows no laps`, () => expect(sw.displays.laps).to.deep.equal([]))
View timer.specs.js
const createStopWatch = () => {
const createDisplays = (main, laps = []) => ({main, laps})
const sw = {
displays: createDisplays(null)
}
return sw
}
View timer.specs.js
import { expect } from 'chai'
describe(`Given a stopwatch`, () => {
let sw
beforeEach(() => sw = createStopWatch())
it(`shows nothing on main display`, () => expect(sw.displays.main).to.equal(null))
it(`shows no laps`, () => expect(sw.displays.laps).to.deep.equal([]))
})
View dp-string-gcd.org

Greatest Common Divisor of Strings

From the Operation Code Slack

Problem statement:

For strings S and T, we say “T divides S” if and only if S = T + ... + T  (T concatenated with itself 1 or more times)
Return the largest string X such that X divides str1 and X divides str2.
```
Input: str1 = "ABCABC", str2 = "ABC"
@togakangaroo
togakangaroo / daily programmer gcd of strings.html
Created Oct 14, 2019
an example of doing an op-code #daily-programmer challenge with literate coding
View daily programmer gcd of strings.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2019-10-14 Mon 12:29 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>&lrm;</title>
<meta name="generator" content="Org mode" />
View index.html
<style id="jsbin-css">
ul {
list-style-type: none;
padding: 0;
display: inline-flex;
font-size: 50px;
outline: 1px solid red;
width: 5em;
overflow: hidden;
}
View index.html
<style id="jsbin-css">
section {
overflow: hidden;
background-color: teal;
height: calc(5 * 2.6ex);
line-height: 2.6ex;
}
section p {
float: right;
margin: 0;
You can’t perform that action at this time.