j_dong/Java读取Excel
Java读取Excel的方法,解析xls、xlsx两种格式
  java excel 最后更新时间 2013-11-23 08:42:01
snippet_file.java 175行 Java
Raw
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* 读取Excel
*
* @author zengwendong
*/
public class ReadExcelUtils {
private Logger logger = LoggerFactory.getLogger(ReadExcelUtils.class);
private Workbook wb;
private Sheet sheet;
private Row row;

public ReadExcelUtils(String filepath) {
if(filepath==null){
return;
}
String ext = filepath.substring(filepath.lastIndexOf("."));
try {
InputStream is = new FileInputStream(filepath);
if(".xls".equals(ext)){
wb = new HSSFWorkbook(is);
}else if(".xlsx".equals(ext)){
wb = new XSSFWorkbook(is);
}else{
wb=null;
}
} catch (FileNotFoundException e) {
logger.error("FileNotFoundException", e);
} catch (IOException e) {
logger.error("IOException", e);
}
}
/**
* 读取Excel表格表头的内容
*
* @param InputStream
* @return String 表头内容的数组
* @author zengwendong
*/
public String[] readExcelTitle() throws Exception{
if(wb==null){
throw new Exception("Workbook对象为空!");
}
sheet = wb.getSheetAt(0);
row = sheet.getRow(0);
// 标题总列数
int colNum = row.getPhysicalNumberOfCells();
System.out.println("colNum:" + colNum);
String[] title = new String[colNum];
for (int i = 0; i < colNum; i++) {
// title[i] = getStringCellValue(row.getCell((short) i));
title[i] = row.getCell(i).getCellFormula();
}
return title;
}

/**
* 读取Excel数据内容
*
* @param InputStream
* @return Map 包含单元格数据内容的Map对象
* @author zengwendong
*/
public Map<Integer, Map<Integer,Object>> readExcelContent() throws Exception{
if(wb==null){
throw new Exception("Workbook对象为空!");
}
Map<Integer, Map<Integer,Object>> content = new HashMap<Integer, Map<Integer,Object>>();
sheet = wb.getSheetAt(0);
// 得到总行数
int rowNum = sheet.getLastRowNum();
row = sheet.getRow(0);
int colNum = row.getPhysicalNumberOfCells();
// 正文内容应该从第二行开始,第一行为表头的标题
for (int i = 1; i <= rowNum; i++) {
row = sheet.getRow(i);
int j = 0;
Map<Integer,Object> cellValue = new HashMap<Integer, Object>();
while (j < colNum) {
Object obj = getCellFormatValue(row.getCell(j));
cellValue.put(j, obj);
j++;
}
content.put(i, cellValue);
}
return content;
}

/**
*
* 根据Cell类型设置数据
*
* @param cell
* @return
* @author zengwendong
*/
private Object getCellFormatValue(Cell cell) {
Object cellvalue = "";
if (cell != null) {
// 判断当前Cell的Type
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:// 如果当前Cell的Type为NUMERIC
case Cell.CELL_TYPE_FORMULA: {
// 判断当前的cell是否为Date
if (DateUtil.isCellDateFormatted(cell)) {
// 如果是Date类型则,转化为Data格式
// data格式是带时分秒的:2013-7-10 0:00:00
// cellvalue = cell.getDateCellValue().toLocaleString();
// data格式是不带带时分秒的:2013-7-10
Date date = cell.getDateCellValue();
cellvalue = date;
} else {// 如果是纯数字

// 取得当前Cell的数值
cellvalue = String.valueOf(cell.getNumericCellValue());
}
break;
}
case Cell.CELL_TYPE_STRING:// 如果当前Cell的Type为STRING
// 取得当前的Cell字符串
cellvalue = cell.getRichStringCellValue().getString();
break;
default:// 默认的Cell值
cellvalue = "";
}
} else {
cellvalue = "";
}
return cellvalue;
}

public static void main(String[] args) {
try {
String filepath = "F:test.xls";
ReadExcelUtils excelReader = new ReadExcelUtils(filepath);
// 对读取Excel表格标题测试
// String[] title = excelReader.readExcelTitle();
// System.out.println("获得Excel表格的标题:");
// for (String s : title) {
// System.out.print(s + " ");
// }
// 对读取Excel表格内容测试
Map<Integer, Map<Integer,Object>> map = excelReader.readExcelContent();
System.out.println("获得Excel表格的内容:");
for (int i = 1; i <= map.size(); i++) {
System.out.println(map.get(i));
}
} catch (FileNotFoundException e) {
System.out.println("未找到指定路径的文件!");
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}
web前端执行者/jquery ui各种验证代码
  最后更新时间 2013-11-25 18:35:54
snippet_file.txt 264行 Text
Raw
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
//表单验证扩展
$.extend($.fn.validatebox.defaults.rules,
{ //验证中文
CHS:{
validator:function(value){
return /^[\u0391-\uFFE5]+$/.test(value);
},
message:"只能输入汉字."
},
//字符验证
stringCheck:{
validator:function(value){
return /^[\u0391-\uFFE5\w]+$/.test(value);
},
message:"只能包括中文字、英文字母、数字和下划线."
},
//验证中文,英文,数字
stringCheckSub:{
validator:function(value){
return /^[a-zA-Z0-9\u4E00-\u9FA5]+$/.test(value);
},
message:"只能包括中文字、英文字母、数字."
},
englishCheckSub:{
validator:function(value){
return /^[a-zA-Z0-9]+$/.test(value);
},
message:"只能包括英文字母、数字."
},
numberCheckSub:{
validator:function(value){
return /^[0-9]+$/.test(value);
},
message:"只能输入数字."
},
//手机号码验证
mobile:{
validator:function(value){
var reg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
return value.length == 11 && reg.test(value);
},
message:"请正确填写您的手机号码."
},
//电话号码验证
telephone:{
validator:function(value){
//电话号码格式010-12345678
var reg = /^\d{3,4}?\d{7,8}$/;
return reg.test(value);
},
message:"请正确填写您的电话号码."
},
//联系电话(手机/电话皆可)验证
mobileTelephone:{
validator:function(value){
var cmccMobile = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var tel = /^\d{3,4}?\d{7,8}$/;
return tel.test(value) || (value.length == 11 && cmccMobile.test(value));
},
message:"请正确填写您的联系电话."
},
//验证国内邮编验证
zipCode:{
validator:function(value){
var reg = /^[1-9]\d{5}$/;
return reg.test(value);
},
message:"邮编必须长短0开端的6位数字."
},
//身份证号码验证
idCardNo:{
validator:function(value){
return isIdCardNo(value);
},
message:"请正确输入您的身份证号码."
},
//验证两个不同时为空
//可以自定义提示信息
allNotNull:{
validator:function(toValue,fromValue){
if(fromValue ==null || fromValue.length ==0 || fromValue[0]==null || fromValue[0]==""){
if(toValue ==null || toValue.length ==0 || toValue[0]==null || toValue[0]==""){
$.fn.validatebox.defaults.rules.compareDigit.message="中,英.文名不可同时为空 ";
return false;
}else{
return true;
}
}else
{return true;}
},
message:""
},
//数字验证大小,结束值应该大于开始值
//可以自定义提示信息
compareDigit:{
validator:function(toValue,fromValue){
if(fromValue ==null || fromValue.length ==0 || fromValue[0]==null || fromValue[0]==""){
return true;
}
if(parseFloat(toValue) > parseFloat(fromValue[0])){
return true;
}else{
if(fromValue.length >= 2){
$.fn.validatebox.defaults.rules.compareDigit.message = fromValue[1];
}else{
$.fn.validatebox.defaults.rules.compareDigit.message = '结束值应该大于开始值';
}
return false
}
},
message:""
},
//日期、时间验证大小,结束日期应该大于开始日期
//可以自定义提示信息
compareDate:{
validator:function(toDate,param){
if(param ==null || param.length ==0 || param[0]==null || param[0]==""){
return true;
}
if(toDate > param[0]){
return true;
}else{
if(param.length >= 2){
$.fn.validatebox.defaults.rules.compareDate.message = param[1];
}
else {
$.fn.validatebox.defaults.rules.compareDate.message = '结束日期应该大于开始日期';
}
return false
}
},
message:''
}
//到服务器端验证
/*remote:{
validator:function(value,param){
var params = {};
params[param[1]] = value;
$.post(param[0],params,function(data){
if(!data.msg){
$.fn.validatebox.defaults.rules.account.message = param[2];
}
return data.msg;
});
},
message:""
}*/
}
)

//--身份证号码验证-支持新的带x身份证
function isIdCardNo(num)
{
var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
var error;
var varArray = new Array();
var intValue;
var lngProduct = 0;
var intCheckDigit;
var intStrLen = num.length;
var idNumber = num;
// initialize
if ((intStrLen != 15) && (intStrLen != 18)) {
//error = "输入身份证号码长度不对!";
//alert(error);
//frmAddUser.txtIDCard.focus();
return false;
}
// check and set value
for(i=0;i<intStrLen;i++) {
varArray[i] = idNumber.charAt(i);
if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {
//error = "错误的身份证号码!.";
//alert(error);
//frmAddUser.txtIDCard.focus();
return false;
} else if (i < 17) {
varArray[i] = varArray[i]*factorArr[i];
}
}
if (intStrLen == 18) {
//check date
var date8 = idNumber.substring(6,14);
if (isDate8(date8) == false) {
//error = "身份证中日期信息不正确!.";
//alert(error);
return false;
}
// calculate the sum of the products
for(i=0;i<17;i++) {
lngProduct = lngProduct + varArray[i];
}
// calculate the check digit
intCheckDigit = 12 - lngProduct % 11;
switch (intCheckDigit) {
case 10:
intCheckDigit = 'X';
break;
case 11:
intCheckDigit = 0;
break;
case 12:
intCheckDigit = 1;
break;
}
// check last digit
if (varArray[17].toUpperCase() != intCheckDigit) {
//error = "身份证效验位错误!...正确为: " + intCheckDigit + ".";
//alert(error);
return false;
}
}
else{ //length is 15
//check date
var date6 = idNumber.substring(6,12);
if (isDate6(date6) == false) {
//alert("身份证日期信息有误!.");
return false;
}
}
//alert ("Correct.");
return true;
}

/**
* 判断是否为“YYYYMM”式的时期
*
*/
function isDate6(sDate) {
if(!/^[0-9]{6}$/.test(sDate)) {
return false;
}
var year, month, day;
year = sDate.substring(0, 4);
month = sDate.substring(4, 6);
if (year < 1700 || year > 2500) return false
if (month < 1 || month > 12) return false
return true
}
/**
* 判断是否为“YYYYMMDD”式的时期
*
*/
function isDate8(sDate) {
if(!/^[0-9]{8}$/.test(sDate)) {
return false;
}
var year, month, day;
year = sDate.substring(0, 4);
month = sDate.substring(4, 6);
day = sDate.substring(6, 8);
var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
if (year < 1700 || year > 2500) return false
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
if (month < 1 || month > 12) return false
if (day < 1 || day > iaMonthDays[month - 1]) return false
return true
}
_明月/中秋之月
该网页中插入有一张图片,图片(010.jpg)的网址链接为:http://image.so.com/i?q=月饼&src=srp# 。该图片放置在与网页文件同一文件夹下的Picture文件中。
  最后更新时间 2016-09-07 08:42:20
snippet_file_0.txt 33行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
<html>
<head>
<title>中秋之月</title>
</head>
<body>
<div style="background:#9DD5E5; height = 90%; width= 70%">
<h2>参与大赛赢月饼,耶耶耶。 </h2><br/><br/><br/>
<center>
<font size="6" face="仿宋">一剪梅·中秋元月</font><br/>
<br/>

<font size="4" face="宋体">辛弃疾 [宋]</font><br/><br/>

<font size="5" face="仿宋">忆对中秋丹桂丛。花在杯中。月在杯中。</font><br/><br/>

<font size="5" face="仿宋">今宵楼上一尊同。云湿纱窗。雨湿纱窗。</font><br/><br/>

<font size="5" face="仿宋">浑欲乘风问化工。路也难通。信也难通。</font><br/><br/>

<font size="5" face="仿宋">满堂惟有烛花红。杯且从容。歌且从容。</font><br/><br/>


</center>
<br/><br/>
<marquee direction="right" ><img src="Picture\010.jpg" title = "月饼" /></marquee>
<br/><br/><br/><br/>

</div>
</body>

</html>
OS_Mirror/15个实用的jQuery代码片.md
可以直接拿来用的15个jQuery代码片。来源 http://www.csdn.net/article/2013-07-16/2816238-15-jQuery-Code-Snippets-for-Developers#
  JQuery 最后更新时间 2013-11-22 17:42:52
15个实用的jQuery代码片.md 18行 Text
Raw

15个实用的jQuery代码片

文件名及对应代码片功能

jq15_1.预加载图片
jq15_2.让页面中的每个元素都适合在移动设备上展示
jq15_3.图像等比例缩放
jq15_4.返回页面顶部
jq15_5.使用jQuery打造手风琴式的折叠效果
jq15_6.通过预加载图片廊中的上一幅下一幅图片来模仿Facebook的图片展示方式
jq15_7.使用jQuery和Ajax自动填充选择框
jq15_8.自动替换丢失的图片
jq15_9.在鼠标悬停时显示淡入/淡出特效
jq15_10.清空表单数据
jq15_11.预防对表单进行多次提交
jq15_12.动态添加表单元素
jq15_13.让整个Div可点击
jq15_14.平衡高度或Div元素
jq15_15. 在窗口滚动时自动加载内容

最美代码/JohnnyX.cpp
解魔方的机器人。魔方大赛二等奖。
  机器人 最后更新时间 2013-11-22 17:40:59
JohnnyX.cpp 208行 C++
Raw
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
/**********************************************************************
*
* A cube 'state' is a vector<int> with 40 entries, the first 20
* are a permutation of {0,...,19} and describe which cubie is at
* a certain position (regarding the input ordering). The first
* twelve are for edges, the last eight for corners.
*
* The last 20 entries are for the orientations, each describing
* how often the cubie at a certain position has been turned
* counterclockwise away from the correct orientation. Again the
* first twelve are edges, the last eight are corners. The values
* are 0 or 1 for edges and 0, 1 or 2 for corners.
*
**********************************************************************/

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

//----------------------------------------------------------------------

typedef vector<int> vi;

//----------------------------------------------------------------------

int applicableMoves[] = { 0, 262143, 259263, 74943, 74898 };

// TODO: Encode as strings, e.g. for U use "ABCDABCD"

int affectedCubies[][8] = {
{ 0, 1, 2, 3, 0, 1, 2, 3 }, // U
{ 4, 7, 6, 5, 4, 5, 6, 7 }, // D
{ 0, 9, 4, 8, 0, 3, 5, 4 }, // F
{ 2, 10, 6, 11, 2, 1, 7, 6 }, // B
{ 3, 11, 7, 9, 3, 2, 6, 5 }, // L
{ 1, 8, 5, 10, 1, 0, 4, 7 }, // R
};

vi applyMove ( int move, vi state ) {
int turns = move % 3 + 1;
int face = move / 3;
while( turns-- ){
vi oldState = state;
for( int i=0; i<8; i++ ){
int isCorner = i > 3;
int target = affectedCubies[face][i] + isCorner*12;
int killer = affectedCubies[face][(i&3)==3 ? i-3 : i+1] + isCorner*12;;
int orientationDelta = (i<4) ? (face>1 && face<4) : (face<2) ? 0 : 2 - (i&1);
state[target] = oldState[killer];
//state[target+20] = (oldState[killer+20] + orientationDelta) % (2 + isCorner);
state[target+20] = oldState[killer+20] + orientationDelta;
if( !turns )
state[target+20] %= 2 + isCorner;
}
}
return state;
}

int inverse ( int move ) {
return move + 2 - 2 * (move % 3);
}

//----------------------------------------------------------------------

int phase;

//----------------------------------------------------------------------

vi id ( vi state ) {
//--- Phase 1: Edge orientations.
if( phase < 2 )
return vi( state.begin() + 20, state.begin() + 32 );
//-- Phase 2: Corner orientations, E slice edges.
if( phase < 3 ){
vi result( state.begin() + 31, state.begin() + 40 );
for( int e=0; e<12; e++ )
result[0] |= (state[e] / 8) << e;
return result;
}
//--- Phase 3: Edge slices M and S, corner tetrads, overall parity.
if( phase < 4 ){
vi result( 3 );
for( int e=0; e<12; e++ )
result[0] |= ((state[e] > 7) ? 2 : (state[e] & 1)) << (2*e);
for( int c=0; c<8; c++ )
result[1] |= ((state[c+12]-12) & 5) << (3*c);
for( int i=12; i<20; i++ )
for( int j=i+1; j<20; j++ )
result[2] ^= state[i] > state[j];
return result;
}
//--- Phase 4: The rest.
return state;
}

//----------------------------------------------------------------------

int main ( int argc, char** argv ) {
//--- Define the goal.
string goal[] = { "UF", "UR", "UB", "UL", "DF", "DR", "DB", "DL", "FR", "FL", "BR", "BL",
"UFR", "URB", "UBL", "ULF", "DRF", "DFL", "DLB", "DBR" };
//--- Prepare current (start) and goal state.
vi currentState( 40 ), goalState( 40 );
for( int i=0; i<20; i++ ){
//--- Goal state.
goalState[i] = i;
//--- Current (start) state.
string cubie = argv[i+1];
while( (currentState[i] = find( goal, goal+20, cubie ) - goal) == 20){
cubie = cubie.substr( 1 ) + cubie[0];
currentState[i+20]++;
}
}
//--- Dance the funky Thistlethwaite...
while( ++phase < 5 ){
//--- Compute ids for current and goal state, skip phase if equal.
vi currentId = id( currentState ), goalId = id( goalState );
if( currentId == goalId )
continue;
//--- Initialize the BFS queue.
queue<vi> q;
q.push( currentState );
q.push( goalState );
//--- Initialize the BFS tables.
map<vi,vi> predecessor;
map<vi,int> direction, lastMove;
direction[ currentId ] = 1;
direction[ goalId ] = 2;
//--- Dance the funky bidirectional BFS...
while( 1 ){
//--- Get state from queue, compute its ID and get its direction.
vi oldState = q.front();
q.pop();
vi oldId = id( oldState );
int& oldDir = direction[oldId];
//--- Apply all applicable moves to it and handle the new state.
for( int move=0; move<18; move++ ){
if( applicableMoves[phase] & (1 << move) ){
//--- Apply the move.
vi newState = applyMove( move, oldState );
vi newId = id( newState );
int& newDir = direction[newId];
//--- Have we seen this state (id) from the other direction already?
//--- I.e. have we found a connection?
if( newDir && newDir != oldDir ){
//--- Make oldId represent the forwards and newId the backwards search state.
if( oldDir > 1 ){
swap( newId, oldId );
move = inverse( move );
}
//--- Reconstruct the connecting algorithm.
vi algorithm( 1, move );
while( oldId != currentId ){
algorithm.insert( algorithm.begin(), lastMove[ oldId ] );
oldId = predecessor[ oldId ];
}
while( newId != goalId ){
algorithm.push_back( inverse( lastMove[ newId ] ));
newId = predecessor[ newId ];
}
//--- Print and apply the algorithm.
for( int i=0; i<(int)algorithm.size(); i++ ){
cout << "UDFBLR"[algorithm[i]/3] << algorithm[i]%3+1;
currentState = applyMove( algorithm[i], currentState );
}
//--- Jump to the next phase.
goto nextPhasePlease;
}
//--- If we've never seen this state (id) before, visit it.
if( ! newDir ){
q.push( newState );
newDir = oldDir;
lastMove[ newId ] = move;
predecessor[ newId ] = oldId;
}
}
}
}
nextPhasePlease:
;
}
}
OS_Mirror/超有用的十个php代码片.md
【合集】超有用的十个php代码片,快收藏!来源:http://www.csdn.net/article/2013-07-23/2816316-10-php-snippets-for-developers#
  php 最后更新时间 2013-11-22 17:42:51
CodePudge/Ruby编辑器
直接复制这段代码,粘贴到浏览器地址栏即可运行!
  最后更新时间 2016-09-12 16:30:23
Ruby编辑器 1行 Text
Raw
 1
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
Vimiix/flower.html
  最后更新时间 2016-09-05 13:17:21
flower.html 44行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
<!DOCTYPE HTML>
<html><head>
<title>中秋快乐!</title>
<meta charset="utf-8" />
</head>
<body>
<h2>Fancy , 中秋快乐 !</h2>
<canvas id="c"></canvas>
<script>
var b = document.body;
var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d');
document.body.clientWidth;
</script>
<script>
with(m=Math)
C=cos,S=sin,P=pow,R=random;
c.width=c.height=f=500;
h=-250;
function p(a,b,c){
if(c>60)
return[S(a*7)*(13+5/(.2+P(b*4,4)))-S(b)*50,b*f+50,625+C(a*7)*(13+5/(.2+P(b*4,4)))+b*400,a*1-b/2,a];
A=a*2-1;
B=b*2-1;
if(A*A+B*B<1){
if(c>37){
n=(j=c&1)?6:4;o=.5/(a+.01)+C(b*125)*3-a*300;w=b*h;
return[o*C(n)+w*S(n)+j*610-390,o*S(n)-w*C(n)+550-j*350,1180+C(B+A)*99-j*300,.4-a*.1+P(1-B*B,-h*6)*.15-a*b*.4+C(a+b)/5+P(C((o*(a+1)+(B>0?w:-w))/25),30)*.1*(1-B*B),o/1e3+.7-o*w*3e-6]
}if(c>32){
c=c*1.16-.15;
o=a*45-20;
w=b*b*h;
z=o*S(c)+w*C(c)+620;
return[o*C(c)-w*S(c),28+C(B*.5)*99-b*b*b*60-z/2-h,z,(b*b*.3+P((1-(A*A)),7)*.15+.3)*b,b*.7]
}
o=A*(2-b)*(80-c*2);
w=99-C(A)*120-C(b)*(-h-c*4.9)+C(P(1-b,7))*50+c*2;
z=o*S(c)+w*C(c)+700;
return[o*C(c)-w*S(c),B*99-C(P(b, 7))*50-c/3-z/1.35+450,z,(1-b/1.2)*.9+a*.1, P((1-b),20)/4+.05]
}
}
setInterval('for(i=0;i<1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}',0)
</script>
</body></html>
hjimce/blog_20160313_1_181672
来自CSDN博客:Batch Normalization 学习笔记 http://blog.csdn.net/qq_26898461/article/details/51221166#
  最后更新时间 2016-04-22 16:26:04
blog_20160313_1_181672 4行 Python
Raw
 1
 2
 3
 4
m = K.mean(X, axis=-1, keepdims=True)#计算均值
std = K.std(X, axis=-1, keepdims=True)#计算标准差
X_normed = (X - m) / (std + self.epsilon)#归一化
out = self.gamma * X_normed + self.beta#重构变换
冰麟轻武/LoadResourceDll.cs
运行中加载资源中的dll http://www.cnblogs.com/blqw/p/LoadResourceDll.html#
  最后更新时间 2014-06-17 17:45:19
LoadResourceDll.cs 87行 C#
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text.RegularExpressions;

namespace blqw
{
/// <summary> 载入资源中的动态链接库(dll)文件
/// </summary>
public static class LoadResourceDll
{
/// <summary> 已加载DLL
/// </summary>
private static Dictionary<string, Assembly> LoadedDlls = new Dictionary<string, Assembly>();
/// <summary> 已处理程序集
/// </summary>
private static Dictionary<string, object> Assemblies = new Dictionary<string, object>();
/// <summary> 在对程序集解释失败时触发
/// </summary>
/// <param name="sender">AppDomain</param>
/// <param name="args">事件参数</param>
private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
//程序集
Assembly ass;
//获取加载失败的程序集的全名
var assName = new AssemblyName(args.Name).FullName;
//判断Dlls集合中是否有已加载的同名程序集
if (LoadedDlls.TryGetValue(assName, out ass) && ass != null)
{
LoadedDlls[assName] = null;//如果有则置空并返回
return ass;
}
else
{
throw new DllNotFoundException(assName);//否则抛出加载失败的异常
}
}

/// <summary> 注册资源中的dll
/// </summary>
/// <param name="pattern">*表示连续的未知字符,_表示单个未知字符,如*.dll</param>
public static void RegistDLL(string pattern = "*.dll")
{
System.IO.Directory.GetFiles("", "");
//获取调用者的程序集
var ass = new StackTrace(0).GetFrame(1).GetMethod().Module.Assembly;
//判断程序集是否已经处理
if (Assemblies.ContainsKey(ass.FullName))
{
return;
}
//程序集加入已处理集合
Assemblies.Add(ass.FullName, null);
//绑定程序集加载失败事件(这里我测试了,就算重复绑也是没关系的)
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
//获取所有资源文件文件名
var res = ass.GetManifestResourceNames();
var regex = new Regex("^" + pattern.Replace(".", "\\.").Replace("*", ".*").Replace("_", ".") + "$", RegexOptions.IgnoreCase);
foreach (var r in res)
{
//如果是dll,则加载
if (regex.IsMatch(r))
{
try
{
var s = ass.GetManifestResourceStream(r);
var bts = new byte[s.Length];
s.Read(bts, 0, (int)s.Length);
var da = Assembly.Load(bts);
//判断是否已经加载
if (LoadedDlls.ContainsKey(da.FullName))
{
continue;
}
LoadedDlls[da.FullName] = da;
}
catch
{
//加载失败就算了...
}
}
}
}
}
}