Skip to content

Instantly share code, notes, and snippets.

View wsky's full-sized avatar
🏠
Working from home

Harry wsky

🏠
Working from home
View GitHub Profile
@wsky
wsky / svn-ignore.sh
Created December 12, 2012 05:34
svn cmdline usual
export SVN_EDITOR=vim
svn propedit svn:ignore .
svn status --no-ignore
@wsky
wsky / BufferManager.cs
Created November 29, 2012 08:01
Socket Buffer Management/Pooling
//http://codebetter.com/gregyoung/2007/06/18/async-sockets-and-buffer-management/
namespace TickerPlant
{
/// <summary>
/// A manager to handle buffers for the socket connections
/// </summary>
/// <remarks>
/// When used in an async call a buffer is pinned. Large numbers of pinned buffers
/// cause problem with the GC (in particular it causes heap fragmentation).
@wsky
wsky / gist:4085597
Created November 16, 2012 08:51
JavaScript GUID
var guid = function () {
function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
};
@wsky
wsky / gist:4083436
Created November 16, 2012 02:36
how cooper and ark login intergrate
if(!isCooperLogin())//cooper是否通过登录验证
if(!isArkLogin())//arkclient是否通过登录验证
redirectToArklogin();//跳转到ark登录页面
else
setCooperLogin();//若ark通过验证则设置cooper通过验证写cookie
else
//...
// The code below would print overlapped A and B sequences like:
// ...
// A
// A
// B
// B
// ...
//
// Please add multi-threading protection code to make sure that
// As and Bs are printed in the order of:
@wsky
wsky / CompositeId.cs
Created September 12, 2012 13:54
FluentNHibernate usual mapping
CompositeId()
.KeyProperty(m => m.ID)
.KeyProperty(Reveal.Member<Method>("ServiceName"));
@wsky
wsky / gist:3550520
Created August 31, 2012 09:00
app.config supportedRuntime
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
@wsky
wsky / gist:3521554
Created August 30, 2012 01:47
checksum MD5
using (var md5 = new MD5CryptoServiceProvider())
{
var retVal = md5.ComputeHash(file);
var sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
sb.Append(retVal[i].ToString("x2"));
return Json(sb.ToString());
}
@wsky
wsky / gist:3336510
Created August 13, 2012 02:46
isMobileRegex
Regex isMobileRegex = new Regex(
@"(iemobile|iphone|ipod|android|nokia|sonyericsson|blackberry|samsung|sec\-|windows ce|motorola|mot\-|up.b|midp\-)"
,RegexOptions.IgnoreCase | RegexOptions.Compiled);
bool isMobileDevice = !string.IsNullOrEmpty(Request.UserAgent) && isMobileRegex.IsMatch(Request.UserAgent);
@wsky
wsky / gist:3225045
Created August 1, 2012 08:34
IsXmlHttpRequest
public static bool IsXmlHttpRequest(this HttpRequestBase request)
{
var header = request.Headers["X-Requested-With"];
return !string.IsNullOrEmpty(header) && header.ToLower().IndexOf("xmlhttp") >= 0;
}