Skip to content

Instantly share code, notes, and snippets.

@ospfranco
ospfranco / WebImage.swift
Created January 16, 2022 12:44
React Native macOS Draggable SDWebImage
import Cocoa
import SDWebImage
class InternalWebImage: NSView, NSDraggingSource, NSPasteboardItemDataProvider {
let image = NSImageView()
@objc var url: NSString = "" {
didSet {
self.setupView()
}
@fnky
fnky / login.tsx
Last active December 15, 2023 19:56
Remix Form validation with zod
import { json, ActionFunction, useActionData, Form } from "remix";
import { z } from "zod";
// This type infer errors from a ZodType, as produced by `flatten()` of a parsed schema.
type inferSafeParseErrors<T extends z.ZodType<any, any, any>, U = string> = {
formErrors: U[];
fieldErrors: {
[P in keyof z.infer<T>]?: U[];
};
};
@almonk
almonk / SnappyWindow.swift
Last active June 27, 2023 20:24
SnappyWindow – A NSWindow that acts like the PIP Video Window from Safari
//
// SnappyWindow.swift
// A NSWindow that snaps to corners
//
// Created by Alasdair Monk on 03/02/2021.
//
import Foundation
import Cocoa
@OliverJAsh
OliverJAsh / foo.ts
Created December 3, 2020 17:48
ts-morph: Convert named imports to namespace import
// https://gist.github.com/OliverJAsh/5de515ad1f81b88409c13cd548c20893
// https://twitter.com/OliverJAsh/status/1334537098469265413
const { Project } = require('ts-morph');
const project = new Project({
tsConfigFilePath: 'tsconfig.app.no-references.json',
});
const PATH_TO_MATCH = '/Users/oliverash/Development/unsplash-web/shared/helpers/booleans.ts';
@yuyoyuppe
yuyoyuppe / transparent_imgui.cxx
Created March 22, 2019 15:35
Proof of concept that ... DXGI_ALPHA_MODE_PREMULTIPLIED doesn't work. Just use small borderless window and set bg_color to rgba(x,x,x,1)
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#pragma comment(lib, "user32.lib")
#include <wrl.h>
#include <dxgi1_3.h>
#include <d3d11_2.h>
#include <d2d1_2.h>
#include <d2d1_2helper.h>
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active February 13, 2024 14:30
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@bvaughn
bvaughn / updating-subscriptions-when-props-change-example.js
Last active March 27, 2022 09:29
Advanced example for manually updating subscriptions in response to props changes in an async-safe way
// This is an advanced example! It is not typically required for application code.
// If you are using a library like Redux or MobX, use the container component provided by that library.
// If you are authoring such a library, use the technique shown below.
// This example shows how to safely update subscriptions in response to props changes.
// In this case, it is important to wait until `componentDidUpdate` before removing a subscription.
// In the event that a render is cancelled before being committed, this will prevent us from unsubscribing prematurely.
// We also need to be careful about how we handle events that are dispatched in between
// `getDerivedStateFromProps` and `componentDidUpdate` so that we don't put stale values into the `state`.
// put this at the top of your app
const setState = Component.prototype.setState
Component.prototype.setState = function(nextState) {
console.group(this.constructor.name)
console.trace()
if (this.shouldComponentUpdate) {
console.log('shouldComponentUpdate', (
this.shouldComponentUpdate(this.props, nextState)
))
}

Parser

  • /src/parser/spider_monkey_ast.ml: The type definitions for the AST. Tries to stay very close to ESTree
  • /src/parser/lexer_flow.mll: The ocamllex lexer logic
  • /src/parser/parser_flow.ml: The recursive descent JS parser

Inference

  • /src/typing/type_inference_js.ml: Contains the "entry point" for inference (Function called infer_ast).
  • /src/typing/statement.ml: Most of the inference logic (runs through the AST and generates the initial constraints)