Skip to content

Instantly share code, notes, and snippets.

View nuintun's full-sized avatar
😊
I may be slow to respond.

nuintun nuintun

😊
I may be slow to respond.
View GitHub Profile
@nuintun
nuintun / 复选框半选中效果实现.md
Last active August 29, 2015 13:56
复选框半选中效果实现
@nuintun
nuintun / 浏览器console兼容.md
Last active June 6, 2016 08:47
浏览器console兼容
浏览器console兼容

方法一:

// make it safe to use console.log always
(function (b){
  function c(){}

  for (var d = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","), a; a = d.pop();) {
@nuintun
nuintun / NodeJS实现多域名解析.markdown
Last active May 13, 2019 06:27
NodeJS实现多域名解析
引用vhost.js,脚本代码如下:
module.exports = function vhost(hostname, server){
  if (!hostname) throw new Error('vhost hostname required');
  if (!server) throw new Error('vhost server required');
  
  var regexp = new RegExp(
    '^' + hostname.replace(/[^*\w]/g, '\\$&').replace(/[*]/g, '(?:.*?)') + '$',
    'i'
 );
@nuintun
nuintun / 用JS计算字符所占字节数.markdown
Last active March 18, 2024 03:31
用JS计算字符所占字节数
/**
 * 计算字符串所占的内存字节数,默认使用UTF-8的编码方式计算,也可制定为UTF-16
 * UTF-8 是一种可变长度的 Unicode 编码格式,使用一至四个字节为每个字符编码
 *
 * 000000 - 00007F(128个代码)      0zzzzzzz(00-7F)                             一个字节
 * 000080 - 0007FF(1920个代码)     110yyyyy(C0-DF) 10zzzzzz(80-BF)             两个字节
 * 000800 - 00D7FF
 * 00E000 - 00FFFF(61440个代码)    1110xxxx(E0-EF) 10yyyyyy 10zzzzzz           三个字节
 * 010000 - 10FFFF(1048576个代码)  11110www(F0-F7) 10xxxxxx 10yyyyyy 10zzzzzz  四个字节
@nuintun
nuintun / Cmd-Util工具CSS拆分正则.md
Last active August 29, 2015 14:00
Cmd-Util工具CSS拆分正则

Cmd-Util工具CSS拆分正则

var tokensRE = /(\/\*[^*]*\*+([^/*][^*]*\*+)*\/)|(@import\s+url\s*\(.+?\);?|@import\s+(['"]).+?\4;?)|((.(?!@import\s|\/\*))+(.(?=@import\s|\/\*))*)|((.(?!@import\s|\/\*))*(.(?=@import\s|\/\*))+)|([\r\n]+)/g;

带行报错功能的CSS解析器

/*
 * css
 * https://github.com/spmjs/spm2/issues/4
 *
 * Hsiaoming Yang <[email protected]>
 */
var endblockRE = /^\/\*!\s*endblock(?:\s*|\s+(.+?)\s*)\*\/$/,
@nuintun
nuintun / 节点同步.md
Last active March 11, 2021 02:08
在一个元素节点生成一个锁,保证在没有解锁的时候回调不会执行!

源码

(function ($){
  $.fn.sync = function (lock, fn){
    // 初始化参数
    fn = arguments.length === 1 ? lock : fn;
    fn = typeof lock === 'function' ? fn : $.noop;
    lock = lock && typeof lock === 'string' ? lock : 'default';
    lock = 'data-sync-' + lock;
@nuintun
nuintun / 联图二维码生成插件.md
Last active September 24, 2021 08:38
利用联图二维码API生成二维码的jQuery插件
(function ($){
  $.fn.qrcode = function (options){
    // 如果参数书字符串,默认设置成二维码内容
    if (typeof options === 'string') {
      options = { text: options };
    }

    // 参数合并
    options = $.extend({}, {
@nuintun
nuintun / UTF8和UTF16互相转换脚本.md
Last active June 6, 2016 08:30
UTF8和UTF16互相转换脚本
/* utf.js - UTF-8 <=> UTF-16 convertion
 * Copyright (C) 1999 Masanao Izumo <[email protected]>
 * Version: 1.0
 * LastModified: Dec 25 1999
 * This library is free.  You can redistribute it and/or modify it.
 * Reference http://suflow.iteye.com/blog/1687396
 */

/*
@nuintun
nuintun / C#图片处理.md
Last active March 11, 2021 02:08
C#图片处理类库

C#图片缩放,利用插值去除缩图毛边。

/// <summary>
/// 缩放图片
/// </summary>
/// <param name="original">原始图片</param>
/// <param name="width">新的宽度</param>
/// <param name="height">新的高度</param>
/// <returns>处理以后的图片</returns>