Monday, December 31, 2012

How to ask user if want to leave current page in JavaScript?


Add function into onbeforeunload
var unsavedChanges = false;
window.onbeforeunload = function() {
  if (unsavedChanges) return 'You have unsaved changes!';
}

https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload

Saturday, December 29, 2012

How to convert SQL Server's timestamp column to datetime?

No. You can't
SQL Server's timestamp just an incrementing number and does not preserve a date or a time.

How to get client IP address?

How to get client IP address?
HttpContext.Request.UserHostAddress

How to fix "The name does not exist in the current context" in ASP.NET webforms?

Delete all of content in designer.cs, let Visual Studio generate again.

10 Web Predictions for 2012: the Results!

http://www.sitepoint.com/2012-web-prediction-results/

Wednesday, December 26, 2012

Why session id changes every time in ASP.NET?

Why session id changes every time in ASP.NET?
protected void Session_Start(Object sender, EventArgs e) 
{
    Session["init"] = 0;
}
http://msdn.microsoft.com/en-ca/library/system.web.sessionstate.httpsessionstate.sessionid.aspx
a new session ID is generated for each page request until the session object is accessed. If your application requires a static session ID for the entire session, you can either implement the Session_Start method in the application's Global.asax file and store data in the Session object to fix the session ID, or you can use code in another part of your application to explicitly store data in the Session object.

Monday, December 24, 2012

How to get first td in each tr of one table by jQuery?

$("#myTable tr td:first-child").addClass("diyi");

Thursday, December 20, 2012

How to change entity framework connection string dynamically

Use constructor with connection string
http://msdn.microsoft.com/en-us/library/bb739017.aspx

var db = new dbContext(connectionString);

How to change ASP.NET membership database connection string dynamically?

By reflection:
        private void SetProviderConnectionString(string connectionString)
        {
            // Set private property of Membership, Role and Profile providers.
            FieldInfo connectionStringField = Membership.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic); 
            if (connectionStringField != null)
                connectionStringField.SetValue(Membership.Provider, connectionString);

            FieldInfo roleField = Roles.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
            if (roleField != null)
                roleField.SetValue(Roles.Provider, connectionString);

            FieldInfo profileField = ProfileManager.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
            if (profileField != null) 
                profileField.SetValue(ProfileManager.Provider, connectionString);
        }

How to call WCF service in ASP.NET ?

Add following setting in web.config:


  
    
      
      
    
  
  
    
      
        
      
    
  

http://msdn.microsoft.com/en-ca/library/bb763177(v=vs.90).aspx

How to solve "CustomError for 403 Forbidden not working"?


In IIS 7 add following settings into web.config
  
    
      
      
      
      
    
   
  

How to use QR code in ASP.NET MVC?

The lib is: QRCODENET
http://qrcodenet.codeplex.com/


public ActionResult QRImage(int id)
        {
            string url = string.Format("http://myevents.apphb.com/event/details/{0}", id);
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode qrCode = qrEncoder.Encode(url);

            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);
            MemoryStream ms = new MemoryStream();
            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms);
            byte[] image = ms.ToArray(); ;
            return File(image, "image/png");
        }

Wednesday, December 19, 2012

Reverse polish notation in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Threading;
 
namespace RPNEvaluator
{
    class RPNEvaluator
    {
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
 
            string rpn = "3 4 2 * 1 5 - 2 3 ^ ^ / +";
            Console.WriteLine("{0}\n", rpn);
 
            decimal result = CalculateRPN(rpn);
            Console.WriteLine("\nResult is {0}", result);
        }
 
        static decimal CalculateRPN(string rpn)
        {
            string[] rpnTokens = rpn.Split(' ');
            Stack stack = new Stack();
            decimal number = decimal.Zero;
 
            foreach (string token in rpnTokens)
            {
                if (decimal.TryParse(token, out number))
                {
                    stack.Push(number);
                }
                else
                {
                    switch (token)
                    {
                        case "^":
                        case "pow":
                            {
                                number = stack.Pop();
                                stack.Push((decimal)Math.Pow((double)stack.Pop(), (double)number));
                                break;
                            }
                        case "ln":
                            {
                                stack.Push((decimal)Math.Log((double)stack.Pop(), Math.E));
                                break;
                            }
                        case "sqrt":
                            {
                                stack.Push((decimal)Math.Sqrt((double)stack.Pop()));
                                break;
                            }
                        case "*":
                            {
                                stack.Push(stack.Pop() * stack.Pop());
                                break;
                            }
                        case "/":
                            {
                                number = stack.Pop();
                                stack.Push(stack.Pop() / number);
                                break;
                            }
                        case "+":
                            {
                                stack.Push(stack.Pop() + stack.Pop());
                                break;
                            }
                        case "-":
                            {
                                number = stack.Pop();
                                stack.Push(stack.Pop() - number);
                                break;
                            }
                        default:
                            Console.WriteLine("Error in CalculateRPN(string) Method!");
                            break;
                    }
                }
                PrintState(stack);
            }
 
            return stack.Pop();
        }
 
        static void PrintState(Stack stack)
        {
            decimal[] arr = stack.ToArray();
 
            for (int i = arr.Length - 1; i >= 0; i--)
            {
                Console.Write("{0,-8:F3}", arr[i]);
            }
 
            Console.WriteLine();
        }
    }
}

How to change checkbox size?

The behavior is different in browsers. And maximum size is limited.


How to solve "Service has zero application endpoints" in WCF host

Check service name in config file
Make sure it is a full name with all the namespace path

Building Back-end Data and Services for Windows 8 Apps: ASP.NET Web API

http://devhammer.net/blog/building-back-end-data-and-services-for-windows-8-apps-asp.net-web-api

Glimpse, A client side Glimpse to your server



http://getglimpse.com/Help/Plugin/Server

Monday, December 17, 2012

How to convert int32 into binary string (0/1)?

How to convert int32 into binary string (0/1)?
function createBinaryString (nMask) {
  // nMask must be between -2147483648 and 2147483647
  for (var nFlag = 0, nShifted = nMask, sMask = ""; nFlag < 32; nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1);
  return sMask;
}
  
var string1 = createBinaryString(11);
var string2 = createBinaryString(4);
var string3 = createBinaryString(1);
  
alert(string1);
// prints 00000000000000000000000000001011, i.e. 11
var bits=string1.split("");

Friday, December 14, 2012

What is difference between "throw" and "throw ex" in catch block?

Please use "throw" only,  this way, will keep original exception

ASP.NET and Web Tools 2012.2

http://www.asp.net/vnext/overview/fall-2012-update

Enhancements to Web Publishing
New Web API functionality
New templates for Facebook Application and Single Page Application
Real-time communication via ASP.NET SignalR
Extensionless Web Forms via ASP.NET Friendly URLs
Support for the new Windows Azure Authentication

How to display currency in Javascript?

Number.prototype.formatMoney = function (c, d, t) {
    var n = this,
        c = isNaN(c = Math.abs(c)) ? 2 : c,
        d = d == undefined ? "," : d,
        t = t == undefined ? "." : t,
        s = n < 0 ? "-" : "",
        i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
        j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

//Usage: 

(123456789.12345).formatMoney(2, '.', ',');

http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript

Inline Editing With The WebGrid

http://www.mikesdotnetting.com/Article/202/Inline-Editing-With-The-WebGrid



Thursday, December 13, 2012

How disable a key by jQuery?

$('html').bind('keypress', function(e)
{
   if(e.keyCode == 80 || e.keyCode == 112)
   {
      return false;
   }
})

Wednesday, December 12, 2012

How to solve problem "Configuration file is not well-formed XML" in web.config with ampersand

replace ampersane & with &amp;

Why: web.config is in the format of XML 1.0:
The ampersand character (&) and the left angle bracket (<) may appear in their literal form only when used as markup delimiters, or within acomment, a processing instruction, or a CDATA section. If they are needed elsewhere, they must be escaped using either numeric character references or the strings "&amp;" and "&lt;" respectively

Monday, December 10, 2012

How to iterate an Enum in C#?

            Array values = Enum.GetValues(typeof(MyEnumType));
            foreach (MyEnumType val in values)
            {
                var enumName = Enum.GetName(typeof(MyEnumType), val);
            }

Why should not use Session variable for better performence in ASP.NET?

However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished. 

http://msdn.microsoft.com/en-au/library/ms178581(v=vs.100).aspx

Re-Use MVC Views Across Projects With Razor Generat

http://blog.mirajavora.com/re-use-mvc-views-across-projects-with-razor-generator
Razor-Generator-Extension

Friday, December 7, 2012

Think First, Code Later

http://24ways.org/2012/think-first-code-later/

You, or someone just like you, have been building a website, probably as part of a skilled and capable team. You’re a front-end developer, focusing on JavaScript – it’s either your sole responsibility or shared around. It’s quite a big job, been going on for months, and at last it feels like you’re reaching the end of it

Thursday, December 6, 2012

How to fix "An unhandled Microsoft.NET Framework exception occured in w3wp.exe"

Change the ApplicationPoolIdentity of the application pool for your project to an account such as Local System.

How to install ASP.NET MVC4 into Visual Studio 2010?

http://www.microsoft.com/en-us/download/details.aspx?id=30683

How to disable session in ASP.NET MVC?

Two levels:
Application level is in web.config
<sessionState mode="Off" />

Controller level
[SessionState(SessionStateBehaviour.Disabled)]
public class MyController : Controller
{}

Wednesday, December 5, 2012

Monday, December 3, 2012

Why All The Lambdas in ASP.NET MVC?

http://odetocode.com/blogs/scott/archive/2012/11/26/why-all-the-lambdas.aspx


- If Model is null, the code will fail with an exception.
- We aren't providing any client side validation support.
- We have no ability to display an alternate value (like an erroneous value a user entered on a previous form submission – we want to redisplay the value, show an error message, and allow the user to fix simple typographical errors).


What is .d in Json result?


it protects from a tricky JSON hijacking scenario that exists when the outer JSON entity is an array.
http://stackoverflow.com/questions/2811525/removing-the-d-object-from-asp-net-web-service-json-output

http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/

3.5 JSON Response in Firebug

Thursday, November 29, 2012

How to read database connection string from web.config?

 System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

How to generate ASPX dynamically?

By Razor engine
http://razorengine.codeplex.com/

  string template = @"<%@ Control Language="C#" ClassName="@Model.Name" %>";
  string result = Razor.Parse(template, new { Name = "Classname" });

Wednesday, November 28, 2012

How to add dynamic field in OTRS?


1. Cretae dynamic field first
Admin->Ticket->Dynamic Field

2. Change configuration to make avaiblae in different view
Goto Admin -> SysConfig
search by ###DynamicField
Enable the dynamic field just created
There are a lot of setting for different views.

RavenDB and DataTables.Ne

http://antjanus.com/blog/web-development-tutorials/how-to-with-ravendb-and-datatables-net/

directory alt by brujo 1024x768 How To with RavenDB and DataTables.Net

Friday, November 23, 2012

ASP.NET web SQL Utility

http://www.codeproject.com/Articles/15408/Web-SQL-Utility

A nice and small tool to show the query result for MS SQL Server and Access database

Thursday, November 22, 2012

Make a Captcha Image Validation with Jquery and MVC

 http://www.codeproject.com/Tips/494536/Make-a-Captcha-Image-Validation-with-Jquery-and-MV

   <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            loadCaptcha();
        });
        function loadCaptcha() {
            $.ajax({
                type: 'GET', url: 'Home/generateCaptcha',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                success: function (data) { $("#m_imgCaptcha").attr('src', data); },
                error: function (data) { alert("Error while loading captcha image") }
            });
        }
    </script> 


public ActionResult generateCaptcha()
        {
            System.Drawing.FontFamily family = new System.Drawing.FontFamily("Arial");
            CaptchaImage img = new CaptchaImage(150, 50, family);
            string text = img.CreateRandomText(4) + " " + img.CreateRandomText(3);
            img.SetText(text);
            img.GenerateImage();
            img.Image.Save(Server.MapPath("~") + this.Session.SessionID.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
            Session["captchaText"] = text;
            return Json(this.Session.SessionID.ToString() + ".png?t=" + DateTime.Now.Ticks, JsonRequestBehavior.AllowGet);
        } 

Wednesday, November 21, 2012

What is OTRS?

OTRS is an Open-source Ticket Request System, developed by Perl, default database is MySQL.
http://www.otrs.com

Following link is a group of tips for integrating OTRS into .Net project
http://rayaspnet.blogspot.ca/search/label/OTRS

Tuesday, November 20, 2012

How to call OTRS web service in C#?

There are two ways for calling web service to create/get/search ticket in OTRS:
First way: call RPC.pl
Second way: GenericInterface

Follwoing are the steps for RPC:
1. Setup SOAP user in OTRS:
Log in OTRS with FULL admin permission
Admin -> SysConfig -> Framework -> Core: SOAP
Add and enable SOAP user and password
2. In C# project, prepare SOAP request like following
Then make Webrequest for URL: http://localhost/otrs/RPC.pl

<?xml version=""1.0"" encoding=""utf-8""?>
  <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
soap:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
    <soap:Body>
      <Dispatch xmlns=""/Core"">
        <c-gensym4 xsi:type=""xsd:string"">soapUserName</c-gensym4>
        <c-gensym6 xsi:type=""xsd:string"">soapUserPassword</c-gensym6>
        <c-gensym8 xsi:type=""xsd:string"">TicketObject</c-gensym8>
        <c-gensym10 xsi:type=""xsd:string"">TicketSearch</c-gensym10>
        <c-gensym57 xsi:type=""xsd:string"">Limit</c-gensym57>
        <c-gensym59 xsi:type=""xsd:int"">10000</c-gensym59>
        <c-gensym8 xsi:type=""xsd:string"">Result</c-gensym8>
        <c-gensym10 xsi:type=""xsd:string"">ARRAY</c-gensym10>
        <c-gensym57 xsi:type=""xsd:string"">UserID</c-gensym57>
        <c-gensym59 xsi:type=""xsd:int"">1</c-gensym59>
      </Dispatch>
    </soap:Body>
  </soap:Envelope>
3. The result is in the XML format
If you meet problem, please give me an email, may I help a little bit. wangchiwei@gmail.com

How I went from $100-an-hour programming to $X0,000-a-week consulting.

https://training.kalzumeus.com/newsletters/archive/consulting_1

- Clients Pay For Value, Not For Time
- Charging Weekly: It Makes Everything Automatically Better
- Getting Clients: The Importance Of Social Proof
- Scaling A Consulting Business
- Hybridizing Consultancies With Product Businesses

Monday, November 19, 2012

Asynchronous partial views

http://blog.michaelckennedy.net/2012/11/13/improve-perceived-performance-of-asp-net-mvc-websites-with-async-partialviews/




Friday, November 16, 2012

The Eight Levels of Programmers

twisted-sister-i-wanna-rock-video-still-frame.jpg
http://www.codinghorror.com/blog/2009/04/the-eight-levels-of-programmers.html

Thursday, November 15, 2012

How to get current assembly version and build time?


        private static string GetAssemblyVersionBuildDate()

        {
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);

            return "v"+ System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString() + " "+ dt.ToString();
        }

How to access session variables from anywhere in ASP.NET?


By full path like this:
System.Web.HttpContext.Current.Session["sessionVarName"];

How to remove local mapping in TFS?

How to remove local mapping in TFS?
1. In team exploerer, Open that folder
2. Go File -> Source Control -> Remove mapping (It is dynamic menu item)

Coexistence of projects between Visual Studio 2010 and 2012

http://weblogs.asp.net/sreejukg/archive/2012/10/17/coexistence-of-projects-between-visual-studio-2010-and-2012.aspx

clip_image001

Wednesday, November 14, 2012

How to parse html tag by HTML Agility pack?

 http://www.codeplex.com/htmlagilitypack
 
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(@"<html><body><p><table id=""foo""><tr><th>hello</th></tr><tr><td>world</td></tr></table></body></html>");
 
foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table")) {
    Console.WriteLine("Found: " + table.Id);
    foreach (HtmlNode row in table.SelectNodes("tr")) {
        Console.WriteLine("row");
        foreach (HtmlNode cell in row.SelectNodes("th|td")) {
            Console.WriteLine("cell: " + cell.InnerText);
        }
    }

CDN for jquery UI themes

http://stackoverflow.com/questions/1348559/are-there-hosted-jquery-ui-themes-anywhere



  • base: Google CDNMicrosoft CDN
  • black-tie: Google CDNMicrosoft CDN
  • blitzer: Google CDNMicrosoft CDN
  • cupertino: Google CDNMicrosoft CDN
  • dark-hive: Google CDNMicrosoft CDN
  • dot-luv: Google CDNMicrosoft CDN
  • eggplant: Google CDNMicrosoft CDN
  • excite-bike: Google CDNMicrosoft CDN
  • flick: Google CDNMicrosoft CDN
  • hot-sneaks: Google CDNMicrosoft CDN
  • humanity: Google CDNMicrosoft CDN
  • le-frog: Google CDNMicrosoft CDN
  • mint-choc: Google CDNMicrosoft CDN
  • overcast: Google CDNMicrosoft CDN
  • pepper-grinder: Google CDNMicrosoft CDN
  • redmond: Google CDNMicrosoft CDN
  • smoothness: Google CDNMicrosoft CDN
  • south-street: Google CDNMicrosoft CDN
  • start: Google CDNMicrosoft CDN
  • sunny: Google CDNMicrosoft CDN
  • swanky-purse: Google CDNMicrosoft CDN
  • trontastic: Google CDNMicrosoft CDN
  • ui-darkness: Google CDNMicrosoft CDN
  • ui-lightness: Google CDNMicrosoft CDN
  • vader: Google CDNMicrosoft CDN


  • How to solve problem, jQuery UI datepicker not working in IE9?

    http://rayaspnet.blogspot.ca/2011/12/how-to-avoid-quirks-mode-in-ie.html

    Put this line into the first place
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
    </head>


    or set this meta tag in IIS server into HTTP response headers.

    Reference:
    How to avoid compatibility view and quirk mode in IE?


    Synchronizing webpages across devices with SignalR

    http://lostechies.com/erichexter/2012/10/30/synchronizing-webpages-across-devices-home-automation/


    Tuesday, November 13, 2012

    ASP.NET SignalR

    http://weblogs.asp.net/davidfowler/archive/2012/11/11/microsoft-asp-net-signalr.aspx
    VsIntegration

    Monday, November 12, 2012

    How to set field value by reflection in C#?

                Class1 result1 = new Class1();
                FieldInfo[] fields = result1.GetType().GetFields(BindingFlags.Public| BindingFlags.Instance);
                foreach (var f in fields)
                {
                    f.SetValue(result1, Convert.ChangeType("1", f.FieldType));
                }

    How to Configure log4net with asp.net step by step

    http://ruchirac.blogspot.ca/2012/10/configure-log4net-with-aspnet-logging.html

    Wednesday, November 7, 2012

    How to solve error "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF"?

    There are two ways to sovle the problem:
    1: Add this setting into config file?
    <configuration>
     <system.net>
      <settings>
       <httpWebRequest useUnsafeHeaderParsing="true" />
      </settings>
     </system.net>
    </configuration>

    2. Call following function first
            public static bool setAllowUnsafeHeaderParsing()
            {
                //Get the assembly that contains the internal class
                Assembly aNetAssembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
                if (aNetAssembly != null)
                {
                    //Use the assembly in order to get the internal type for the internal class
                    Type aSettingsType = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");
                    if (aSettingsType != null)
                    {
                        //Use the internal static property to get an instance of the internal settings class.
                        //If the static instance isn't created allready the property will create it for us.
                        object anInstance = aSettingsType.InvokeMember("Section",
                          BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });
                        if (anInstance != null)
                        {
                            //Locate the private bool field that tells the framework is unsafe header parsing should be allowed or not
                            FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
                            if (aUseUnsafeHeaderParsing != null)
                            {
                                aUseUnsafeHeaderParsing.SetValue(anInstance, true);
                                return true;
                            }
                        }
                    }
                }
                return false;
            }

    How to install SOAP::Lite module into OTRS on Windows IIS server?


    Run Perl\bin\ppm.bat as administrator
    Search SOAP and install it

    How to set up SOAP / Web service user for OTRS?

    - Login into your existing OTRS Installation as Admin
    - in the Menu under “Admin”->”Sysconfig” set Group to “Framework” and click “show”
    - In the list of subgroups click “Core::SOAP”
    - Check the boxes for SOAP::User: and SOAP::Password: and enter the values you like
    - click update

    http://www.iniy.org/?p=20

    Where is database connection setting in OTRS?

    Under folder:
    \OTRS\Kernel

    File name is config.pm

    Reference:
    http://doc.otrs.org/2.1/en/html/c1154.html

    How to get download file length by WebClient?

                byte[] buffer;
                var client = new WebClient();
                buffer = client.DownloadData("http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js");
                Stream strm = new MemoryStream(buffer);
                var fileLength = strm.Length;

    Wednesday, October 31, 2012

    Tuesday, October 30, 2012

    How to disable copy/cut/paste for html textbox by jQuery

    <script type="text/javascript">
       $(document).ready(function(){
            $('#txtInput').live("cut copy paste",function(e) {
                    e.preventDefault();
                });
            });
      </script>

    Monday, October 29, 2012

    Web design trends

    http://weavora.com/blog/2012/10/21/web-design-trends-we-love/

    Single page websites

    Once frowned upon by both clients and designers, long pages which require a lot of scrolling are now all over the web. One explanation is that users are so accustomed to vertical scrolling (assisted by mouse wheel) that it’s actually worse to split the content on separate pages – it requires more effort from users to find it and reach it.
     
    Single page websites

    Google Architecture

    Update 2: Sorting 1 PB with MapReduce. PB is not peanut-butter-and-jelly misspelled. It's 1 petabyte or 1000 terabytes or 1,000,000 gigabytes. It took six hours and two minutes to sort 1PB (10 trillion 100-byte records) on 4,000 computers and the results were replicated thrice on 48,000 disks.
    Update: Greg Linden points to a new Google article MapReduce: simplified data processing on large clusters. Some interesting stats: 100k MapReduce jobs are executed each day; more than 20 petabytes of data are processed per day; more than 10k MapReduce programs have been implemented; machines are dual processor with gigabit ethernet and 4-8 GB of memory.

    http://highscalability.com/google-architecture