Skip to content

Instantly share code, notes, and snippets.

View TooBug's full-sized avatar
💭
I may be slow to respond.

TooBug TooBug

💭
I may be slow to respond.
View GitHub Profile
var less = require('less');
var fs = require('fs');
var path = require('path');
var SourceMapGenerator = require('source-map').SourceMapGenerator
function errfn(callback) {
return function (err) {
if (err) callback.call(this, err);
else callback.apply(this, [].slice.apply(arguments).slice(1));
}
@TooBug
TooBug / citydata.js
Created August 22, 2013 07:04
2012年底统计中国行政区域数据(二级)
var citydata =[
{province:'北京市',city:['东城区','西城区','朝阳区','丰台区','石景山区','海淀区','门头沟区','房山区','通州区','顺义区','昌平区','大兴区','怀柔区','平谷区','密云县','延庆县']},
{province:'天津市',city:['和平区','河东区','河西区','南开区','河北区','红桥区','东丽区','西青区','津南区','北辰区','武清区','宝坻区','滨海新区','宁河县','静海县','蓟县']},
{province:'河北省',city:['石家庄市','唐山市','秦皇岛市','邯郸市','邢台市','保定市','张家口市','承德市','沧州市','廊坊市','衡水市']},
{province:'山西省',city:['太原市','大同市','阳泉市','长治市','晋城市','朔州市','晋中市','运城市','忻州市','临汾市','吕梁市']},
{province:'内蒙古自治区',city:['呼和浩特市','包头市','乌海市','赤峰市','通辽市','鄂尔多斯市','呼伦贝尔市','巴彦淖尔市','乌兰察布市','兴安盟','锡林郭勒盟','阿拉善盟']},
{province:'辽宁省',city:['沈阳市','大连市','鞍山市','抚顺市','本溪市','丹东市','锦州市','营口市','阜新市','辽阳市','盘锦市','铁岭市','朝阳市','葫芦岛市']},
{province:'吉林省',city:['长春市','吉林市','四平市','辽源市','通化市','白山市','松原市','白城市','延边朝鲜族自治州']},
{province:'黑龙江省',city:['哈尔滨市','齐齐哈尔市','鸡西市','鹤岗市','双鸭山市','大庆市','伊春市','佳木斯市','七台河市','牡丹江市','黑河市','绥化市','大兴安岭地区']},
{province:'上海市',city:['黄浦区','徐汇区','长宁区','静安区','普陀区','闸北区','虹口区','杨浦区','闵行区','宝山区','嘉定区','浦东新区','金山区','松江区','青浦区','奉贤区','崇明县']},
@TooBug
TooBug / comet.js
Created December 23, 2016 09:36
未上线的聊天系统前端代码
/**
* 封装Comet长连接操作,其中extraRequestData暴露出来,可供动态修改下次请求时的参数
* @author TooBug
* @version 2014-08-02
* @example
var a=new Comet({
url:'http://echo.113.im/',
data:{
data:JSON.stringify({test:123}),
timeout:10000
@TooBug
TooBug / convertTable.js
Created March 13, 2017 09:39
表格适配移动端代码
$('.md-preview table').each(function(){
var $table = $(this);
var $th = $table.find('thead th');
var colCount = $th.length;
var transformCols = $th.slice(1).map(function(index){
var content = this.innerHTML;
if(index > 0){
$(this).remove();
}
return content;
@TooBug
TooBug / gist:9781db6bc14f0d353c4dc95bbb71d0e2
Created May 31, 2017 02:17
给定指定数和一个数组组合,求合为指定数的最少次数组合
var ret = [];
var levels = [698, 208, 128, 68, 6];
function getRet(sum, level){debugger;
if(!level) level = 0;
if(level > levels.length - 1) return false;
var thisCount = Math.floor(sum / levels[level]);
while(thisCount >= 0){
ret[level] = thisCount;
var nextSum = sum - thisCount*levels[level];
@TooBug
TooBug / cleanWord.html
Created March 5, 2018 06:42
clean word tags
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>cleanWord</title>
<style>
html,body{
height:100%;
margin:0;
padding:0;
@TooBug
TooBug / 3door.js
Created March 5, 2018 06:44
三门问题
'use strict';
/**
* 模拟一次游戏过程
* @param {Boolean} isKnown 主持人(卖水的)是否是故意选择(否则是随机选择)
* @return {Boolean} 选择不交换的结果是否猜中(即交换后没猜中的情况)
*/
function isWin(isKnown){
// 目标在几号
var target = (Math.random()*3) | 0;
@TooBug
TooBug / 24points.js
Last active October 30, 2018 02:18
24点计算
let input = process.argv[2].split(',').map((v)=>+v);
// let input = [6,6,6,6];
console.log('输入 %s', input.join(','));
let arr = input.concat(['o','o','o']);
let len = arr.length;
let isNumber = (item) => typeof item === 'number';
@TooBug
TooBug / maoyan.js
Created March 7, 2019 09:30
猫眼电影票房数字识别替换
let canvas, ctx;
function init(){
console.log('==== 初始化canvas 开始 ====');
canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
canvas.style.width = '100px';
canvas.style.height = '100px';
canvas.style.position = 'absolute';