Monthly Archives: January 2013

Deploy an MVC application without precompiling

Microsoft encourages you to develop MVC applications and deploy them in their compiled state, perhaps just as bin files and cshtml.  In some circumstances, though, there might be reasons to deploy an application with just source code.  Why might you do that?  One important reason is that it is frequently important to know exactly what code is in production.  The best way to accomplish this is through a strongly disciplined source code control practices, but in some organizations that may not be realistic.

I have successfully modifed a template MVC 4 application so that only the uncompiled source code can be deployed.

Download here

Development of individual investors

Development

Based on my observations, when people start to invest in stocks, they go through distinct phases.

  • Phase 1 The Arrogant Speculator – the investor sees that some stocks are going up in price (these stocks have been tech start-ups, gold, small cap miners, but could be anything in the future) and they feel like they know more than the old fuddy duddys (everyone else).  There is undoubtedly good reason to be optimistic about a few of these stocks but they are not  worth the enormous price that must be paid for them.  They buy and watch their stocks go up and bask in feelings of their own wisdom.  Soon there is a crash in what they were buying (it doesn’t have to be a wipe out) and they realize that they weren’t so smart after all and sell at a loss or perhaps with a small amount of gains left.
  • Phase 2 The Risky Dividend Investor – once they have completed their speculative phase, they hear that dividends are important.  They think if small amounts of dividends are good, large dividends must be better.  They see the upside in not worrying about the price of the stock.  They look at mortgage REITs, Business Development Corporations and other companies that have very high yields.  Soon, though, they find out that the share price is falling and that the company is in trouble and won’t be able to sustain the dividend.  Once again they find themselves in an unfortunate position.
  • Phase 3 The Mature Investor – After having experienced phases 1 and 2, many investors give up on individual stock picking and invest only in mutual funds or indexes.  They may also look for modest dividend from stable companies in places that they feel will be good in the long run.  They look for low prices on fair companies.
  • Phase 4 The Buffett – This phase is still hypothetical to me because I haven’t quite reached it yet.  I believe it is when you take dividends and company position into account but you look for great companies that are worth a premium and pay only a decent price for them, not a bargain basement price.

Data Extractor

In have been working with ASP.NET MVC lately.  As part of this, I’ve been moving to pure JavaScript pages without viewstate.

Timesheet

Take, for example this very simple timesheet.  The user can add and delete rows without saving to the database or even going back and forth with the web server.  One option is to cleverly name all the text fields so that they can be properly associated with database records.  In other cases, you might want to save the contents of div’s, span’s or even attributes of HTMLelements.  One way to handle this is to keep cleverly named hidden fields in sync with the contents of those HTMLelements.

Here is a jQuery plugin that allows you to convert an HTML element and selected sub-elements, and their properties and attributes into XML which you can then post to the server in a hidden field.  Simply add “decorator” attributes to the elements from which you want to get data:

  • data-extract-method – calls the named jQuery method on the element to get the element value
  • data-extract-name – the name of the XML element to create
  • data-extract-property – gets the value of the named property of the element
  • data-extract attribute – gets the value of the named attribute

For example, this HTML

<html>
    <head>
        <title>Test</title>
        <script src="/lib/jqueryUI/jquery-ui-1.9.0/js/jquery-1.8.2.js" type="text/javascript"></script>
        <script src="~/Scripts/extractState.js"></script>
    </head>
    <body>
        <div id="main" data-extract-name="root">
            <p data-extract-name="item">
                <input type="text" data-extract-name="name" data-extract-method="val" value="Bob" />
                <input type="checkbox" data-extract-name="chk" data-extract-property="checked" />
                <span data-extract-name="age"  data-extract-attribute="class">50</span>
            </p>
            <p data-extract-name="item">
                <input type="text" data-extract-name="name" data-extract-method="val" value="Alice" />
                <input type="checkbox" data-extract-name="chk" data-extract-property="checked" />
                <span data-extract-name="age"  data-extract-attribute="class">25</span>
            </p>
        </div>
        <textarea id="xx"></textarea>
        <script>
            $("#xx").on("click", function () {
                var m = $("#main");
                var v = $.extractState(m);
                $(this).val("<" + v[0].nodeName + ">" + v.html() + "</" + v[0].nodeName + ">")
            });
        </script>
    </body>
</html>

will return this result in the textarea:

<root>
  <item>
    <name>
      <val>Bob</val>
    </name>
    <chk>
      <checked>
      </checked>
    </chk>
    <age>
      <class>gray</class>
    </age>
  </item>
  <item>
    <name>
      <val>Alice</val>
    </name>
    <chk>
      <checked>
      </checked>
    </chk>
    <age>
      <class>black</class>
    </age>
  </item>
</root>
<!--A few words of caution: be very careful of your xml output names.  Don't call an element xml or use hyphens or it won't work in IE.-->