Skip to content

Instantly share code, notes, and snippets.

View justgage's full-sized avatar

Gage Peterson justgage

View GitHub Profile
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
type pomWithError('data, 'err) = Js.Promise.t(Result.t('data, 'err));
type pom('data) = pomWithError('data, unit);
module JsPromise = {
let make = () => {
let resolver = ref(ignore);
let p =
Js.Promise.make((~resolve, ~reject as _) =>
resolver := (a => resolve(. a))
);
type queryBuilder;
type t = (. string) => queryBuilder;
type querySql('options) = {
.
"method": string,
"options": 'options,
"bindings": array(string),
"sql": string,
@gaearon
gaearon / modern_js.md
Last active April 18, 2024 15:01
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](https://developer.mozilla.org/en-US/docs/Web/Jav
@zetashift
zetashift / reparsecomb.re
Created February 18, 2018 18:25
Really barebones start of a parser combinator in ReasonML/OCaml
type result('a) =
| Success('a)
| Failure(string);
/* Encapsulate a parsing function in a type */
type parser('a) =
| Parser(string => result(('a, string)));
let reduce = (fn, list) =>
switch list {
@slashdotdash
slashdotdash / article.ex
Last active August 15, 2018 12:37
Commanded multi-entity aggregates
defmodule Article do
defstruct [:content, comments: []]
# public commands
def execute(%Article{}, %PublishArticle{content: content}) do
%ArticlePublished{content: content}
end
def execute(%Article{}, %CommentOnArticle{} = comment) do
@jaredly
jaredly / BasicServer.re
Created January 2, 2018 05:24
Simple Static File Server in Reason/OCaml
let recv = (client, maxlen) => {
let bytes = Bytes.create(maxlen);
let len = Unix.recv(client, bytes, 0, maxlen, []);
Bytes.sub_string(bytes, 0, len)
};
let parse_top = top => {
let parts = Str.split(Str.regexp("[ \t]+"), top);
switch (parts) {
@robertgonzales
robertgonzales / Frame.js
Created December 12, 2017 03:03
Use React portals to render inside shadow dom and iframes
class Frame extends Component {
componentDidMount() {
this.iframeHead = this.node.contentDocument.head
this.iframeRoot = this.node.contentDocument.body
this.forceUpdate()
}
render() {
const { children, head, ...rest } = this.props
return (
@evancz
evancz / data-interchange.md
Last active April 12, 2024 08:39
Why do I have to write JSON decoders in Elm?

A vision for data interchange in Elm

How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?

These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.

Literature Review

By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.

@akaleeroy
akaleeroy / Readable-Bookmarklet.md
Last active August 30, 2023 08:11
Readable Bookmarklet

Readable Bookmarklet

Bookmarklet Browser Enhancement Readability

Readable dark theme

rdbl.us

Readable is an application that helps you read more of the web. It reformats text — on any website — according to your exact specifications.