Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

/**
* @fileoverview
* - Using the 'QRCode for Javascript library'
* - Fixed dataset of 'QRCode for Javascript library' for support full-spec.
* - this library has no dependencies.
*
* @author davidshimjs
* @see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
* @see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
*/
import React, { PureComponent, createRef } from 'react';
/**
* @class ExtendClickArea
* @argument {PureComponent<{ extend: number, center: boolean }>}
* @description 用来自动扩展按钮的点击区域
**/
export default class ExtendClickArea extends PureComponent {
/** @type {{ width: number, height: number }} */
state = { width: 0, height: 0 };
type BaseEventMap = { [event: string]: [] }
type EventListener<EventMap extends BaseEventMap, Event extends keyof EventMap>
= (...args: EventMap[Event]) => any
type EventListenerItem<EventMap extends BaseEventMap, Event extends keyof EventMap> = {
once: boolean
listener: EventListener<EventMap, Event>
}
/* eslint-disable */
/*
一套基于 postMessage 的页面间通讯协议
*/
/*
interface Request {
id: number
type: 'req'
@bramblex
bramblex / throttle.ts
Last active October 30, 2018 09:22
用于限流
export function throttle<R>(func: () => Promise<R>): () => Promise<R> {
let promise: Promise<R> | null = null
return () => {
if (promise) {
return promise
} else {
promise = func()
promise.finally(() => promise = null)
return promise
}
const { template } = require('./template')
function setEnv(env, paris) {
for (const [name, value] of Object.entries(paris)) {
let get
if (typeof value === 'string') {
@bramblex
bramblex / sql.js
Created July 30, 2018 01:18
sql generator for js
const { escape } = require('mysql')
function escapeValue(value) { return escape(value) }
function escapeName(name) { return '`' + name + '`'; }
// ================ export ================
function $limit(nu) {
return `LIMIT ${escapeValue(nu)}`
function startup(zone, module_path) {
const code
= "eval((function () {"
+ " var path = require('path');"
+ " var startup_module_path = " + JSON.stringify(module_path) + ";"
+ " var startup_module = require(startup_module_path);"
+ " var startup_code = Object"
+ " .getOwnPropertyNames(startup_module)"
+ " .map(function (name) { return { name: name, value: startup_module[name] }; })"
+ " .reduce(function (prev, curr) {"
@bramblex
bramblex / mweb-auto-publish.sh
Last active January 29, 2023 08:23
mweb-auto-publish.sh
if (pbpaste | grep -Eq '^cd "[^"]*" && sh "[^"]*/site_publish_logs/sh_\d*\.sh" && open "[^"]*"')
then
echo "========== MWEB AUTO PUBLISH START =========="
echo "Runing command:"
pbpaste
if pbpaste | sh
then
echo "Success!"
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const [, , ...argv] = process.argv
const create_body_flag = argv.filter(key => key === '-b').length > 0
const classes = argv.filter(key => key !== '-b')
const warpNamespace = (namespaces, content) => {