Skip to content

Instantly share code, notes, and snippets.

View jihchi's full-sized avatar
🦀

Jihchi Lee jihchi

🦀
View GitHub Profile
const express = require('express');
const app = express();
// Application
app.get('/', function(req, res) {
if (process.env.NODE_ENV === 'development') {
for (var key in require.cache) {
delete require.cache[key];
}
}
@mayneyao
mayneyao / notion2blog.js
Last active February 29, 2024 18:01
Notion.so > Personal Blog | custom domain + disqus comment
const MY_DOMAIN = "agodrich.com"
const START_PAGE = "https://www.notion.so/gatsby-starter-notion-2c5e3d685aa341088d4cd8daca52fcc2"
const DISQUS_SHORTNAME = "agodrich"
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
@naugtur
naugtur / GetOptimizationStatus.md
Created August 9, 2019 21:08 — forked from justjavac/GetOptimizationStatus.md
V8 %GetOptimizationStatus

%GetOptimizationStatus return a set of bitwise flags instead of a single value, to access the value, you need to take the binary representation of the returned value. Now, for example, if 65 is returned, the binary representation is the following:

(65).toString(2).padStart(12, '0');
// 000001000001

Each binary digit acts as a boolean with the following meaning:

@ryyppy
ryyppy / 0_functor.re
Last active June 3, 2019 18:33
Reason Functor Example
/*
Let's Assume we want to have a Functor which creates a new Module from
a specific Component Model
The Functor recieves another Module named `Component`, which needs to satisfy certain constraints:
- Component requires an abstract type t (no matter what concrete type)
- It also needs to implement a `render` function which gets said type t and returns a `string`
Also, the newly created module will then contain a function `doSomething`, which will handle any
instance of `Component.t`. So our `Component` also will need a function to create an instance for that,
@Matthias247
Matthias247 / async_await_cancellation.md
Created May 28, 2019 06:09
Async/Await - The challenges besides syntax - Cancellation

Async/Await - The challenges besides syntax - Cancellation

This is the second article in a series of articles around Rusts new async/await feature. The first article about interfaces can be found here.

In this part of the series we want to a look at a mechanism which behaves very different in Rust than in all other languages which feature async/await support. This mechanism is Cancellation.

@Matthias247
Matthias247 / async_await_interfaces.md
Last active April 5, 2023 18:08
# Async/Await - The challenges besides syntax

Async/Await - The challenges besides syntax

4 years after after the release of Rust 1.0, it seems like Rust is now finally getting close to getting support for async/await - a language feature which aims to make it easier to write programs in an asynchronous fashion (where multiple logical tasks get multiplexed on a lower number of OS threads).

One of the last steps before the feature is stabilized is choosing the best possible syntax. The discussions around syntax have triggered an enormous

@developit
developit / *String.prototype.replaceAll() Ponyfill.md
Last active October 11, 2020 23:32
~80b ponyfill for String.prototype.replaceAll()

@developit/replaceall NPM

~80b ponyfill for String.prototype.replaceAll() with good performance.

Why ponyfill? Because this is a proposal for a spec, and polyfilling it in-place before it gets solidified could break code that relies on an incorrect implementation.

Alternate Version
@joshwcomeau
joshwcomeau / use-change-log.hook.js
Last active December 12, 2021 04:29
ChangeLog Hook
/**
`useChangeLog` - dev-mode helper hook to let you
know why a memoized component re-rendered!
Usage example:
const YourComponent = React.memo((props) => {
// Just drop this fella into your memo component's body.
useChangeLog(props);
[%bs.raw {|require("bootstrap/dist/css/bootstrap.min.css")|}];
type complex = {
value: string,
className: string
};
module BtnColorContext =
Context.MakePair({
type t = complex;

Getting Started With Plug'n'Play

If you use create-react-app, #5136 (released with the 2.0) implements a --use-pnp option that allows you to easily create a new project using PnP! In this case, just use create-react-app --use-pnp together with Yarn 1.12, and you're good to go! 👍

Plug'n'Play is a new initiative from Yarn that aims to remove the need for node_modules. It's already available, and has proved being effective even on large-scale infrastructures. This document describes in a few steps how to quickly get started with it. Spoiler alert: it's quite easy 🙂

First, download a package manager that supports it. Yarn 1.12 already does, so that's what we're going to use! To install it, just follow the instructions on our website: https://yarnpkg.com/en/docs/install

If everything is ok, running yarn --version should give you v1.12.1 or higher. If you don't get this result maybe a