Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View heineiuo's full-sized avatar
🍑
I love peach

heineiuo heineiuo

🍑
I love peach
View GitHub Profile
function n(lit) {
const [str] = lit
const [start, end] = str.split('..').map((item) => parseInt(item))
return Array.from({ length: end - start + 1 }, (v, k) => k + start)
}
console.log(n`1..8`) // [1,2,3,4,5,6,7,8]
@heineiuo
heineiuo / generateHash.ts
Last active January 5, 2022 07:32
Generate SHA-256 of File/Blob in browser
import CryptoJS from 'crypto-js'
function byteArrayToWordArray(ba: Uint8Array) {
const wa: number[] = []
for (let i = 0; i < ba.length; i++) {
wa[(i / 4) | 0] |= ba[i] << (24 - 8 * i)
}
return CryptoJS.lib.WordArray.create(wa, ba.length)
}
@heineiuo
heineiuo / Shortest_UUID_v4_in_browser.md
Last active December 10, 2020 14:32
Shortest UUID v4 in browser
URL.createObjectURL(new Blob).split('/')[3]
@heineiuo
heineiuo / lint.js
Created August 29, 2018 05:20
use standardjs with pre-commit hook
const { exec } = require('shelljs')
const path = require('path')
const exit = () => {
console.log('JavaScript Standard Style errors were detected. Aborting commit.')
process.exit(1)
}
const gitdiff = exec(`git diff --name-only --cached --relative`)
if (gitdiff.stderr) {
@heineiuo
heineiuo / font-adjust.js
Last active August 18, 2017 05:10
百度脑图对文字居中兼容处理
/**
* source: https://github.com/fex-team/kityminder-core/blob/dev/src/module/text.js#L10-L127
*/
/**
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理
* 暂时未增加Linux的处理
*/
var FONT_ADJUST = {
'safari': {
@heineiuo
heineiuo / all_node_js_internal_modules.json
Last active August 15, 2017 03:11
All node.js internal modules
{
"v8.x": {
"all": [
"assert",
"async_hooks",
"buffer",
"child_process",
"cluster",
"crypto",
"dns",
@heineiuo
heineiuo / README.md
Last active July 4, 2017 05:11
get native `db` from mongoose
  1. 可以从Model里获取
const Users = mongoose.model('User', new mongoose.Schema({}), 'users')
const db = Users.db

// 然后就可以使用db了,比如 db.collection('users').find({}).toArray()