Skip to content

Instantly share code, notes, and snippets.

View zheeeng's full-sized avatar
🎈
blowing balloons

Zheeeng zheeeng

🎈
blowing balloons
View GitHub Profile
const race = async function * (size, taskIter) {
const queue = []
// enqueue
while (queue.length < size) {
const nextTask = taskIter.next()
if (!nextTask.done) {
queue.push(nextTask.value())
function utoa(str) {
return window.btoa(unescape(encodeURIComponent(str)))
}
function atou(str) {
return decodeURIComponent(escape(window.atob(str)))
}
['contextmenu', 'selectstart', 'copy'].forEach(function(ev){
document.addEventListener(ev, function(event){
return event.returnValue = false
})
});
@zheeeng
zheeeng / regexp-non-match.js
Created July 12, 2019 01:00
Regexp for non-matching
/^(?!.*hello).*$/.test('hello')
/^((?!hello).)*$/.test('hello')
type Config = {
title: string
description: string
rules: Rule[]
}
type Rule = {
description: string,
manipulators: Manipulator[]
}
let channels = [
{'name': 'ηΊ’εΏƒε…†θ΅«', 'channel_id': -3},
{'name': 'ζˆ‘ηš„η§δΊΊε…†θ΅«', 'channel_id': 0},
{'name': '每ζ—₯η§δΊΊζ­Œε•', 'channel_id': -2},
{'name': '豆瓣精选兆衫', 'channel_id': -10},
// εΏƒζƒ… / εœΊζ™―
{'name': 'ε·₯作学习', 'channel_id': 153},
{'name': 'ζˆ·ε€–', 'channel_id': 151},
{'name': '休息', 'channel_id': 152},
{'name': 'δΊ’ε₯‹', 'channel_id': 154},
@zheeeng
zheeeng / utils.ts
Last active March 12, 2020 04:37
common utils
export function findIndex <T> (items: T[], fn: (item: T, index: number) => boolean) {
for (let index = 0, len = items.length; index < len; index++) {
if (fn(items[index], index)) return index
}
return -1
}
export function flatMap <T, U> (items: T[], fn: (item: T, index: number) => U[]) {
return items.reduce((acc, item, index) => acc.concat(fn(item, index)), [] as U[])
@zheeeng
zheeeng / fp-ts-technical-overview.md
Created June 21, 2020 04:30 — forked from gcanti/fp-ts-technical-overview.md
fp-ts technical overview

Technical overview

A basic Option type

// Option.ts

// definition
export class None {
  readonly tag: 'None' = 'None'
🌞 Morning 471 commits β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 24.2%
πŸŒ† Daytime 610 commits β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 31.4%
πŸŒƒ Evening 581 commits β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Žβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 29.9%
πŸŒ™ Night 281 commits β–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 14.5%
@zheeeng
zheeeng / useClickOutside.tsx
Created March 30, 2021 10:15
useClickOutside.tsx
import { useEffect, useRef } from 'react'
export const useClickOutside = <T extends HTMLElement>(callback: (event: MouseEvent) => void) => {
const ref = useRef<T>(null)
const eventRef = useRef(callback)
useEffect(
() => {
eventRef.current = callback