Skip to content

Instantly share code, notes, and snippets.

@yushiro
yushiro / xpath
Last active December 19, 2015 07:09
.NET(C#):使用XPath查询带有命名空间(有xmlns)的XML
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="dotnet" xmlns:w="wpf">
<!-- xmlns: dotnet -->
<a>data in a</a>
<!-- xmlns: dotnet -->
<w:b>data in b</w:b>
<!-- xmlns: wpf -->
<c xmlns="silverlight">
<!-- xmlns: silverlight -->
<w:d>
@yushiro
yushiro / gist:5919323
Created July 3, 2013 15:26
java遍历map的集中用法(执行效率),通过Map.entrySet遍历key和value
System.out.println("通过Map.entrySet遍历key和value:");
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= "
+ entry.getValue());
}
@yushiro
yushiro / sql
Created July 9, 2013 08:45
sql function的创建
--创建函数(返回varchar类型的值)
create function test(@Num varchar(20))--@Num 参数
returns varchar(50) --返回值类型
as
begin
declare @MSG varchar(20)
if(@Num =1)
select @MSG ='正确'
else
select @MSG ='错误'
@yushiro
yushiro / split.sql
Created July 10, 2013 14:18
sql split function
-- =============================================
-- Author: Md. Marufuzzaman
-- Create date:
-- Description: Split an expression.
-- Note: If you are using SQL Server 2000, You need to change the
-- length (MAX) to your maximum expression length of each datatype.
-- =============================================
/*
SELECT * FROM [dbo].[SPLIT] (';','I love codeProject;!!!;Your development resources')
*/
public class LevenshteinDistance
{
/// <summary>
/// 取最小的一位数
/// </summary>
/// <param name="first"></param>
/// <param name="second"></param>
/// <param name="third"></param>
/// <returns></returns>
private int LowerOfThree(int first, int second, int third)
@yushiro
yushiro / jsreg
Created July 23, 2013 10:00
JS正则表达式获取分组内容的方法
js 代码
var testStr = "now test001 test002";
var re = /test(\d+)/ig;
var r = "";
while(r = re.exec(testStr)) {
alert(r[0] + " " + r[1]);
}
此外也可以用testStr.match(re),但是这样的话就不能有g的选项,而且只能得到第一个匹配。
另外备忘一下:
正则表达式对象的属性及方法:
@yushiro
yushiro / linux.md
Last active December 21, 2015 12:08
linux tips

vim中设置了autoindent后,粘帖带缩进的代码会造成多余的缩进。 用下面的代码解决这个问题

:r! cat 
//and then paste ( shift + insert ) the content, and CTRL+D.
@yushiro
yushiro / newline_fixer.py
Created September 6, 2013 15:44
解决'files list file for package 'xxx' is missing final newline' 的BUG
# 8th November, 2009
# update manager failed, giving me the error:
# 'files list file for package 'xxx' is missing final newline' for every package.
# some Googling revealed that this problem was due to corrupt files(s) in /var/lib/dpkg/info/
# looping though those files revealed that some did not have a final new line
# this script will resolve that problem by appending a newline to all files that are missing it
# NOTE: you will need to run this script as root, e.g. sudo python newline_fixer.py
import os
@yushiro
yushiro / csshack.md
Last active December 25, 2015 01:58
css hack tips

IE7 inline-block CSS BUG

.sample {
    display: inline-block;
    zoom: 1;
    *display: inline;
}

创建自增字段

ALTER TABLE tablename ADD COLUMN RowId integer identity Primary Key

判断字段名是否存在

            using (OleDbConnection conn = new OleDbConnection(_connStr))
            {
 conn.Open();