Skip to content

Instantly share code, notes, and snippets.

View shiftyp's full-sized avatar

Ryan Kahn shiftyp

View GitHub Profile
@shiftyp
shiftyp / womp-womp.ts
Last active December 8, 2020 01:02
Unfortunate TypeScript error
interface RefHandles {
scrollToIntent: HTMLElement['scrollTo'];
}
const targetElement = document.createElement('div');
const handles: RefHandles = {
scrollToIntent(...args: any[]) {
targetElement.scrollTo(...args);
}
@shiftyp
shiftyp / state.js
Created November 28, 2020 17:38
State!
let state = 1
const update = (value) => {
state = value
document.innerHTML = Array(value % 4).fill('Hello')
}
setInterval(() => update(Date.now()), 1000)
@shiftyp
shiftyp / index.html
Last active November 23, 2020 14:36
Document Object Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Page</title>
<style>
li { cursor: pointer }
</style>
<!--
The first place JS and HTML intersect is a script tag
@shiftyp
shiftyp / example.tsx
Last active August 22, 2020 17:01
objects 0.2.0 example
import React from 'react'
import { useStable, useWatch } from '@objects/hooks'
import { through, map, debounce } from '@objects/operators'
interface Search {
title: string
}
interface Data {
@shiftyp
shiftyp / example.js
Last active July 29, 2020 18:22
Alternative Wicked API
wickedElements.define('.my-counter', (element, { events, changes, values }) => {
const counter = element.querySelector('.count')
const minus = element.querySelector('.minus')
const plus = element.querySelector('.plus')
changes(values).count(count => {
counter.textContent = count
})
values.count = 0
import { useInstance } from 'object-hooks';
class Analytics {
private api = () => {
const raceError = new Error('handler called before loaded');
bugsnagClient.notify(raceError);
};
public log = (...args: any[]) => {
return this.api(...args);
@shiftyp
shiftyp / gallery.js
Last active December 5, 2019 20:32
Logic for an image gallery built with React Hooks! 🐱https://codesandbox.io/s/hooks-gallery-4xjzz
@shiftyp
shiftyp / snake.js
Last active December 4, 2019 22:29
Logic for a snake game built with React Hooks 🐍https://codesandbox.io/s/snake-hooks-343rh
import { useReducer, useEffect, useRef, useCallback } from 'react'
const offsets = {
n: [0, 1],
s: [0, -1],
e: [1, 0],
w: [-1, 0],
}
const equals = (a, b) =>
@shiftyp
shiftyp / cart.js
Last active June 17, 2020 07:22
A shopping cart with server persistence built with React hooks
import { useReducer, useState, useEffect } from "react";
const reduceCartFromOrders = (current, [id, quantity]) => {
if (current === null) current = {};
if (quantity === null) {
delete current[id];
return current;
}
@shiftyp
shiftyp / settings.json
Created April 25, 2019 12:22
Types are Comments
{
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
"meta.type.declaration",
"meta.type.declaration entity",
"meta.type.declaration entity.name.function",
"meta.type.declaration entity.name.type",
"meta.type.declaration keyword",