Skip to content

Instantly share code, notes, and snippets.

@zmmbreeze
zmmbreeze / uuid.ts
Last active November 21, 2018 13:28
export function random(): number {
let random;
// https://zh.wikipedia.org/wiki/2147483647
// 2147483647 === 1111111111111111111111111111111
try {
const arr = new Uint32Array(1);
// https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues
window.crypto.getRandomValues(arr);
random = arr[0] & 2147483647;
@zmmbreeze
zmmbreeze / playground.rs
Created August 28, 2018 04:53 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![allow(dead_code)]
#![allow(unused_variables)]
#[macro_use]
extern crate log;
#[derive(Debug)]
enum Person {
// 一个 `enum` 可能是个 `unit-like`(类单元结构体),
Engineer,
Scientist,
import Vue from 'vue';
/**
* 代理字段到当前实例上
* @eg:
* const src = {name: 'b'};
* const target = {};
* proxy(['name'], target, src);
* console.log(target.name); // => b
* target.name = 'a';
export default {
methods: {
/**
* find ancestor with specified component name.
* @param {string} name component name.
* @return {Vue} ancestor
*/
findAncestor(name) {
var parent = this.$parent;
if (!parent) {
(function(url){
// 第一部分
var dom,doc,where,iframe = document.createElement('iframe');
iframe.src = "javascript:false";
iframe.title = ""; iframe.role="presentation";
(iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
where = document.getElementsByTagName('script');
where = where[where.length - 1];
where.parentNode.insertBefore(iframe, where);
export default {
methods: {
/**
* find all sub components
* @param {string|function} name component name or validate function.
* @return {Array.<Vue>} result.
*/
findComponents(name) {
const find = (result, child) => {
const isFound = typeof name === 'string'
function preg_quote( str ) {
// http://kevin.vanzonneveld.net
// + original by: booeyOH
// + improved by: Ates Goral (http://magnetiq.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// * example 1: preg_quote("$40");
// * returns 1: '\$40'
// * example 2: preg_quote("*RRRING* Hello?");
// * returns 2: '\*RRRING\* Hello\?'
// copy from https://github.com/vuejs/vue/blob/v2.0.1/src/shared/util.js
/**
* Make a map and return a function for checking if a key
* is in that map.
*/
export function makeMap (
str: string,
expectsLowerCase?: boolean
): (key: string) => true | void {
const map = Object.create(null)
@zmmbreeze
zmmbreeze / analytics.js
Last active April 23, 2024 02:14
GA的源码 analytics.js
(function() {
/**
* 记录方法使用情况的类
* @param {Array.<boolean>} umMap 初始的使用情况
*/
var UsageManager = function(umMap) {
this.umMap = umMap || [];
};
/**
* 记录新的使用情况
docblockr@0.7.3
editorconfig@1.2.2
emmet@2.3.17
language-babel@2.7.0
linter@1.11.3
linter-eslint@5.2.7
merge-conflicts@1.3.7
minimap@4.19.0
minimap-bookmarks@0.2.0
minimap-cursorline@0.1.0