Skip to content

Instantly share code, notes, and snippets.

View zheeeng's full-sized avatar
🎈
blowing balloons

Zheeeng zheeeng

🎈
blowing balloons
View GitHub Profile
function utoa(str) {
return window.btoa(unescape(encodeURIComponent(str)))
}
function atou(str) {
return decodeURIComponent(escape(window.atob(str)))
}
const race = async function * (size, taskIter) {
const queue = []
// enqueue
while (queue.length < size) {
const nextTask = taskIter.next()
if (!nextTask.done) {
queue.push(nextTask.value())
// reference: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript/2117523#2117523
function uuidv4(): string {
const uuidTpl = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return uuidTpl.replace(/[xy]/g, c =>
String(
c == 'x' ? (Math.random() * 16) | 0 : ((Math.random() * 16) & 0x3) | 0x8
)
)
@zheeeng
zheeeng / delete_git_submodule.md
Created August 23, 2018 09:11 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@zheeeng
zheeeng / cycle-jsx-component.archive.ts
Created August 6, 2018 12:46
cycle jsx component archive(uncompleted)
import xs, { Stream } from 'xstream'
import isolate from '@cycle/isolate'
import { VNode, vnode } from 'snabbdom/vnode'
import { h } from 'snabbdom'
import { DOMSource } from '@cycle/dom'
export type VDOMType = VNode | string | boolean | null | undefined
export type DOMInstanceType<S extends string> = DOMSource | { [key in S] : DOMSource }
type ComponentSource = {
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@zheeeng
zheeeng / IPromise.ts
Created July 6, 2018 10:26
Promise interface with Reject ReturnType
interface IPromise<T, U> {
then<TResult1 = T, TResult2 = never>(
onfulfilled?:
| ((value: T) => TResult1 | PromiseLike<TResult1>)
| undefined
| null,
onrejected?:
| ((reason: U) => TResult2 | PromiseLike<TResult2>)
| undefined
| null
@zheeeng
zheeeng / addCopyright.js
Created May 6, 2018 03:50
addCopyright
/**
* @description 添加版权
*/
const addCopyright = () => {
const genCopy = () => {
return [
'',
'',
'作者:Vanessa',
'链接:https://hacpai.com/article/1510544423932',
@zheeeng
zheeeng / modal.jsx
Created April 8, 2018 09:00
react pattern
// https://github.com/facebook/react/issues/6599
class Modal extends React.Component {
componentDidMount() {
this.node = document.createElement('div');
document.body.appendChild(this.node);
this.renderPortal(this.props);
}
function length (str) {
const regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g
return str.replace(regexAstralSymbols, '_').length
}
function reverse(str) {
return Array.from(str).reverse().join('')
}