Skip to content

Instantly share code, notes, and snippets.

View ctsin's full-sized avatar
💭
雄关漫道真如铁,而今迈步从头越。

邢贵志 ctsin

💭
雄关漫道真如铁,而今迈步从头越。
  • EPAM
  • 深圳
  • 10:14 (UTC +08:00)
View GitHub Profile
@ctsin
ctsin / file.js
Created December 5, 2023 03:16
write
let filepath = ''; // your actual filepath
let obj = {}; // your actual object
let response = JSON.stringify(obj, null, 2);
let query = `
INSERT INTO imposters (filepath, response)
VALUES (?, ?)
ON DUPLICATE KEY UPDATE filepath = VALUES(filepath), response = VALUES(response);
`;
@ctsin
ctsin / node-typescript-esm.md
Created November 27, 2023 01:26 — forked from khalidx/node-typescript-esm.md
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

Changes to Event Delegation

In React 16 and earlier, React attaches one handler per event type directly at the document node. If you ahve multiple React versions on the page, they all register event handlers at hte top. This breaks e.stopPropagation().

In React 17, React will no longer attach event handlers at the document level, Instead, it will attach then to the root DOM container into which your React tree is rendered.

const rootNode = document.getElementById('root');
ReactDOM.render(<App />, rootNode);
@ctsin
ctsin / eof.md
Created July 17, 2020 07:16
考虑解决EOL的方法

.gitattributes

text=lf *.css linguist-vendored eol=lf *.scss linguist-vendored eol=lf *.js linguist-vendored eol=lf *.php eol=lf CHANGELOG.md export-ignore

~/.gitconfig

@ctsin
ctsin / pass-by-value-reference.md
Created June 8, 2020 05:48
Learn pass by value and pass by reference in JavaScript
@ctsin
ctsin / typescript-class-transpiled-into-es6.ts
Created May 15, 2020 02:38
TypeScript Class 类转换为 ES 的结果
// https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=7&pc=2#code/MYGwhgzhAEDC0G8BQ1XQHZgLYFNoF5oAKASgID4MBXEEAbhTTAHMcAuarAIxwCcG00YAHt0EAC68qwccN5EADrwCWANzDi8rdABM+HCSvTMyyQYPEALZRAB0LPIQCcTgWgC+Sd0A
// Babel will make a little bit different in properties order.
class C {
name = () => null;
age: number;
constructor(private gender: string) {
this.age = 99;
}
}
@ctsin
ctsin / ChangeDetectionStrategy.ts
Created April 23, 2020 09:27
返回不可变数据配合 ChangeDetectionStrategy 或许能解决 “sinceHasBeenChecked" 错误
// https://alligator.io/angular/change-detection-strategy/
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ChildComponent {
@ctsin
ctsin / type-predicate.ts
Created April 23, 2020 09:04
类型断言
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
type DateVal = Record<'from' | 'to', string>
interface X {
filed: boolean | DateVal
}
const x: X = { filed: true }
@ctsin
ctsin / little-vdom-decompiled.js
Created March 9, 2020 08:06 — forked from marvinhagemeister/little-vdom-decompiled.js
Jason little-vdom decompiled
/* eslint-disable no-unused-vars */
/* eslint-disable no-else-return */
// JSX constructor, similar to createElement()
export const h = (type, props, ...children) => {
return {
type,
// Props will be an object for components and DOM nodes, but a string for
// text nodes
props,