Skip to content

Instantly share code, notes, and snippets.

View craigmichaelmartin's full-sized avatar

Craig Martin craigmichaelmartin

View GitHub Profile
@dvassallo
dvassallo / snake.py
Last active December 24, 2023 04:48
import pygame
import time
import random
class Snake:
def __init__(self):
self.body = [(0, 0)]
self.direction = 'right'
def draw(self, screen):

Preact, Without Build Tools

This is a demonstration of using Preact without any build tooling. The library is linked from the esm.sh CDN, however a standalone JS file exporting HTM + Preact + Hooks can also be downloaded here.

@mirisuzanne
mirisuzanne / cq.css
Last active October 6, 2021 10:41
Thoughts on Container Queries
/*
This is not meant to be a final CSSWG proposal,
but reflects my immediate thoughts after reading
[David Baron's](https://github.com/dbaron/container-queries-implementability) promising draft.
This gist was created to demonstrate my idea for removing selectors from his query syntax.
More of my thoughts & notes are online at css.oddbird.net/rwd/
*/
main,

Using server-sent events

Why and how?

  • Documentation: https://web.dev/articles/eventsource-basics
  • Use case: broadcasting data from server to browsers
  • Benefits:
    • Easy to understand and implement (only a few lines of code)
    • No library is needed
  • Can use same HTTP(S) authentication as elsewhere in the app (which can’t be done with websockets)
const bypass = [
// function names to avoid logging
];
const collapsed = [
// function names to groupCollapsed
];
module.exports = function(babel) {
const { types: t } = babel;
const wrapFunctionBody = babel.template(`{
@chimmelb
chimmelb / chromiumpackages.config
Last active April 4, 2024 16:07
.ebextensions config file to load NodeJS EB instance with packages needed for Puppeteer/Chromium
# This is for ElasticBeanstalk with Amazon Linux 2023. For previous Linux 2 or Linux 1, see revisions for ideas
packages:
yum:
cups-libs: []
libdrm: []
libXdamage: []
libXfixes: []
libXrandr: []
mesa-libgbm: []
libxkbcommon: []
@sebmarkbage
sebmarkbage / The Rules.md
Last active May 7, 2024 15:01
The Rules of React

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.

@sebmarkbage
sebmarkbage / Infrastructure.js
Last active May 2, 2024 03:11
SynchronousAsync.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);
}
@gunar
gunar / await-to-js-no-throw.js
Last active January 5, 2021 00:26
Async Control Flow without Exceptions nor Monads
'use strict'
const toUpper = async string => {
if (string === 'invalid') return [Error('Invalid input')]
return [null, string.toUpperCase()]
}
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') }
const print = console.log
const foo = async input => {
@yossorion
yossorion / what-i-wish-id-known-about-equity-before-joining-a-unicorn.md
Last active April 7, 2024 22:55
What I Wish I'd Known About Equity Before Joining A Unicorn

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would