Wednesday, December 8, 2010

JQuery Templates for Visual Studio

I found a good blog on using JQuery Templates. Reposting here so I can find it again easily if I need it. Hopefully it helps anyone else that may find this as well.

http://weblogs.asp.net/dwahlin/archive/2010/11/20/reducing-code-by-using-jquery-templates.aspx

Additional info

http://api.jquery.com/category/plugins/templates.

You can download the jQuery Templates script here along with a sample application or reference one of the following Microsoft CDN scripts:

Thursday, October 21, 2010

Generic object TryParse

In my opinion whenever you need to parse a value you should always use the TryParse method to make your code more robust and able to handle errors better. The draw back to this is you and up writing a lot of if else statements. I got tired of doing this so was trying to find a more abstracted way to do this for all my values. I found this bit of code very handy. So far it has worked great!

public T GetValue<T>(object obj)
{
   if (obj != null)
   {
       Type type = typeof(T);
 
       T value = default(T);
       var methodInfo = (from m in type.GetMethods(BindingFlags.Public | BindingFlags.Static)
                         where m.Name == "TryParse"
                         select m).FirstOrDefault();
 
       if (methodInfo == null)
           return default(T);
 
       object result = methodInfo.Invoke(null, new object[] { obj, value });
       if ((result != null) && ((bool)result))
       {
           methodInfo = (from m in type.GetMethods(BindingFlags.Public | BindingFlags.Static)
                         where m.Name == "Parse"
                         select m).FirstOrDefault();
 
           if (methodInfo == null)
               return default(T);
 
           value = (T)methodInfo.Invoke(null, new object[] { obj });
 
           return (T)value;
       }
   }
 
   return default(T);
}

Monday, April 5, 2010

Hardening the TCP/IP Stack

I had to spend some time today writing a registry file that would harden the TCP/IP stack. I did not want to manually update all the servers so figured I would just set up a registry file to do it for me. Below is the setting you can put in a .reg file to harden the stack. REMINDER : this comes with no warranty and you should always backup your registry before you make any changes.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TcpIp\Parameters]
"SynAttackProtect"=dword:00000002
"TcpMaxPortsExhausted"=dword:00000001
"TcpMaxHalfOpen"=dword:000001f4
"TcpMaxHalfOpenRetried"=dword:00000190
"TcpMaxConnectResponseRetransmissions"=dword:00000002
"TcpMaxDataRetransmissions"=dword:00000002
"EnablePMTUDiscovery"=dword:00000000
"KeepAliveTime"=dword:000493e0

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netbt\Parameter]
"NoNameReleaseOnDemand"=dword:00000001

[HKLM\System\CurrentControlSet\Services\TcpIp\Parameters]
"EnableICMPRedirect"=dword:00000000

[HKLM\System\CurrentControlSet\Services\Tcpip\Parameters]
"EnableDeadGWDetect"=dword:00000000

[HKLM\System\CurrentControlSet\Services\AFD\Parameters]
"EnableDynamicBacklog"=dword:00000001
"MinimumDynamicBacklog"=dword:00000014
"MaximumDynamicBacklog"=dword:00004e20
"DynamicBacklogGrowthDelta"=dword:0000000a

[HKLM\System\CurrentControlSet\Services\Tcpip\Parameters]
"DisableIPSourceRouting"=dword:00000001
"EnableMulticastForwarding"=dword:00000000
"IPEnableRouter"=dword:00000000
"EnableAddrMaskReply"=dword:00000000

Share this post :