Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Wright joejag

View GitHub Profile
@joejag
joejag / marking.md
Last active Aug 4, 2020
Example of how to mark a technical test
View marking.md

Tech Test Marking Guide

For a given test exercise.

Out of 22 points.

  1. It works: The code implements the specification (8 points, meets spec is 8 - reduce the score for missing parts or bugs found)

  2. The code is easy to read (4 points)

@joejag
joejag / bbc_perf_bug.md
Last active Jun 10, 2020
Hello BBC, please fix a CSS bug that causes high CPU usage on your site
View bbc_perf_bug.md

I continuously get high CPU usage on visiting http://news.bbc.co.uk/. I've got a low spec machine, so I notice these things. I've tracked this down to a CSS bug that you have on your news page.

After downloading the homepage and chopping things up, I managed to find the culprit.

Halfway down the some extra styling is applied by: Morph.initStyles = function () {} function.

It applies about 45 extra pieces of styling into the page. Four of these rules result in constant CPU usage. They are:

  • "<style>@-webkit-keyframes gs-pulse{0%{opacity:1}50%{opacity:.3}to{opacity:1}}@keyframes gs-pulse{0%{opacity:1}50%{opacity:.3}to{opacity:1}}.gs-c-live-pulse{font-weight:700;text-transform:uppercase}.gs-c-live-pulse--news{color:#bb1919}.gs-c-live-pulse--sport{color:#2866f6}.gs-c-live-pulse--sport-light{color:#0186ff}.gs-c-live-pulse__icon{position:relative}.gs-c-live-pulse__icon-center{position:absolute;top:0;right:0;bottom:0;left:0;will-change:opacity;-webkit-animation:gs-pulse 1.7s ease infinite;animation:gs
View example.js
import useWhyRerender from './whyRerender'
const MyComponent = props => {
// any states
const [error, setError] = React.useState(false)
// add interesting things to track
useWhyRerender({
...props,
error
View checkDiff.js
const highlightDifferences = (props, prevProps) => {
console.log('RERENDER DIFF!')
const now = Object.entries(props)
const added = now.filter(([key, val]) => {
if (prevProps[key] === undefined) return true
if (prevProps[key] !== val) {
console.log(`${key}
- ${JSON.stringify(val)}
+ ${JSON.stringify(prevProps[key])}`)
@joejag
joejag / watch.sh
Created Apr 22, 2020
Run with ./watch.sh <your normal command>
View watch.sh
#!/bin/bash
while true; do
clear
date
$*
sleep 2
done
@joejag
joejag / BowlingStreams.java
Created Apr 16, 2020
Bowling kata using streams
View BowlingStreams.java
package bowls;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class BowlingStreams {
@joejag
joejag / novel.md
Created Mar 23, 2020
Innovation and Learning team
View novel.md
View best.txt
================================================================================
["1871-72", "1872-73", "1873-74"] Wanderers 4
["1872-73", "1873-74", "1874-75"] Wanderers 2
["1873-74", "1874-75", "1875-76"] Oxford University 2
["1874-75", "1875-76", "1876-77"] Wanderers 4
["1875-76", "1876-77", "1877-78"] Wanderers 6
["1876-77", "1877-78", "1878-79"] Wanderers 4
["1877-78", "1878-79", "1879-80"] Wanderers 2
["1878-79", "1879-80", "1880-81"] Old Etonians 2
["1879-80", "1880-81", "1881-82"] Clapham Rovers 2
You can’t perform that action at this time.