SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
月度归档:2013年10月
Getting a string dynamically from strings resources
ResourceManager rm = new ResourceManager("RootResourceName", typeof(SomeClass).Assembly); string someString = rm.GetString("someString");
how to catch NULL values using case statement
select contactid,Title,FirstName,MiddleName, case ISNULL(MiddleName, 'NULLVALUE') when 'R.' then 'Robert' when 'B.' then 'Bids' when 'J.' then 'John' when 'NULLVALUE' then 'New Name' else 'No Name' end, LastName from Person.Contact
Node.js使用express解析cookie
首先使用cookieParser()解析请求头里的Cookie, 并用cookie名字的键值对形式放在 req.cookies 你也可以通过传递一个secret 字符串激活签名了的cookie 。
app.use(express.cookieParser());
app.use(express.cookieParser('some secret'));
下面是读写cookie的代码
var express = require('express');
var app = express();
app.get('/readcookie',function(req,res){
res.send('req.cookies.name:' + req.cookies.name);
});
app.get('/writecookie',function(req,res){
res.cookie('name', 'I'm a cookie', 60000);
res.send("cookie saved");
});
app.listen(3000);
console.log('listening on port 3000');
Node.js使用express处理静态文件,static file
var express = require('express'); var app = express(); // log requests app.use(express.logger('dev')); app.use(express.static(__dirname + '/public')); app.listen(1024); console.log('Listening on port 1024');
使用http://localhost:1024/css/style.css就可以读取/public/css/style.css文件了
Node.js教程起步资料
Tutorials
- Hello World
- Hello World Web Server
- Node.js guide
- Build a blog with Node.js, express and mongodb
- Node.Js Tutorials At Project 70
- Node.js for Beginners
Videos
- Node tuts
- Introduction to Node.js with Ryan Dahl
- Node.js: Asynchronous Purity Leads to Faster Development
- Parallel Programming with Node.js
- Server-side JavaScript with Node, Connect & Express
- Node.js First Look
- Ryan Dahl’s Google Tech Talk
Screencasts
Books
- The Node Beginner Book
- Mastering Node.js
- Up and Running with Node.js
- Node.js in Action
- Smashing Node.js: JavaScript Everywhere
- Node.js & Co. (in German)
- Sam’s Teach Yourself Node.js in 24 Hours
- Most detailed list of free JavaScript Books
Courses
Blogs
Podcasts
JavaScript resources
- Crockford’s videos (must see!)
- Essential JavaScript Design Patterns For Beginners
- JavaScript garden
- JavaScript Patterns book
- JavaScript: The Good Parts book
Node Modules
- Wiki List on Github/Joyent/Node (start here last!)
- Search for registered node.js modules
Other
.Net mvc自定义字符串截取(考虑全角/半角)
public static class HtmlHelpers
{
public static string Truncate(this HtmlHelper helper, string inputString, int length)
{
string tempString = string.Empty;
for (int i = 0, tempIndex = 0; i < inputString.Length; ++i, ++tempIndex)
{
if (System.Text.Encoding.UTF8.GetBytes(new char[] { inputString[i] }).Length > 1)
{
++tempIndex;
}
if (tempIndex >= length)
{
tempString += "...";
break;
}
tempString += inputString[i];
}
return tempString;
}
}