Skip to content

Instantly share code, notes, and snippets.

View trevorblades's full-sized avatar
🌵
#AlwaysLearning

Trevor Blades trevorblades

🌵
#AlwaysLearning
View GitHub Profile
@trevorblades
trevorblades / new.js
Created May 11, 2019 21:58
compareStrings refactor
import maxBy from 'lodash/maxBy';
import {remove as removeDiacritics} from 'diacritics';
function prepareString(string) {
return removeDiacritics(string.toLowerCase());
}
export function compareStrings(value, ...solutions) {
const results = solutions.map(solution => {
let matches = 0;
export function getStreak(answers) {
let streak = 0;
for (const answer of answers) {
if (!answer.correct) {
break;
}
streak++;
}
import React from 'react';
const posts = [
{
id: 1,
from: 'XminionsniperX',
time: '21:30',
title: 'Welcome',
post: 'Welcome to the new Website everyone'
}
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600" rel="stylesheet">
</head>
<body style="margin: 0">
<table cellpadding="0" cellspacing="0" width="600" style="font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 15px; color: #191C23; margin: 0 auto;">
<tr>
<td style="background: #3F20BA; color: white; padding: 45px; padding-bottom: 36px; text-align: center;">
<img width="125" src="https://i.imgur.com/B68dwyf.png" alt="Apollo logo" />
<h2 style="font-weight: 300; margin: 0; margin-top: 25px; line-height: 1.3;">We're hosting the following events in May to help you get the most out of GraphQL and Apollo.</h2>
@trevorblades
trevorblades / index.js
Created June 27, 2019 22:40
gatsby-remark-transform-typescript
const visit = require('unist-util-visit');
const babel = require('@babel/core');
const ts = ['ts', 'tsx', 'typescript'];
const babelOptions = {
presets: [
[
'@babel/typescript',
{
allExtensions: true,
@trevorblades
trevorblades / ProductsList.js
Created July 19, 2019 18:18
Apollo render props vs. hooks (basic example)
function ProductsList() {
const {loading, error, data} = useQuery(LIST_PRODUCTS);
if (loading) return 'Loading...';
if (error) return error.message;
return (
<ul>
{data.products.map(product => (
<li key={product.id}>{product.name}</li>
))}
</ul>
import React, {Component} from 'react';
import styles from './Navbar.module.css';
import {Link, NavLink} from 'react-router-dom';
function isLoggedIn() {
const cookies = document.cookie
.split(';')
.filter(item => item.trim().startsWith('logedIn='));
return cookies.length > 0;
}
function spellingBeeSolutions(wordList, puzzles) {
return puzzles.map(puzzle => {
const puzzleLetters = puzzle.split('');
return wordList.reduce((acc, word) => {
const letters = word.split('');
const match = letters.every(
letter => puzzleLetters.includes(letter)
);
@trevorblades
trevorblades / demo-gatsby-config.js
Created August 26, 2019 23:09
Sourcing from a theme consumer
module.exports = {
plugins: [
{
resolve: 'gatsby-theme-esports',
options: {
root: __dirname
}
}
]
};
@trevorblades
trevorblades / events.js
Created October 8, 2019 04:20
Event handling with hooks
useEffect(() => {
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, []);
function handleKeyDown(event) {
console.log(event);
}