Thursday, June 30, 2011

What is OR operator in jQuery selector, Multiple selector


Comma (,)
Put comma between difference selectors, you can get combine result. OR operator.

$("div,span,p.myClass").css("border","3px solid red");

In jQuery, call Multiple selector

Reference:
http://api.jquery.com/multiple-selector/

Wednesday, June 29, 2011

What is prototype Property in JavaScript

The prototype property allows you to add properties and methods to any object.
A prototype property is automatically created for every function, to allow for the possibility that the function will be used as a constructor
(Every function in Javascript is an instance of the Function object)
JavaScript prototype Property

Tuesday, June 28, 2011

What is Facebook's architecture?

What is Facebook's architecture? - Quora: "What is Facebook's architecture?"


  • Web front-end written in PHP. Facebook's HipHop [1] then converts it to C++ and compiles it using g++, thus providing a high performance templating and Web logic execution layer
  • Business logic is exposed as services using Thrift [2]. Some of these services are implemented in PHP, C++ or Java depending on service requirements (some other languages are probably used...)
  • Services implemented in Java don't use any usual enterprise application server but rather use Facebook's custom application server. At first this can look as wheel reinvented but as these services are exposed and consumed only (or mostly) using Thrift, the overhead of Tomcat, or even Jetty was probably too high with no significant added value for their need.
  • Persistence is done using MySQL, Memcached [3], Facebook's Cassandra [4], Hadoop's HBase [5]. Memcached is used as a cache for MySQL as well as a general purpose cache. Facebook engineers admit that their use of Cassandra is currently decreasing as they now prefer HBase for its simpler consistency model and its MapReduce ability.
  • Offline processing is done using Hadoop and Hive
  • Data such as logging, clicks and feeds transit using Scribe [6] and are aggregating and stored in HDFS using Scribe-HDFS [7], thus allowing extended analysis using MapReduce
  • BigPipe [8] is their custom technology to accelerate page rendering using a pipelining logic
  • Varnish Cache [9] is used for HTTP proxying. They've prefered it for its high performance and efficiency [10].
  • The storage of the billions of photos posted by the users is handled by Haystack, an ad-hoc storage solution developed by Facebook which brings low level optimizations and append-only writes [11].
  • Facebook Messages is using its own architecture which is notably based on infrastructure sharding and dynamic cluster management. Business logic and persistence is encapsulated in so-called 'Cell'. Each Cell handles a part of users ; new Cells can be added as popularity grows [12]. Persistence is achieved using HBase [13].
  • Facebook Messages' search engine is built with an inverted index stored in HBase [14]
  • Facebook Search Engine's implementation details are unknown as far as I know
  • The typeahead search uses a custom storage and retrieval logic [15]
  • Chat is based on an Epoll server developed in Erlang and accessed using Thrift [16]

Tips for building Nuget packages

http://lostechies.com/joshuaflanagan/2011/06/23/tips-for-building-nuget-packages/

The Web Is Shrinking


http://allthingsd.com/20110623/the-web-is-shrinking-now-what/

Monday, June 27, 2011

Table Splitting in Entity Framework

http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx

What is SassAndCoffee

http://blog.paulbetts.org/index.php/2011/06/06/new-release-sassandcoffee-0-9-now-not-glacially-slow/


SassAndCoffee is a library for ASP.NET (both MVC and old-school WebForms) that adds drop-in support for two new languages: Sass and SCSS, a language that allows you to write reusable, more structured CSS, as well as CoffeeScript, which is a JavaScript dialect that is much more syntactically elegant, but still preserving 100% compatibility with regular JavaScript.

ActionMethodSelectorAttribute for Multiple Submit Buttons in ASP.NET MVC

http://www.dotnetcurry.com/(X(1)S(3n14c545mislet45ps2pyu55))/ShowArticle.aspx?ID=724

RazorGenerator for ASP.NET MVC

http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html

How to use Microsoft Translator service with screenshots and example

As the web grows, more and more international businesses are turning to the web. The demand for a multi-lingual website has never been so great. There are currently a few pay services out there that offer a translation API and also a few free ones (Google and Microsoft). One of the services that I have been looking at recently is the Microsoft Translator service. The API has support for SOAP, AJAX and HTTP which is a great addition to the API.

http://deanhume.com/Home/BlogPost/microsoft-translator-api/55 

Sunday, June 26, 2011

Most programmers write about 10-12 lines of code per day

My experience as a programmer  has taught me a few things about writing software. Here are some things that people might find surprising about writing code:
  • A programmer spends about 10-20% of his time writing code, and most programmers write about 10-12 lines of code per day that goes into the final product, regardless of their skill level. Good programmers spend much of the other 90% thinking, researching, and experimenting to find the best design. Bad programmers spend much of that 90% debugging code by randomly making changes and seeing if they work.
    “A great lathe operator commands several times the wage of an average lathe operator, but a great writer of software code is worth 10,000 times the price of an average software writer.” –Bill Gates
  • A good programmer is ten times more productive than an average programmer. A great programmer is 20-100 times more productive than the average. This is not an exaggeration– studies since the 1960′s have consistently shown this. A bad programmer is not just unproductive – he will not only not get any work done, but create a lot of work and headaches for others to fix.
  • Great programmers spend little of their time writing code – at least code that ends up in the final product. Programmers who spend much of their time writing code are too lazy, too ignorant, or too arrogant to find existing solutions to old problems. Great programmers are masters at recognizing and reusing common patterns. Good programmers are not afraid to refactor (rewrite) their code constantly to reach the ideal design. Bad programmers write code which lacks conceptual integrity, non-redundancy, hierarchy, and patterns, and so is very difficult to refactor. It’s easier to throw away bad code and start over than to change it.
  • Software obeys the laws of entropy, like everything else. Continuous change leads to software rot, which erodes the conceptual integrity of the original design. Software rot is unavoidable, but programmers who fail to take conceptual integrity into consideration create software that rots so so fast that it becomes worthless before it is even completed. Entropic failure of conceptual integrity is probably the most common reason for software project failure. (The second most common reason is delivering something other than what the customer wanted.) Software rot slows down progress exponentially, so many projects face exploding timelines and budgets before they are killed.
  • 2004 study found that most software projects (51%) will fail in a critical aspect, and 15% will fail totally. This is an improvement since 1994, when 31% failed.
  • Although most software is made by teams, it is not a democratic activity. Usually, just one person is responsible for the design, and the rest of the team fills in the details.
  • Programming is hard work. It’s an intense mental activity. Good programmers think about their work 24/7. They write their most important code in the shower and in their dreams. Because the most important work is done away from a keyboard, software projects cannot be accelerated by spending more time in the office or adding more people to a project.

Saturday, June 25, 2011

Top 10 Things Ten Years of Professional Software Development Has Taught Me

http://www.taylor.se/blog/2007/03/22/top-ten-things-ten-years-of-professional-software-development-has-taught-me/

I was reading this top ten list yesterday, and I thought I can problably come up with my own list of things no-one told me before I started developing software for money. This is my list.
  1. Object orientation is much harder than you thinkMaybe it's just me, but coming from Computer Science class I thought that OO was easy. I mean, how hard can it be to create classes that mimic the real world? It turns out that it's pretty hard. Ten years later, I'm still learning how to model properly. I wish I spent more time reading up on OO and design patterns. Good modeling skills are worth a lot to every development team.
  2. The difficult part of software development is communicationAnd that's communication with persons, not socket programming. Now and then you do run into a tricky technical problem, but it's not at all that common. Much more common is misunderstandings between you and the project manager, between you and the customer and finally between you and the other developers. Work on your soft skills.
  3. Learn to say noWhen I started working, I was very eager to please. This meant that I had a hard time saying no to things people asked of me. I worked a lot of overtime, and still didn't finish everything that was asked of me. The result was disappointment from their side, and almost burning out on my part. If you never say no, your yes is worth very little. Commit to what you can handle, and if people keep asking you for more, make it very explicit that this would mean not doing something else. What I did was to have a list of stuff that I needed to do on a piece of paper with me. When someone asked for something, I showed them the list and asked what I should bump to have time to help them. This allowed me to say no in a nice way.
  4. If everything is equally important, then nothing is importantThe business likes to say that all the features are as crucial. They are not. Push back and make them commit. It's easier if you don't force them to pick what to do and what not to do. Instead, let them choose what you should do this week. This will let you produce the stuff that brings value first. If all else goes haywire, at least you've done that.
  5. Don’t over-think a problemI can spend whole days designing things in front of the white board. That doesn't mean it will be any better, it just means it will be more complicated. I don't mean to say you shouldn't design at all, just that the implementation will quickly show me stuff I didn't think of anyway, so why try to make it perfect? Like Dave Farell says: “The devil is in the details, but exorcism is in implementation, not theory.”
  6. Dive really deep into something, but don't get hung upChris and I spent a lot of time getting into the real deep parts of SQL Server. It was great fun and I learned a lot from it, but after some time I realized that knowing that much didn't really help me solve the business' problems. An example: I know that at the table level, SQL Server will not take an IU lock – it will only take a IX lock. This is a performance tweak, since most of the time, the IU lock will have to be escalated into a IX lock anyway. To find this, I spent countless days experimenting, I read loads of material and talked to Microsoft people at conferences. Have I ever had any use of this knowledge. Nope.
  7. Learn about the other parts of the software development machineIt's really important to be a great developer. But to be a great part of the system that produces software, you need to understand what the rest of the system does. How do the QA people work? What does the project manager do? What drives the business analyst? This knowledge will help you connect with the rest of the people, and will grease interactions with them. Ask the people around you for help in learning more. What books are good? Most people will be flattered that you care, and willingly help you out. A little time on this goes a really long way.
  8. Your colleagues are your best teachersA year after I started on my first job, we merged with another company. Suddenly I had a lot of much more talented and experienced people around me. I remember distinctly how this made me feel inferior and stupid. I studied hard, reading book after book but I still didn't catch up. They had too much of an advantage on me, I figured.
    Nowadays, working with great people doesn't make me feel bad at all. I just feel I have the chance of a lifetime to learn. I ask questions and I try really hard to understand how my colleagues come to the conclusions they do. This is why I joined ThoughtWorks. See your peers as an asset, not competition.
  9. It all comes down to working softwareNo matter how cool your algorithms are, no matter how brilliant your database schema is, no matter how fabulous your whatever is, if it doesn't scratch the clients' itch, it's not worth anything. Focus on delivering working software, and at the same time prepare to continue delivering software using that code base and you're on the right path.
  10. Some people are assholesMost of the time, most of the people around you are great. You learn from them, and they learn from you. Accomplishing something together is a good feeling. Unfortunately, you will probably run into the exceptions. People that because of something or other are plain old mean. Demeaning bosses. Lying colleagues. Stupid, ignorant customers. Don't take this too hard. Try to work around them and do what you can to minimize the pain and effort they cause, but don't blame yourself. As long as you stay honest and do your best, you've done your part.

Friday, June 24, 2011

If a programming language was a boat

http://mendel.soup.io/post/138357929/If-a-programming-language-was-a-boat



Java

Java is a cargo ship. It’s very bulky. It’s very enterprise~y. Though it can also carry a lot of weight. Will carry a project, but not very fun to drive.
Java programming language as a cargo ship
Original photo by cfarivar


PHP

PHP is a bamboo raft. A series of hacks held together by string. Still keeps afloat though.
PHP programming language as a raft
Original photo by permanently scatterbrained


C

C is a nuclear submarine. The instructions are probably in a foreign language, but all of the hardware itself is optimized for performance.
C programming language as a nuclear submarine
Original photo by Ryan C. McGinley


HTML

HTML isn’t really a
programming language
boat.
HTML is not a boat
Original photo by ascendeddaniel


Uploading Excel Data to the Bing Spatial Data Services

http://www.bing.com/community/site_blogs/b/maps/archive/2011/06/21/dev-tip-of-the-week-uploading-excel-data-to-the-bing-spatial-data-services.aspx

Thursday, June 23, 2011

How to add an event into user control in ASP.NET WebForms?


Reason: Put two user controls in same page, you want call one function in B while one thing happens in A.

Three steps to do that: Define, Raise and Book event. 

Define event in A:
    public delegate void AfterOneTask ();
    public event AfterOneTask AfterOneTaskHandler;

Raise event in A:
    protected void Submit_Click(object sender, EventArgs e)
    {
       ….
        if (this. AfterOneTaskHandler!= null) AfterOneTaskHandler();
       }
Book event in B:
    protected void Page_Init(object sender, EventArgs e)
    {
        this.ctlA.AfterOneTaskHandler +=new UserControlA.AfterOneTask(controlb.method1);
    }

What is 8-second rule

 A June 2001 Zona Research report entitled "The Need for Speed II" found that the average web user will wait about eight seconds for a page to download, but that current average download time across backbone connection on most web sites is almost ten seconds.[4]
The 8-second rule is an old (by Internet standards) way of measuring the adequate response time of a webserver through different bandwidth connections. It specified that if the load-time of a web page exceeds eight seconds, users are unlikely to wait, or "stick around", for its completion. In order to increase the "stickiness" of a website, faster ways to deliver the content to the user needed to be devised. These included stripping away unnecessary HTML code and using fewer images.[5]
It is generally believed that this rule no longer applies, since a much higher percentage of Internet users now have broadband available, making almost every website load up much faster, in some cases in less than a second. However, the rule has remained as a rough unit to measure the performance of a webserver.

http://en.wikipedia.org/wiki/Network_performance#8-second_rule

Tuesday, June 21, 2011

How to solve the problem that jQuery doesn’t work with UpdatePanel?


jQuery live method

How to set row index to CommandArgument in the templatefield of Gridview


CommandArgument="<%# Container.DataItemIndex %>"




        <asp:TemplateField >
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" Text="Remove" CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>

Maslow's Hierarchy of Needs


How to disagree

http://www.paulgraham.com/disagree.html

Custom paging by Entity Framework

http://geekswithblogs.net/Frez/articles/using-the-entity-framework-and-the-objectdatasource-custom-paging.aspx

Saturday, June 18, 2011

Facebook like button

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Frayaspnet.blogspot.com%2F"
        scrolling="no" frameborder="0"
        style="border:none; width:350px; height:20px"><iframe></iframe></iframe>

Friday, June 17, 2011

ASP.NET Universal Providers


Today the Web Platform and Tools team (WPT) is releasing an Alpha of the ASP.NET Universal Providers that will extend Session, Membership, Roles and Profile support to SQL Compact Edition and SQL Azure. Other than supporting additional storage options, the providers work like the existing SQL-based providers

http://www.hanselman.com/blog/IntroducingSystemWebProvidersASPNETUniversalProvidersForSessionMembershipRolesAndUserProfileOnSQLCompactAndSQLAzure.aspx

Resign Patterns

Resign Patterns Ailments of Unsuitable Project-Disoriented Software

http://www.lsd.ic.unicamp.br/~oliva/fun/prog/resign-patterns

Thursday, June 16, 2011

Advance Shapes in Bing Maps V7

http://rbrundritt.wordpress.com/2011/06/10/advance-shapes-in-bing-maps-v7/

Demo for W3C Geolocation

http://ie.microsoft.com/testdrive/HTML5/Geolocation/Default.html

HTML5 Support for the Visual Studio 2010 Editor

Folks have been asking "When will VS2010 support HTML5?" I've been saying, jokingly, that the answer is "yesterday" as there's nothing keeping you from creating HTML5 in Visual Studio or ASP.NET today. However, there's no intellisense and there's lots of squiggly lines that make people uncomfortable. Combine all that with the fact that HTML5 is a moving target, and it's unclear. We've said before that the next version of Visual Studio will have better support HTML5, but what about today?

HTML5 Support for the Visual Studio 2010 Editor

Wednesday, June 15, 2011

How to use ASP.NET Expression to set property in server control?


ASP.NET expressions are a declarative way set control properties based on information that is evaluated at run time.
<asp:Label id="label1" runat="server" text="<%$ Resources: Messages, ThankYouLabel %>" />
<asp:Literal runat="server" text="<%$ AppSettings: copyright %>"/>




ASP.NET Expression Builders

http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx



[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder {
    public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, 
       object parsedData, ExpressionBuilderContext context) {
        return new CodeSnippetExpression(entry.Expression);
    }
}
<compilation debug="true">
  <expressionBuilders>
    <add expressionPrefix="Code" type="Infinity.Web.Compilation.CodeExpressionBuilder"/>
  </expressionBuilders>
</compilation>
And to see it in action:
<asp:CheckBox id="chk1" runat="server" Text="<%$ Code: DateTime.Now %>" />

LINQ Cheat Sheet

Microsoft patches 34 vulnerabilities


http://www.net-security.org/secworld.php?id=11168

Tuesday, June 14, 2011

How to get current login user name in ASP.NET


Page.User.Identity.Name

Why Microsoft has made developers horrified about coding for Windows 8


Windows developers have invested a lot of time, effort, and money into the platform. Over the years, they've learned Win32, COM, MFC, ATL, Visual Basic 6, .NET, WinForms, Silverlight, WPF. All of these technologies were, at one time or another, instrumental in creating desktop applications on Windows. With the exception of Visual Basic 6, all of them are still more or less supported on Windows today, and none of them can do it all; all except Visual Basic 6 and WinForms have a role to play in modern Windows development.
Hearing that Windows 8 would use HTML5 and JavaScript for its new immersive applications was, therefore, more than a little disturbing to Windows developers

Twitter API in ASP.NET, Topsy Otter

http://www.eggheadcafe.com/tutorials/aspnet/244cefbb-a3d2-4e3c-b8b6-fb3c12c0d5fa/aspnet-twitter-link-tracker-for-friend-posts-via-twitter-and-ottter-apis.aspx

Sunday, June 12, 2011

CSS framework

http://www.javaeye.com/news/20054

Saturday, June 11, 2011

Three Spirits in The Soul of a Software Developer

Great Artist

If you hear a voice within you say, ‘You cannot paint,’ then by all means paint, and that voice will be silenced. – Vincent van Gogh
The first spirit is a Great Artist who pushes our fellow programmer to work on challenging tasks, invent new approaches and seek for self realization. The spirit gives power and desire to create state of art solutions and move forward with learning and practice. The Great Artistspirit is behind the best software; it makes the developer to think out of box, strive for beautiful code and forget everything outside the problem. It is powerful spirit but dangerous for ordinary business – there is no predictability and assurance that developer will remember what client really needs. The developer driven by this spirit tend to reject mediocre, but good enough solutions, will do stuff his own way and go far beyond what is necessary. This developer has zero tolerance to poor code and will refactor most important pieces of code even night before important demo… after testers go home to sleep.

Reliable Worker

No man is an island, entire of itself; every man is a piece of the continent. – John Donne
The second spirit is a Reliable Worker who puts interests of the team, company and client on the first place. The developer driven by this spirit completely dedicates himself to success of the project and Greater Good. The Reliable Worker spirit  suppresses creativity and code that is not sanctioned by management and could fail. The developer will stay late to meet deadlines and fix embarrassing bugs; he will test after testers and verify installation after administrators.This altruistic spirit makes a developer focused, accountable and disciplined citizen of the company, but sometimes cause stress, uneasiness and feeling of wasted talent.  The danger is that  Reliable Worker spirit can evaporate fast if a company don’t care about developer’s hard work and sacrifices.

Selfish Pragmatist

Life is what happens to you while you’re busy making other plans. – John Lennon

Thursday, June 9, 2011

Problem to uncheck list of checkboxes by jQuery


You cannot go this way:
$(':checkbox').attr('Checked', false);

Have to go by
            $(':checkbox').each(function () {
                this.checked = false;
            });


No problem to check all of checkboxes by:
$(':checkbox').attr('Checked', true);

Interesting…

Documentation helps you in the bedroom

http://zachholman.com/posts/documentation/

NPOI, a open source project for read/write xls, doc, ppt files

http://npoi.codeplex.com/

http://dotnetslackers.com/articles/aspnet/Create-Excel-Spreadsheets-Using-NPOI.aspx

Wednesday, June 8, 2011

How do I turn on off a checkbox with JQuery or Javascript?

For specific checkbox:
check:
$("form #mycheckbox").attr('checked', true);
uncheck:
$("form #mycheckbox").attr('checked', false);

How to solve “The ObjectContext instance has been disposed and can no longer be used for operations that require a connection”

Convert your LINQ query result into array or iList:



                return query.ToList();
Or

                return query.ToArray();


           

How to detect iframe src / URL change event by javascript?

By onload event in iframe:

<iframe src="http://www.google.com/" onLoad="alert('Test');"></iframe>
<iframe src="/test.html" onLoad="alert(this.contentWindow.location);"></iframe>

aspx2razor, a tool to convert WebForm to Razor

aspx2razor.exe c:\MyProject\MyViews\*.cshtml MyOutputDirectory -r


http://blogs.telerik.com/blogs/posts/11-01-19/webforms_to_razor_view_converter_tool.aspx

http://weblogs.asp.net/pglavich/archive/2011/06/06/converting-from-webforms-view-engine-to-razor-some-tips.aspx

Monday, June 6, 2011

What is overflow in CSS?


The CSS property Overflow can be used when displaying content. It regulates the scrollbars.

You can use 4 variables in the element overflow, namely auto, hidden, scroll and visible.
Auto will automatically add a scrollbar when needed.
Hidden will not show a scrollbar, but ‘hide’ the content that usually expand the box.
Scroll will always add a scrollbar.
The value visible will not expand the div, but will just display all the content without changing the div’s height

How to disable scrolling bars for iframe?


How to disable scrolling bars for iframe?


    <div style="overflow:hidden;" >
            <iframe></iframe>
    </div>

Demo for EF 4.1 Code First in ASP.NET MVC 3

EFMVC – A demo web app using ASP.NET MVC 3 and EF 4.1 Code First - Shiju Varghese's Blog

Dependency Injection With ASP.NET HttpModules

Dependency Injection With ASP.NET HttpModules

Saturday, June 4, 2011

What is the difference between Page_init and Page_Load event?

Page_init
 This event is the first event to occur when an ASP.net page is executed,
 this is the event where you should be performing any initialization steps
 that you need to setup or create instances of server controls.
 Its generally advised not to access controls in this event as there is no
 guarantee of the controls been created at this stage, its in this event the
 controls are actually created.
 This event fires only the first time the page is loaded and from the next
 time on a postback Page_init is not fired.

Page_load
 This is the event where most of our work will be done, this event occurs
 when all objects/controls on the page are created and will be available for
 use.

Unlike Page_init, this event is loaded everytime when the page is postback.

Thursday, June 2, 2011

Wednesday, June 1, 2011

What is NEWSEQUENTIALID()

Get better performance than normal GUID for indexing


http://msdn.microsoft.com/en-us/library/ms189786.aspx

Code Indentation and Nesting

Code Indentation and Nesting - Speed of Light

The greatest benefit of this style is bailing early. Instead of deeply nesting your code (and thus heavily indenting it), you have simple statements designed to end execution in as few instructions as possible, and designed to be as simple to follow as possible. Consider the examples:


        - (void)doSomethingWithString:(NSString *)s {
            if (nil != s) {
                if ([s length] > 0) {
                    NSLog(@"%@", s);
                }
            }
        }
        
        // VS
        - (void)doSomethingWithString:(NSString *)s {
            if (nil == s)
                return;
        
            if (![s length])
                return;
        
            NSLog(@"%@", s);
        }