Skip to content

Instantly share code, notes, and snippets.

@paulshen
paulshen / transform-imports-plugin.js
Created October 13, 2021 15:55 — forked from orenelbaum/transform-imports-plugin.js
Natto Solid imports transformation plugin
export default function transformImportsPlugin({ types }) {
return {
visitor: {
ImportDeclaration(path) {
const importSource = path.node.source.value
if (importSource !== "solid-js/web") return
const solidWebIdentifier = types.Identifier("solidjsWeb")
@paulshen
paulshen / tictactoe.rs
Created August 13, 2021 18:30
egui tictactoe
use super::hyperlink::Hyperlink;
use eframe::{egui, epi};
use egui::{pos2, vec2, Color32, Pos2, Rect, Stroke, Widget};
use rand::seq::SliceRandom;
#[derive(Copy, Clone, Debug, PartialEq)]
enum Player {
User,
Computer,
}
@paulshen
paulshen / render.js
Created June 29, 2021 17:29
natto.dev vega-embed renderer
import vegaEmbed from 'https://cdn.skypack.dev/vega-embed';
export default (element) => ({
render: (value) => {
vegaEmbed(element, value);
},
})
This file has been truncated, but you can view the full file.
!function(A){var e={};function t(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return A[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}t.m=A,t.c=e,t.d=function(A,e,i){t.o(A,e)||Object.defineProperty(A,e,{enumerable:!0,get:i})},t.r=function(A){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(A,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(A,"__esModule",{value:!0})},t.t=function(A,e){if(1&e&&(A=t(A)),8&e)return A;if(4&e&&"object"==typeof A&&A&&A.__esModule)return A;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:A}),2&e&&"string"!=typeof A)for(var r in A)t.d(i,r,function(e){return A[e]}.bind(null,r));return i},t.n=function(A){var e=A&&A.__esModule?function(){return A.default}:function(){return A};return t.d(e,"a",e),e},t.o=function(A,e){return Object.prototype.hasOwnProperty.call(A,e)},t.p="",t(t.s=224)}([function(A,e,t){"use strict";function i(A){return A&&0===A.length}function r(A){return null==A?[]:Object.keys(
@paulshen
paulshen / natto-eval.js
Created April 13, 2021 16:11
natto.dev eval pseudocode
const f = useMemo(() => {
try {
return new Function('inputs', `return ${expression}`);
} catch (e) {
return [e];
}
}, [expresssion]);
// input atoms
>>>> Start compiling
[3/3] Building src/Server-Server.cmj
FAILED: src/Server-Server.cmj src/Server-Server.cmi /Users/paulshen/Code/spotify-listening-room/server/src/Server.bs.js
/Users/paulshen/Code/spotify-listening-room/server/node_modules/bs-platform/darwin/bsc.exe -bs-package-name server -bs-ns Server -bs-package-output commonjs:src -color always -bs-suffix -I . -I src -I ../isomorphic -I /Users/paulshen/Code/spotify-listening-room/server/node_modules/bs-express/lib/ocaml -I /Users/paulshen/Code/spotify-listening-room/server/node_modules/bs-fetch/lib/ocaml -I /Users/paulshen/Code/spotify-listening-room/server/node_modules/reason-promise/lib/ocaml -I /Users/paulshen/Code/spotify-listening-room/server/node_modules/@ahrefs/bs-dotenv/lib/ocaml -I /Users/paulshen/Code/spotify-listening-room/server/node_modules/bs-socket/lib/ocaml -I /Users/paulshen/Code/spotify-listening-room/server/node_modules/@glennsl/bs-json/lib/ocaml -warn-error +101 -o src/Server-Server.cmj src/Server.reast
We've found a bug for you
@paulshen
paulshen / App.js
Created July 11, 2019 21:41
React nextEffect leak
import React from "react";
// Even though <InnerBody> unmounts (and remounts), this Fiber holds a reference to
// the initial <InnerBody> fiber node.
function Sidebar() {
React.useEffect(() => {
console.log("Sidebar");
});
return <div>Sidebar (look at my nextEffect chain)</div>;
}
@paulshen
paulshen / useMemo.js
Created June 21, 2019 04:54
useMemo using useRef
function useMemo(f, deps) {
const state = React.useRef();
if (state.current != null) {
const [prevDeps, prevResult] = state.current;
if (areArraysShallowEqual(deps, prevDeps)) {
return prevResult;
}
}
const result = f();
state.current = [deps, result];
window.fbAsyncInit = function() {
// Fix in Parse's date parser
var _parseDate = Parse._parseDate;
Parse._parseDate = function(str) {
return new Date(Date.parse(str));
};
Parse.FacebookUtils.init({
appId : '123', // Facebook App ID
version : 'v2.0'
// first pass
<div>{
a: <p><ExpensiveWidget /></p>
}</div>
// second pass
<div>{
b: <p>new paragraph</p>,