Skip to content

Instantly share code, notes, and snippets.

View iTonyYo's full-sized avatar
🎯
Focusing

Whoami iTonyYo

🎯
Focusing
  • California
View GitHub Profile
@iTonyYo
iTonyYo / shoeFactory.ts
Created August 1, 2022 07:16
《TypeScript 编程》5.13 练习题.3
type Shoe = {
purpose: string
}
type ShoeFactory = {
create(t: 'boot'): Boot
create(t: 'balletFlat'): BalletFlat
create(t: 'sneaker'): Sneaker
create(t: string): Boot
}
@iTonyYo
iTonyYo / findIndex.ts
Last active July 27, 2022 06:55
二分查找有序数值列表
/**
* 二分查找有序数值列表
* [1, 4, 10, 300, 5000000]
*
* Benchmark 结果,
*
* [1, 4, 10, 300, 5000000].findIndex((el) => el === 500);
* 原生 x 95,827,672 ops/sec ±0.87% (88 runs sampled)
*
* findIndex(500, [1, 4, 10, 300, 5000000]);
Markdown 8 mins ███████████████████▌░ 93.3%
Bash 0 secs █▍░░░░░░░░░░░░░░░░░░░ 6.7%
@iTonyYo
iTonyYo / README.md
Created January 25, 2021 01:08 — forked from addyosmani/README.md
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

// /-> INSERT -> EQUAL
// EQUAL | /-> EQUAL
// \-> DELETE |
// \-> INSERT -> EQUAL
@iTonyYo
iTonyYo / modern_js.md
Created June 12, 2019 14:13 — forked from gaearon/modern_js.md
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
@iTonyYo
iTonyYo / walksync.js
Created June 5, 2019 07:56 — forked from kethinov/walksync.js
List all files in a directory in Node.js recursively in a synchronous fashion
// List all files in a directory in Node.js recursively in a synchronous fashion
var walkSync = function(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + file).isDirectory()) {
filelist = walkSync(dir + file + '/', filelist);
}
else {
@iTonyYo
iTonyYo / solid.js
Created May 3, 2019 14:16 — forked from crizstian/solid.js
Code examples of SOLID principles for JavaScript
/*
Code examples from the article: S.O.L.I.D The first 5 priciples of Object Oriented Design with JavaScript
https://medium.com/@cramirez92/s-o-l-i-d-the-first-5-priciples-of-object-oriented-design-with-javascript-790f6ac9b9fa#.7uj4n7rsa
*/
const shapeInterface = (state) => ({
type: 'shapeInterface',
area: () => state.area(state)
})
@iTonyYo
iTonyYo / reset.js
Created April 2, 2019 11:30 — forked from 19h/reset.js
Node.js — Clear Terminal / Console. Reset to initial state.
console.reset = function () {
return process.stdout.write('\033c');
}
git tag -am "annotation goes here" tagname_goes_here # cut a tag
git tag -d tagname_goes_here # burn it
git tag -am "annotation goes here" tagname_goes_here # cut another tag
git push --tags # push tags to remote
git push origin :refs/tags/tagname_goes_here # delete tag from remote