Skip to content

Instantly share code, notes, and snippets.

@xxli807
xxli807 / SQLP.sql
Created May 8, 2016 03:14
SQL Performace Script
// check the current session connections
SELECT login_name, [program_name], COUNT(session_id) AS [session_count]
FROM sys.dm_exec_sessions WITH (NOLOCK)
GROUP BY login_name,[program_name]
ORDER BY COUNT(session_id) desc;
// session connection based on the individual database
SELECT DB_NAME(dbid) AS DBName, COUNT(dbid) AS NumberOfConnections, loginame AS LoginName
FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid,loginame
@xxli807
xxli807 / DateTime Extension
Created April 26, 2015 11:32
DateTime Extension
///summary
///DateTime extension is also commonly used
///summary
public static class DateTimeExtensions
{
private const string _auNormalTimeFormat = "hh:mm tt";
private const string _auNormalDateFormat = "dd/MM/yyyy";
private const string _auNormalDateTimeFormat = "dd/MM/yyyy hh:mm tt";
private const string _normalDateFormat = "yyyy-MM-dd";
private const string _normalDateTimeFormat = "yyyy-MM-dd h:mm tt";
@xxli807
xxli807 / String Extension
Created April 26, 2015 11:25
String Extension
///summary
/// the most common way will be used in string conversion
///summary
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(this string str)
{
return string.IsNullOrWhiteSpace(str);
}
@xxli807
xxli807 / IEnumableExtension
Created April 26, 2015 11:21
IEnumableExtension
///Summary
///IEnumableExtension is another common used in c# MVC. In the dropdown List
///Summary
public static class IEnumerableExtensions
{
public static string JoinString(this IEnumerable<string> values)
{
return JoinString(values, ",");
}
@xxli807
xxli807 / enum
Created April 26, 2015 11:09
Enum Extension
///Summary
///enum extension are used commonly in C#
///Summary
public static class EnumExtensions
{
public static string GetDisplayText(this Enum e)
{
object value = e;
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
if (fieldInfo == null)
@xxli807
xxli807 / sql server hosts
Last active August 29, 2015 14:17
hosts file Modify on server
Under many situations the web server needs to call the application server which sits in the server server. It will be fine if the server address is used in ip address format. But if the application is also used for external application. So have to use the domain name of the server. so for windows server we need to map the hosts file (system32/dirves/etc/hosts) to the domain name for example: 127.0.0.1 to the xx.com.au domain. Otherwise it will throw a connection time out exception.
@xxli807
xxli807 / gmail api
Created March 24, 2015 09:33
Using .net invoke gmail client
/// using system.net.mail API
///enable the api using port number. SMTP using 587
public void sendGmail(host, port){
var form="fromEmail";
var to ="toEmail";
var mail = new MailMessage(from, to){
BodyEncoding = Encoding.GetEncoding(
Thread.CurrentThread.CurrentCulture.TextInfo.ANSICodePage),
Subject ="subject",
Body = "",
.NET MVC project to speed up the start/load:
1: under IIS chose the site and advance setting, set the automatically to true
2: application pool advanced setting, set the automatically to true
3: CPU interval to 0
4: Rapid-Fail protection to 0
5: Recycling time interval depending on the period when there are more requests
6: under web.config system.webServer section add the following (for IIS 7.5 ABOVE)
<applicationInitialization skipManagedModules="true"> <add initializationPage="/" /></applicationInitialization>
@xxli807
xxli807 / System architect
Last active August 29, 2015 14:15
.NET C#, IOC, EF, MVC, Jquery etc.
.NET MVC4 technology introduction
//if have time, I will write the detail information....
front-end(Js library)
moment.js --used for date time
underscore.js-used for template,ROM
jquery/bootstrap
datatable.js--used for table
stickem.js--used for absulate position
date-picker.js--for date time display
@xxli807
xxli807 / ldaps.java
Created February 14, 2015 09:38
Java get x.509 certificate from Ldaps
//get the x.509 certificate from the ldaps server and convert to pemstring
public String ContextSearchLDAPs() throws NamingException {
//create the hashtable to store the parameters to retrieve the data
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
//set the provider URL
env.put(Context.PROVIDER_URL, providerURL);
//important, this is used to let the server return the binary data
env.put("java.naming.ldap.attributes.binary", searchAttribute);
// Principal and credentials will be obtained from the connection, // cn,ou,o