Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View cuixiping's full-sized avatar
🎯
Focusing

Cuixiping cuixiping

🎯
Focusing
View GitHub Profile
@cuixiping
cuixiping / excel column name to number.js
Created April 9, 2018 07:20
Excel表风格的字母列名转换为序号数字 Convert excel column name to number in javascript
/**
* Excel表风格的字母列名转换为序号数字
* Excel spreadsheet style column names are like A,B,C...,AA,AB,AC,...etc
* Sometimes we need to convert the letters name to number 1,2,3...,27,28,29,...etc
* Author: https://github.com/cuixiping
**/
//solution 1: best performance and best compatibility
function lettersToNumber(letters){
var chrs = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ', mode = chrs.length - 1, number = 0;
@cuixiping
cuixiping / checkSequence
Last active August 29, 2015 13:57
checkSequence 检测一组牌里有没有顺子
//这个是一组的,大城小胖是两组,那就先concat合并数组再传进来即可检测
function checkSequence(cards){
var B=[0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768];
var found = false, i, n = cards.length;
var sum = 0, queueSum = [], queueSumDic = {}, specials = {1:0, 14:0, 15:0};
while((i=cards.pop())){
(i in specials) ? (specials[i]++) : (sum |= B[i]);
} //#1
function appendSum(sum){ //存入一手牌
if(!queueSumDic[sum]) {
@cuixiping
cuixiping / gist:5479633
Created April 29, 2013 03:58
1 行正则去除重复字符或者重复单词
//去除重复字符
var str='aabbaabbcddcabcadbcad';
var str2=str.replace(/(.)(?=.*\1)/g,'');
document.writeln(str2); //bcad
//去除重复单词
var str='one two two one two one 99 two 99';
var str2=str.replace(/(\b\w+\b) (?=.*\1)/g,'');
document.writeln(str2); //one two 99
@cuixiping
cuixiping / webdings
Created October 29, 2012 07:26
webdings and wingdings preivew
<h1>webdings and wingdings preivew</h1>
<script>
var arr=[],s,fs=["webdings","wingdings","wingdings 2","wingdings 3"];
arr['&'.charCodeAt(0)-33] = '&amp;';
arr['<'.charCodeAt(0)-33] = '&lt;';
arr['>'.charCodeAt(0)-33] = '&gt;';
for (var i=33; i<127; i++){
s = arr[i-33] || String.fromCharCode(i);
arr[i-33] = '<span title="'+s+'\n'+i+'">'+s+'</span>';
}
@cuixiping
cuixiping / $("#id a") - $("#id .c a").js
Created August 23, 2012 14:36
设 A = $("#id a"),B = $("#id .c a"),求 A - B。
// oldj:设 A = $("#id a"),B = $("#id .c a"),求 A - B。要求:
// 1、不能用 jQuery 等框架;
// 2、兼容 IE6 在内的各大浏览器;
// 3、尽可能高效;
// 4、尽可能简短。
function getWanted() {
var root = document.getElementById('id');
var aa = Array.prototype.slice.call(root.getElementsByTagName('a'),0);
for(var i = aa.length-1; i >= 0; i--) {
if (check(aa[i].parentNode)) {
@cuixiping
cuixiping / h5g
Created July 19, 2012 07:35 — forked from wintercn/h5g
HTML5 Canvas Game Template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<!--允许全屏-->
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="yes" name="apple-touch-fullscreen"/>
<!--禁止电话号码和邮箱识别-->
// 根据生日的月份和日期,计算星座。 http://blog.csdn.net/cuixiping/
function getAstro(m,d){
return "魔羯水瓶双鱼牡羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m*2-(d<"102223444433".charAt(m-1)- -19)*2,2);
}
//下面写一个测试函数
function test(m,d){
document.writeln(m+"月"+d+"日 "+getAstro(m,d));
}