Thursday, October 30, 2014

HttpContext.Current.Response.Write("Hello World!");

...is gonna allow you to write your own HTML to the browser replacing everything that was there before!

Where is American Express SafeKey?

  1. United Kingdom
  2. India
  3. Singapore
  4. Switzerland
  5. Russia
  6. Turkey
  7. Malaysia
  8. France
  9. Spain
  10. Italy
  11. Germany
  12. Netherlands
  13. Japan
  14. Hong Kong
  15. Australia
  16. Cyprus
  17. China
  18. Greece
  19. Vietnam

A stringified integer is typically handed into a credit card processor for a representation of a payment amount.

The currency amount for US dollars will typically get changed from a number with two decimal places to an integer for the total number of pennies. The total number of pennies will then be handed in as a string.

Get the absolute value of an integer in C#.

This suggests doing something like this:

int foo = -13;
int bar = Math.Abs(foo);

a better posting on currency codes

http://www.forexrealm.com/additional-info/currencies-codes-a-b.html seems to have a much better cheat sheet on currency codes than what I gave here. I pulled the following from there:

 Afghanistan  Afghani  AFA  4 
 Albania  Lek  ALL  8 
 Algeria  Algerian Dinar  DZD  12 
 American Samoa  US Dollar  USD  840 
 Andorra  Euro  EUR  978 
 Angola  New Kwanza  AON  24 
 Anguilla  East Caribbean Dollar  XCD  951 
 Antarctica  No universal currency     
 Antigua and Barbuda  East Caribbean Dollar  XCD  951 
 Argentina  Argentine Peso  ARS  32 
 Armenia  Armenian Dram  AMD  51 
 Aruba  Aruban Guilder  AWG  533 
 Australia  Australian Dollar  AUD  36 
 Austria  Euro  EUR  978 
 Azerbaijan  Azerbaijanian Manat  AZM  31 
 Bahamas  Bahamian Dollar  BSD  44 
 Bahrain  Bahraini Dinar  BHD  48 
 Bangladesh  Taka  BDT  50 
 Barbados  Barbados Dollar  BBD  52 
 Belarus  Belarussian Ruble  BYR  974 
 Belgium  Euro  EUR  978 
 Belize  Belize Dollar  BZD  84 
 Benin  CFA Franc BCEAO  XOF  952 
 Bermuda  Bermudian Dollar  BMD  60 
 Bhutan  Ngultrum  BTN  64 
 Bhutan (other)  Indian Rupee  INR  356 
 Bosnia and Herzegovina  Convertible Marks  BAM  977 
 Botswana  Pula  BWP  72 
 Bouvet Island  Norwegian Krone  NOK  578 
 Brazil  Brazilian Real  BRL  986 
 British Indian Ocean Territory  Pound Sterling  GBP  826 
 British Indian Ocean Territory (other)  US Dollar  USD  840 
 Brunei Darussalam  Brunei Dollar  BND  96 
 Bulgaria  Lev  BGL  100 
 Burkina Faso  CFA Franc BCEAO  XOF  952 
 Burundi  Burundi Franc  BIF  108 
 Cambodia  Riel  KHR  116 
 Cameroon  CFA Franc BEAC  XAF  950 
 Canada  Canadian Dollar  CAD  124 
 Cape Verde  Cape Verde Escudo  CVE  132 
 Cayman Islands  Cayman Islands Dollar  KYD  136 
 Central African Republic  CFA Franc BEAC  XAF  950 
 Chad  CFA Franc BEAC  XAF  950 
 Chile  Chilean Peso  CLP  152 
 China  Yuan Renminbi  CNY  156 
 Christmas Island  Australian Dollar  AUD  36 
 Cocos (Keeling) Islands  Australian Dollar  AUD  36 
 Colombia  Colombian Peso  COP  170 
 Comoros  Comoro Franc  KMF  174 
 Congo  CFA Franc BEAC  XAF  950 
 Congo, The Democratic Republic Of  Franc Congolais  CDF  976 
 Cook Islands  New Zealand Dollar  NZD  554 
 Costa Rica  Costa Rican Colon  CRC  188 
 Cote D'ivoire  CFA Franc BCEAO  XOF  952 
 Croatia  Kuna  HRK  191 
 Cuba  Cuban Peso  CUP  192 
 Cyprus  Cyprus Pound  CYP  196 
 Cyprus - TRNC  Turkish Lira  TRL  792 
 Czech Republic  Czech Koruna  CZK  203 
 Denmark  Danish Krone  DKK  208 
 Djibouti  Djibouti Franc  DJF  262 
 Dominica  East Caribbean Dollar  XCD  951 
 Dominican Republic  Dominican Peso  DOP  214 
 East Timor  US Dollar  USD  840 
 Ecuador  US Dollar  USD  840 
 Egypt  Egyptian Pound  EGP  818 
 El Salvador  El Salvador Colon  SVC  222 
 Equatorial Guinea  CFA Franc BEAC  XAF  950 
 Estonia  Kroon  EEK  233 
 Eritrea  Nakfa  ERN  232 
 Ethiopia  Ethiopian Birr  ETB  230 
 European Union  Euro  EUR  978 
 Faeroe Islands  Danish Krone  DKK  208 
 Falkland Islands (Malvinas)  Pound  FKP  238 
 Fiji  Fiji Dollar  FJD  242 
 Finland  Euro  EUR  978 
 France  Euro  EUR  978 
 French Guiana  Euro  EUR  978 
 French Polynesia  CFP Franc  XPF  953 
 French Southern Territories  Euro  EUR  978 
 Gabon  CFA Franc BEAC  XAF  950 
 Gambia  Dalasi  GMD  270 
 Georgia  Lari  GEL  981 
 Germany  Euro  EUR  978 
 Ghana  Cedi  GHC  288 
 Gibraltar  Gibraltar Pound  GIP  292 
 Greece  Euro  EUR  978 
 Greenland  Danish Krone  DKK  208 
 Grenada  East Caribbean Dollar  XCD  951 
 Guadeloupe  Euro  EUR  978 
 Guam  US Dollar  USD  840 
 Guatemala  Quetzal  GTQ  320 
 Guinea  Guinea Franc  GNF  324 
 Guinea-Bissau  CFA Franc BCEAO  XOF  952 
 Guyana  Guyana Dollar  GYD  328 
 Haiti  Gourde  HTG  332 
   US Dollar  USD  840 
 Heard and Mcdonald Islands  Australian Dollar  AUD  36 
 Honduras  Lempira  HNL  340 
 Hong Kong  Hong Kong Dollar  HKD  344 
 Hungary  Forint  HUF  348 
 Iceland  Iceland Krona  ISK  352 
 India  Indian Rupee  INR  356 
 Indonesia  Rupiah  IDR  360 
 International Monetary Fund (Imf)  SDR  XDR  960 
 Iran (Islamic Republic Of)  Iranian Rial  IRR  364 
 Iraq  Iraqi Dinar  IQD  368 
 Ireland  Euro  EUR  978 
 Israel  New Israeli Sheqel  ILS  376 
 Italy  Euro  EUR  978 
 Jamaica  Jamaican Dollar  JMD  388 
 Japan  Yen  JPY  392 
 Jersey  Pound Sterling  GBP  826 
 Jordan  Jordanian Dinar  JOD  400 
 Kazakhstan  Tenge  KZT  398 
 Kenya  Kenyan Shilling  KES  404 
 Kiribati  Australian Dollar  AUD  36 
 Korea, Democratic People's Republic Of  North Korean Won  KPW  408 
 Korea, Republic Of  Won  KRW  410 
 Kuwait  Kuwaiti Dinar  KWD  414 
 Kyrgyzstan  Som  KGS  417 
 Lao People's Democratic Republic   Kip  LAK  418 
 Latvia  Latvian Lats  LVL  428 
 Lebanon  Lebanese Pound  LBP  422 
 Lesotho  Loti  LSL  426 
 Lesotho (other)  Rand  ZAR  710 
 Liberia  Liberian Dollar  LRD  430 
 Libyan Arab Jamahiriya  Libyan Dinar  LYD  434 
 Liechtenstein  Swiss Franc  CHF  756 
 Lithuania  Lithuanian Litas  LTL  440 
 Luxembourg  Euro  EUR  978 
 Macau  Pataca  MOP  446 
 Macedonia, The Former Yugoslav Republic Of  Denar  MKD  807 
 Madagascar  Malagasy Franc  MGF  450 
 Malawi  Kwacha  MWK  454 
 Malaysia  Malaysian Ringgit  MYR  458 
 Maldives  Rufiyaa  MVR  462 
 Mali  CFA Franc BCEAO  XOF  952 
 Malta  Maltese Lira  MTL  470 
 Marshall Islands  US Dollar  USD  840 
 Martinique  Euro  EUR  978 
 Mauritania  Ouguiya  MRO  478 
 Mauritius  Mauritius Rupee  MUR  480 
 Mexico  Mexican Peso  MXN  484 
 Micronesia  US Dollar  USD  840 
 Moldova, Republic Of  Moldovan Leu  MDL  498 
 Monaco  Euro  EUR  978 
 Mongolia  Tugrik  MNT  496 
 Montserrat  East Caribbean Dollar  XCD  951 
 Morocco  Moroccan Dirham  MAD  504 
 Mozambique  Metical  MZM  508 
 Myanmar  Kyat  MMK  104 
 Namibia  Namibia Dollar  NAD  516 
 Namibia (other)  Rand  ZAR  710 
 Nauru  Australian Dollar  AUD  36 
 Nepal  Nepalese Rupee  NPR  524 
 Netherlands  Euro  EUR  978 
 Netherlands Antilles  Antillian Guilder  ANG  532 
 New Caledonia  CFP Franc  XPF  953 
 New Zealand  New Zealand Dollar  NZD  554 
 Nicaragua  Cordoba Oro  NIO  558 
 Niger  CFA Franc BCEAO  XOF  952 
 Nigeria  Naira  NGN  566 
 Niue  New Zealand Dollar  NZD  554 
 Norfolk Island  Australian Dollar  AUD  36 
 Northern Mariana Islands  US Dollar  USD  840 
 Norway  Norwegian Krone  NOK  578 
 Oman  Rial Omani  OMR  512 
 Pakistan  Pakistan Rupee  PKR  586 
 Palau  US Dollar  USD  840 
 Panama  Balboa  PAB  590 
 Panama (other)  US Dollar  USD  840 
 Papua New Guinea  Kina  PGK  598 
 Paraguay  Guarani  PYG  600 
 Peru  Nuevo Sol  PEN  604 
 Philippines  Philippine Peso  PHP  608 
 Pitcairn  New Zealand Dollar  NZD  554 
 Poland  Zloty  PLN  985 
 Portugal  Euro  EUR  978 
 Puerto Rico  US Dollar  USD  840 
 Qatar  Qatari Rial  QAR  634 
 Reunion  Euro  EUR  978 
 Romania  Leu  RON  946 
 Russian Federation  Russian Ruble  RUB  810 
 Rwanda  Rwanda Franc  RWF  646 
 St Helena  St Helena Pound  SHP  654 
 St Kitts - Nevis  East Caribbean Dollar  XCD  951 
 Saint Lucia  East Caribbean Dollar  XCD  951 
 St Pierre and Miquelon  Euro  EUR  978 
 Saint Vincent and The Grenadines  East Caribbean Dollar  XCD  951 
 Samoa  Tala  WST  882 
 San Marino  Euro  EUR  978 
 Sao Tome and Principe  Dobra  STD  678 
 Saudi Arabia  Saudi Riyal  SAR  682 
 Senegal  CFA Franc BCEAO  XOF  952 
 Serbia and Montenegro  New Dinar  YUM  891 
 Serbia and Montenegro (other)  Euro (in Montenegro)  EUR  978 
 Seychelles  Seychelles Rupee  SCR  690 
 Sierra Leone  Leone  SLL  694 
 Singapore  Singapore Dollar  SGD  702 
 Slovakia  Slovak Koruna  SKK  703 
 Slovenia  Tolar  SIT  705 
 Solomon Islands  Solomon Islands Dollar  SBD  90 
 Somalia  Somali Shilling  SOS  706 
 South Africa  Rand  ZAR  710 
 Spain  Euro  EUR  978 
 Sri Lanka  Sri Lanka Rupee  LKR  144 
 Sudan  Sudanese Dinar  SDD  736 
 Suriname  Surinam Guilder  SRG  740 
 Svalbard and Jan Mayen Islands  Norwegian Krone  NOK  578 
 Swaziland  Lilangeni  SZL  748 
 Sweden  Swedish Krona  SEK  752 
 Switzerland  Swiss Franc  CHF  756 
 Syrian Arab Republic  Syrian Pound  SYP  760 
 Taiwan, Province Of China  New Taiwan Dollar  TWD  901 
 Tajikistan  Somoni  TJS  972 
 Tanzania, United Republic Of  Tanzanian Shilling  TZS  834 
 Thailand  Baht  THB  764 
 Togo  CFA Franc BCEAO  XOF  952 
 Tokelau  New Zealand Dollar  NZD  554 
 Tonga  Pa'anga  TOP  776 
 Trinidad and Tobago  Trinidad and Tobago Dollar  TTD  780 
 Tunisia  Tunisian Dinar  TND  788 
 Turkey  Turkish Lira  TRL  792 
 Turkmenistan  Manat  TMM  795 
 Turks and Caicos Islands  US Dollar  USD  840 
 Tuvalu  Australian Dollar  AUD  36 
 Uganda  Uganda Shilling  UGX  800 
 Ukraine  Hryvnia  UAH  980 
 United Arab Emirates  UAE Dirham  AED  784 
 United Kingdom  Pound Sterling  GBP  826 
 United States  US Dollar  USD  840 
   (Same day)  USS  998 
   (Next day)  USN  997 
 United States Minor Outlaying Islands  US Dollar  USD  840 
 Uruguay  Peso Uruguayo  UYU  858 
 Uzbekistan  Uzbekistan Sum  UZS  860 
 Vanuatu  Vatu  VUV  548 
 Vatican City State (Holy See)  Euro  EUR  978 
 Venezuela  Bolivar  VEB  862 
 Vietnam  Dong  VND  704 
 Virgin Islands (British)  US Dollar  USD  840 
 Virgin Islands (U.S.)  US Dollar  USD  840 
 Wallis and Futuna Islands  CFP Franc  XPF  953 
 Western Sahara  Moroccan Dirham  MAD  504 
 Yemen  Yemeni Rial  YER  886 
 Zambia  Kwacha  ZMK  894 
 Zimbabwe  Zimbabwe Dollar  ZWD  716 

The original intent of my old article was to help in specifying a credit card code to hand to a processor, but honestly it is more likely that one of the numeric codes will be handed over and thus the old cheat sheet is kinda bad.

Wednesday, October 29, 2014

getting Ankh to honor the "ignore-on-commit" setting you just made in TortoiseSVN

Close Visual Studio and then open it anew!

There is now an XML 1.1.

Links:

Checking the "Preserve log" checkbox at the upper left of the "Network" tab in Google Chrome Developer Tools will allow one to record a list of HTTP traffic interactions progressively into a list as one browses the web!

It's Fiddleresque!

I'm am "learning" that one may hand an HttpContext into a method signature to empower a Response.Redirect outside of a web form in a standalone class in C#.

myHttpContext.Response.Redirect(url); would then be the way to do the act. However, this may not be the smartest thing. Response.Redirect does not play nicely with ASP.NET MVC and thus abstracting a redirect out of the UI to other code may just not be smart. (What if you change out the UI or let other UIs talk to your class?) These mechanics belong in their UI implemenations.

Tuesday, October 28, 2014

Add and edit users in Windows Server 2012 R2.

  1. From the desktop, click on the Windows Icon at the start menu position of yesteryear in the lower left corner.
  2. Pick "Administrative Tools" which will take you back to the desktop and show you a list of things in a window titled "Administrative Tools."
  3. Double-click on "Computer Management."
  4. The "Users" stuff is under "Local Users and Groups" under "System Tools" under "Computer Management (Local)" in the "Computer Management" window which appears.

Friday, October 24, 2014

"12 Reasons Your API Sucks" was the other talk by Keith Casey I saw at this year's Code Camp.

So, what are the twelve reasons?

  1. Documentation. PDF documentation has maintainability issues. Move documentation out of PDFs to your web site. Don't hide documentation behind an NDA. The documentation needs to be discoverable. If people are googling your error messages and finding Stack Overflow instead of your web site then others are writing your documentation for you.
  2. Helper Documentation. This is not the same as API documentation. Give the best documentation possible at the lowest level possible (i.e. that is, don't shut others out by giving language-specific details.)
  3. "Getting Started" Code. The examples need to be good, short, terse.
  4. Too Much Boilerplate. Don’t have examples 22 lines long.
  5. SOAP as the Interface. SOAP is like a mortgage with a big contract upfront and a multistep process for reacting when things go wrong. REST in contrast is more flexible and hence better though it does introduce ambiguity to iron out.
  6. Illogical Inconsistencies. Getting "201 Created" back from a resource is an example.
  7. Poor Workflow and Modeling. The entire point of an API is to offer affordances, just as the handle on a coffee mug affords the ability to pick a coffee mug up by hand or perhaps hang the coffee mug on a peg. On the other hand it is hard to see what the Twitter and Facebook APIs afford and what they were intended for and this wishy-washiness is a bad sign. Twitter put a lot of companies out of business when it turned off its API and this pain stems from murkiness in definition of goals.
  8. Numerous Approaches. If there are too many ways to approach how to do something and no one way is right, that is and things are confusing.
  9. Authentication. Don't roll your own. Unless you are a cryptography expert you'll do it wrong. Find a plugin or a module in your space.
  10. Your Stuff is Broken. What does your uptime look like? 99% is fine for Dish Networks. For you? Is your API Deterministic? Does it return the same result every time for each input? It really should because if it doesn't it will give the impression that it is broken. At Clarify, where results are based on voice-recognition and hence have a hint of play, data handed back is kept at a database and all queries are looked up against existing records to make sure that back to back requests for the same content do not return varying results enraging the users.
  11. Error Messages Are Bad. 404 is an error and not 200.
  12. Logging and Debugging. Runscope was recommended as a tool to use.

Did you know that you may name a Web API method anything provided that the first few characters correspond to a verb?

public string Getttttttttttttttttt() ...is perfectly legitimate for example. This method could catch Get requests.

more regarding certificates and "mmc"

I would add to this:

  • at the "Certificates snap-in" dialog pick "Computer account"
  • once you have a "Certificates (Local Computer)" heading under "Console Root" right-click on the "Certificates" folder below both "Personal" and "Trusted Root Certification Authorities" to add a certificate to these regions by picking "Import..." from the "All Tasks" menu

Thursday, October 23, 2014

Daisy chain monitors together

...with Multi-Display Adapters

Google+ Hangouts

...seems to be the way to do chat over Google+. In the upper right corner of the interface there is what looks like a cartoon "I'm-speaking" bubble with two quotes in it that is going to open up a menu which hugs the right of the browser.

Send a header within a jQuery .ajax implementation.

If you click the button in this view, it will put "my dog has fleas" into the token div.

<button id="clickhere">click here</button>
<div id="response"></div>
@section scripts
{
   <script language="javascript">
      $('#clickhere').bind("click", function() {
         $.ajax({
            type: "POST",
            url: "/api/values",
            headers: { 'possessions': 'fleas' },
            success: function (result) {
               $("#response").html(result);
            }
         });
      });
   </script>
}

 
 

At the Web API side in C# the way to make sense of the header looks like this:

using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace Stuff.Controllers
{
   public class ValuesController : ApiController
   {
      public string Post()
      {
         IEnumerable<string> headerValues;
         if (Request.Headers.TryGetValues("possessions", out headerValues))
         {
            return "my dog has " + headerValues.First();
         }
         return "my dog has nada";
      }
   }
}

Wednesday, October 22, 2014

a better posting on gradients in CSS

In contrast to this, I find the following much less confusing.

#banner {
   height: 15px;
   background-color: #EE3124;
   background: -webkit-linear-gradient(180deg, #EE3124, #C41230);
   background: -o-linear-gradient(180deg, #EE3124, #C41230);
   background: -moz-linear-gradient(180deg, #EE3124, #C41230);
   background: linear-gradient(180deg, #EE3124, #C41230);
}

 
 

The first parameter in the last four lines of code dictates which direction the gradient runs. In this case it is from top to bottom. Easy. Note also that I set a flat background color for IE7 above the four lines of modern magic.

long running processes

I like the stack overflow definition here: "Long running processes prevent other processes from responding as quickly as intended. Typically a problem in UI programming, long running processes can prevent the UI from responding to user input."

In embracing Hybris...

...SAP is to discontinue support for its existing eCommerce way-of-doing-things which was perhaps called WebCommerce or something comparable. Hybris is the new way to go. IBM's WebSphere is a player in this same space and so it too will be challenged by Hybris.

 
 

Addendum 8/9/2018: WebSphere is a Java server.

Tuesday, October 21, 2014

Decorating list items with both display:block; and float: left;

...seems a pretty good way to allow them to be a fixed width while also sitting in a horizontal row. It works jiffy down to IE7.

An example of changing the contents of a content box out with jQuery while clicking different tabs above.

Below the contents of the actual divs are populated from the C# side upon the Page_Load event of a web form, but you may imagine the divs hold whatever you'd like really. The first of four tabs starts as styled differently as if to say "This tab is selected and current." Comparably, the first of four divs is not hidden while the others are. You can probably guess what the snippetSelection and displaynone classes do, eh?

<ul id="snippetNavigation">
   <li class="snippetSelection">Description</li>
   <li>ASP.NET</li>
   <li>JavaScript</li>
   <li>C#</li>
</ul>
 
<section id="snippets" style="height:440px;">
   <div id="Description" runat="server"></div>
   <div id="Markup" class="displaynone" runat="server"></div>
   <div id="JavaScript" class="displaynone" runat="server"></div>
   <div id="CodeBehind" class="displaynone" runat="server"></div>
</section>
 
<script type="text/javascript" language="javascript">
   $('#snippetNavigation li').bind('click', function () {
      var outerCounter = 0;
      var options = $("#snippetNavigation li");
      while (outerCounter < options.length) {
         var option = options[outerCounter];
         if (options[outerCounter] == this) {
            var innerCounter = 0;
            var snippets = $("#snippets div");
            while (innerCounter < snippets.length) {
               var snippet = snippets[innerCounter];
               if (outerCounter == innerCounter) {
                  console.log(snippet);
                  $(snippet).attr("class", "");
               } else {
                  $(snippet).attr("class", "displaynone");
               }
               innerCounter++;
            }
            $(option).attr("class", "snippetSelection");
         } else {
            $(option).attr("class", "");
         }
         outerCounter++;
      }
   });
</script>

When debugging in Cassini via Visual Studio 2013, stylesheet changes will take effect in Google Chrome immediately without you having to force a refresh at the browser.

How do you JavaScript peeps stand to work in Sublime Text all day long? I don't have empathy at all.

Monday, October 20, 2014

box-shadow is the CSS effect for drop shadows around the edges of a div.

I am using it for the first time today. It looks like this:

box-shadow: 0 0 40px #666666;

 
 

The first two numbers seem to be for offsetting the shadow per this.

Circuit Scribe

I'm seeing this for the first time this morning in something someone shared on Facebook. Cool stuff.

Sunday, October 19, 2014

I discussed refactoring ForEach loops to Lambda expressions via ReSharper with a friend and a stranger at this year's code camp over the lunch.

My friend said that the Lambdas are more "performant" than the ForEach stuff would otherwise be. I did not know this. She also mentioned that you can't use ReSharper to reverse the Lambda stuff back into a ForEach shape which I've found to be true too.

Keith Casey will SPOIL you with a better-than-average tech talk.

Yesterday, I attended the annual Austin Code Camp which the Austin .NET Users Group (ADNUG) puts on. The best talk I saw, which I will write of first, was "SPOIL your users with Great Helper Libraries" by D. Keith Casey, formerly of Twilio, now of Clarify (makes audio and video clips searchable and SEO-friendly by crafting copy from uploaded media with voice recognition software), and author of a technology agnostic book on API design called "A Practical Approach to API Design." API designs themselves should be done with care and be more than just exposing CRUD functionality over an API in one afternoon of coding as APIs may be hard to work with if they are not designed well. The status codes need to make sense (more on that later) ...and so on. Mr. Casey spoke of a scenario in which an API was sketched on a Monday, followed by the JSON going back and forth being sketched on a Tuesday, and then on the Wednesday and Thursday a simulator was built out. That's more like it! Something further to take seriously and not to shortchange are the SDKs which exposition how to use the API you have hopefully built with obsessive compulsive hand washing love. As a guideline for good practices in doing so, Keith has invented his own acronym, SPOIL which stands for:

  • Succinct
  • Purposeful
  • Open Source
  • Idiomatic
  • Logical

 
 

S is for succinct, briefly and clearly expressed, precise but concise. An example should just be a few lines of code. At Clarify, it takes just two lines of code to do anything and three is too many. Users will commonly copy and paste code examples from SDKs and then hammer then into shape in their apps and if an example is twenty-two lines of code long instead of two there is a clearly a greater chance of a misconfiguration. What if the developer fails to see the couple of key spots to alter in a twenty-two line mess? When writing examples try to cover the scenarios which cover eighty percent of use cases instead of ninety-nine. It is important that an example be readable not confusing. P is for purposeful, having or showing resolve. It is usually an afterthought to throw together an API and that's bad. If someone is using your companies' product and they feel rage, then you're doing it wrong. Keith recommends writing all of the documentation first before development. O is for Open Source, universal access and a free license. Don't compile your SDKs into binaries that others cannot change up. The libraries should be free to use and modify. Keith once tweeted a request for links to bad API designs and one of the many responses he got asked him to sign a nondisclosure agreement first. Not cool. Your copyright should never come off your product. You should just simply offer a use agreement in which parties cannot pretend that you endorse them and cannot remove your copyright. Otherwise the public should be allowed to manhandle and mangle your SDKs at will in the name of understanding your API. At the end of the talk I asked a question about the next point, I for Idiomatic, and Keith suggested that amongst the things one might do to get an SDK in a language that is out of the norm and sweet spot for its authors shipshape is to request that the community around that other language you've never written code in give you feedback and critiques. This scared me as it requires being really vulnerable, but as I sit here and type this up I realize that the Python community, for example, (I've never written Python) should be able to critique my Python SDK anyways if I offer one and I really do things the right way and make the SDK open source. The scary, I'm-going-to-let-you-have-a-laugh-at-my-poor-code aspect of being vulnerable in offering SDKs across more languages than you personally truly know is probably just a part of the SDK game that I've got to get used to. I should just remind myself that others doing the same thing are facing the same challenge. I is for Idiomatic. An SDK should not be akin to a language it is not intended for. One should not look at Keith's C# SDK and recoil at how it is PHP-flavored and goofy if considered in a C# context. Swagger will give you JSON representations of your API and APImatic can turn around and generate SDKs from the Swagger objects in seven different languages, but some of what it spits out is just goofy. In circling back to the question I asked, which more or less was "What should I do if I'm the wrong person to write an SDK in a language I don't know?" I was told that it might indeed be wise to bring in outside consultants. When I started to stress over the likelihood of getting budget approved for as much another gentleman in the audience suggested it might be smart to pick a customer who uses the other language and get them to audit what is crafted and offer suggestions and feedback. L is for Logical, clear and sound reasoning, consistent and predictable. To me this last point felt like it had less to do with the SDKs than the API design itself. The status codes that your API gives back should make sense. Beyond that, they shouldn't do silly things like returning 403 Forbidden when attempting to delete something one is not permissioned to delete as this sort of reveals that the thing to be deleted does exist to someone who doesn't need to be told anything about it. 404 Not Found would be better in this circumstance. If you are not being deliberate in your reasoning for what you return and it's not a part of your documentation, you're going to drive your users up the wall. Different coders will do different things in building out an API if there isn't a plan and some standards. Don't let your API become a hodgepodge of madness. Do wireframes and user process diagrams. Write stories. Other things said of interest were:

  • The way authentication works at Clarify is that a bearer-token is given to a user when he/she first creates an account and there is an expectation that such a token will be included whenever the user uses the API every time.
  • I/ODOCS is something akin to Swagger. It is an alternative.
  • Brain Wolfe of Volusion (and also Habanero Software, LLC) was at the table I sat at and he said that Volusion offers a sister endpoint for each of its API endpoints which just gives metadata on the first API endpoint. The metadata is crafted by C# reflection using an in-house tool.

Keep Trovi from opening up in new tabs in Firefox.

There are two steps to this. First, you will want to remove Trovi from your list of search engines. Click the down arrow at the left of the search bar, and then/next pick "Manage Search Engines..." from the base of the menu which appears. This will bring up a dialog box where you may remove Trovi from the list.

Finally, go to "Troubleshooting Information" under the "Help" menu. Then click the button which is labeled "Reset Firefox..." at the upper right of the page which appears.

Friday, October 17, 2014

It seems you may not nest a div with a min-height:100%; style inside of another div with a min-height:100%; style and expect the inner div's style to behave properly.

I really looks like every tag wrapping a div with a min-height:100%; style need to be styled with height:100%; for the effect to behave, all the way out to the HTML tag itself, or else the effect will fall down.

Fireworks Canvas

Fireworks does not have a base layer labeled "Background" like Photoshop. Instead there is a "Canvas" with a flat color or a transparency below all of the layers and you must tweak this outside of the "Layers" pane in the "Properties" pane.

Wednesday, October 15, 2014

If you migrate what was in a web form without a master page into a web form that uses a master page, expect the ids of HTML tags rendered to change up.

If you have Default.aspx in the root of a web forms application standalone and it has a asp:Label inside like so:

<asp:Label runat="server" ID="foo">Test</asp:Label>

 
 

The HTML that will end up at the browser will look like this:

<span id="foo">Test</span>

 
 

Yet, when you recreate Default.aspx as a web form which uses a master page and put the same label in it the HTML might look like this:

<span id="MainContent_foo">Test</span>

 
 

This would come from the asp:Label being nested within an asp:Content tag with a ContentPlaceHolderID of "MainContent." This situation dirties up the ids and is likely to sabotage JavaScript that had been working just fine before you decided you had to get that old page from another era into the master page like all of the newer pages. The way to get the HTML back to this shape...

<span id="foo">Test</span>

 
 

...is to doctor your tags like so:

<asp:Label runat="server" ID="foo" ClientIDMode="Static">Test</asp:Label>

 
 

Make sense?

Get the name of the current page in web forms.

This suggests this:

var x = this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5);
x = x + ".aspx";

 
 

...which seems to work just fine. I have this line(s) of code inside of the Page_Load event on a MasterPage.

Tuesday, October 14, 2014

When you get the latest, how will you know that you're missing a dependency that NuGet should fulfill?

Let's say an error is like so:

Could not load file or assembly 'file:///C:\whatever\ui\bin\System.Net.Http.Formatting.dll' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

 
 

When you look at the reference to System.Net.Http.Formatting in the Solution Explorer does it have a path to a .dll like so:

  • C:\whatever\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll

...with "packages" in the mix? ...as opposed to a path like this for System.Net.Http:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Net.Http.dll

 
 

This should tell you that you need to run a Nuget command to put something in the packages folder such as:

Install-Package Microsoft.AspNet.WebApi.Client

 
 

You likely can find the command by just Googling against the name of the .dll and the word "NuGet" as that is how I found this.

B2G

...stands for Business to Government just as B2B is Business to Business and B2C is Business to Consumer and, yes, B2E is Business to Employee. I learned this today by chance at Wikipedia.

Monday, October 13, 2014

Get the header, footer, section, and article tags working in Internet Explorer 7 and Internet Explorer 8 with Modernizr!

It turns out that the problem I describe here is easy to fix. Go to http://modernizr.com/ and get the production Modernizr 2.8.3 in its default configuration while checking no additional checkboxes and also not unchecking the three checked-by-default checkboxes for...

  1. html5shiv v3.7
  2. Modernizr.load
  3. Add CSS Classes

...either. Next, save off the 8K file and reference it like so:

<script src="modernizr.js"></script>

 
 

That is all there is to it! Here are two interesting links I looked at in figuring this out:

position: static;

...is a good way to turn off absolute positioning or any other positioning effect that may cause you heartache in a cascading effect. This is the default positioning but I am just now learning about it today as there is normally no reason to explicitly use it. I've found a fringe use case for turning off an undesired cascading effect however. Looky:

#foo ul {
   position: absolute;
   margin: 0;
   margin-left: -300px;
   padding: 0;
}
#foo ul li ul {
   position: static;
   margin-left: 25px;
}

Saturday, October 11, 2014

Observer Pattern

Today I've decided to recreate the observer pattern example that I accidentally destroyed here. In it there are four varieties of animals which inherit from a common base class which looks like this:

namespace NuclearWar.Animals
{
   public abstract class Animal
   {
      public virtual bool IsHiding { get; set; }
      public virtual bool IsSickly { get; set; }
      
      public Animal()
      {
         IsHiding = false;
         IsSickly = false;
      }
   }
}

 
 

The four kinds of Animal are:

  1. namespace NuclearWar.Animals
    {
       public class Asp : Animal
       {
          public Asp()
          {
          }
          
          public void AbsorbRadiation()
          {
             IsSickly = true;
          }
       }
    }
     
     
  2. namespace NuclearWar.Animals
    {
       public class Bug : Animal
       {
          public Bug()
          {
             IsHiding = true;
          }
          
          public void AbsorbRadiation()
          {
             IsSickly = true;
             IsHiding = false;
          }
       }
    }
     
     
  3. namespace NuclearWar.Animals
    {
       public class Cat : Animal
       {
          public Cat()
          {
          }
          
          public void AbsorbRadiation()
          {
             IsSickly = true;
             IsHiding = true;
          }
       }
    }
     
     
  4. namespace NuclearWar.Animals
    {
       public class Dog : Animal
       {
          private bool _isRoamingTheCountrysideFoamingAtTheMouth;
          
          public bool IsRoamingTheCountrysideFoamingAtTheMouth
          {
             get
             {
                return _isRoamingTheCountrysideFoamingAtTheMouth;
             }
             set
             {
                _isRoamingTheCountrysideFoamingAtTheMouth = value;
                if (value)
                {
                   IsHiding = false;
                }
             }
          }
          
          public Dog()
          {
             IsRoamingTheCountrysideFoamingAtTheMouth = false;
          }
          
          public void AbsorbRadiation()
          {
             IsSickly = true;
             IsRoamingTheCountrysideFoamingAtTheMouth = true;
          }
       }
    }

 
 

Another type in my application is NuclearBomb. At first ReSharper put Antlr.Runtime.Misc as the namespace directive at the top of this file instead of System in the name of empowering Action and I had to include Antlr3.Runtime as a reference in the test project where the test I am about to show you lives, but then I caught the mistake.

using System;
namespace NuclearWar.Machines
{
   public class NuclearBomb
   {
      public Action Detonate;
   }
}

 
 

In this test, I make bunch of animals and then set off a NuclearBomb to make them all sick. This test passes.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NuclearWar.Animals;
using NuclearWar.Machines;
namespace NuclearWar.Tests.Machines
{
   [TestClass]
   public class NuclearBombTest
   {
      [TestMethod]
      public void Test()
      {
         
//Act 1
         Asp lucifer = new Asp();
         Bug gregor = new Bug();
         Cat felix = new Cat();
         Dog spot = new Dog();
         
         Assert.AreEqual(lucifer.IsHiding, false);
         Assert.AreEqual(lucifer.IsSickly, false);
         
         Assert.AreEqual(gregor.IsHiding, true);
         Assert.AreEqual(gregor.IsSickly, false);
         
         Assert.AreEqual(felix.IsHiding, false);
         Assert.AreEqual(felix.IsSickly, false);
         
         Assert.AreEqual(spot.IsHiding, false);
         Assert.AreEqual(spot.IsSickly, false);
         Assert.AreEqual(spot.IsRoamingTheCountrysideFoamingAtTheMouth, false);
         
         
         
//Act 2
         NuclearBomb littleBoy = new NuclearBomb();
         littleBoy.Detonate = lucifer.AbsorbRadiation;
         littleBoy.Detonate += gregor.AbsorbRadiation;
         littleBoy.Detonate += felix.AbsorbRadiation;
         littleBoy.Detonate += spot.AbsorbRadiation;
         
         Assert.AreEqual(lucifer.IsHiding, false);
         Assert.AreEqual(lucifer.IsSickly, false);
         
         Assert.AreEqual(gregor.IsHiding, true);
         Assert.AreEqual(gregor.IsSickly, false);
         
         Assert.AreEqual(felix.IsHiding, false);
         Assert.AreEqual(felix.IsSickly, false);
         
         Assert.AreEqual(spot.IsHiding, false);
         Assert.AreEqual(spot.IsSickly, false);
         Assert.AreEqual(spot.IsRoamingTheCountrysideFoamingAtTheMouth, false);
         
         
         
//Act 3
         littleBoy.Detonate();
         
         Assert.AreEqual(lucifer.IsHiding, false);
         Assert.AreEqual(lucifer.IsSickly, true);
         
         Assert.AreEqual(gregor.IsHiding, false);
         Assert.AreEqual(gregor.IsSickly, true);
         
         Assert.AreEqual(felix.IsHiding, true);
         Assert.AreEqual(felix.IsSickly, true);
         
         Assert.AreEqual(spot.IsHiding, false);
         Assert.AreEqual(spot.IsSickly, true);
         Assert.AreEqual(spot.IsRoamingTheCountrysideFoamingAtTheMouth, true);
      }
   }
}

 
 

Let's step back through this slowly a second time. I tell a story here in three parts, and first of all our heros are

  1. an asp named Lucifer,
  2. a bug named Gregor (winking at Kafka),
  3. a cat named Felix,
  4. and a dog named Spot.

They start their lives in good health as seen here:

Asp lucifer = new Asp();
Bug gregor = new Bug();
Cat felix = new Cat();
Dog spot = new Dog();
 
Assert.AreEqual(lucifer.IsHiding, false);
Assert.AreEqual(lucifer.IsSickly, false);
 
Assert.AreEqual(gregor.IsHiding, true);
Assert.AreEqual(gregor.IsSickly, false);
 
Assert.AreEqual(felix.IsHiding, false);
Assert.AreEqual(felix.IsSickly, false);
 
Assert.AreEqual(spot.IsHiding, false);
Assert.AreEqual(spot.IsSickly, false);
Assert.AreEqual(spot.IsRoamingTheCountrysideFoamingAtTheMouth, false);

 
 

Next our villian is introduced, a NuclearBomb named littleBoy. All of the AbsorbRadiation methods for the animals are added to littleBoy's Detonate action, but Detonate is not yet called so all of the animals remain in good health.

NuclearBomb littleBoy = new NuclearBomb();
littleBoy.Detonate = lucifer.AbsorbRadiation;
littleBoy.Detonate += gregor.AbsorbRadiation;
littleBoy.Detonate += felix.AbsorbRadiation;
littleBoy.Detonate += spot.AbsorbRadiation;
 
Assert.AreEqual(lucifer.IsHiding, false);
Assert.AreEqual(lucifer.IsSickly, false);
 
Assert.AreEqual(gregor.IsHiding, true);
Assert.AreEqual(gregor.IsSickly, false);
 
Assert.AreEqual(felix.IsHiding, false);
Assert.AreEqual(felix.IsSickly, false);
 
Assert.AreEqual(spot.IsHiding, false);
Assert.AreEqual(spot.IsSickly, false);
Assert.AreEqual(spot.IsRoamingTheCountrysideFoamingAtTheMouth, false);

 
 

Finally, the bomb goes off and all of the animals get sick, each in their own way. Observe:

littleBoy.Detonate();

Assert.AreEqual(lucifer.IsHiding, false);
Assert.AreEqual(lucifer.IsSickly, true);
 
Assert.AreEqual(gregor.IsHiding, false);
Assert.AreEqual(gregor.IsSickly, true);
 
Assert.AreEqual(felix.IsHiding, true);
Assert.AreEqual(felix.IsSickly, true);
 
Assert.AreEqual(spot.IsHiding, false);
Assert.AreEqual(spot.IsSickly, true);
Assert.AreEqual(spot.IsRoamingTheCountrysideFoamingAtTheMouth, true);

 
 

lucifer, gregor, felix, and spot, all independent objects from littleBoy, were all listening for littleBoy to act. That's the observer pattern!

Friday, October 10, 2014

Change Languages in Google Chrome?

  1. from the hotdog menu at the upper right pick "Settings"
  2. pick "Show advanced settings.."
  3. click "Language and input settings..." under a "Languages" subsection partway down the page to open a "Languages" modal
  4. there is an "Add" button here for adding new languages and you may click on different languages in a list to make them do different things such as be a default or be used in spell checking

In experimenting with this today I tried to test through Chrome but I couldn't get Frenchy Chrome to trigger Frenchy content. Sigh. Maybe I needed to restart my browser after changing up settings. I don't know.

Addendum 10/12/2014: Yes, you must close and reopen Chrome to see the effect of the change of language.

distinction between encrypting and encoding

It is not true to say that that which is encrypted cannot be unencrypted and that the only use case for encryption is doing things like encrypting a would-be answer for "What is the password?" to attempt to match it against an encrypted password at a database. Data may be encrypted and then decrypted using a key. An encoding also of course may be decoded, but the distinction is that anyone may decode an encoding without knowing a key. What is more, the mapping-to-something-all-but-impossible-to-reverse-engineer in the password scenario I just mentioned would typically be thought of as hashing and not encrypting.

How to do modern day globalization/localization/internationalization with .resx files.

I was wrong here where I suggest it is some really hard problem that you might as well not think about. Today my superior found this which explains:

 G11N  globalization (supporting different cultures)
 L10N  localization (customization to a specific culture)
 I18N  internationalization (both of the above)

Following the advice in the blog posting my superior shared, I made, in an existing ASP.NET solution, a new "Class Library" type project called "Resources" and added four .resx files to it named like so:

  1. Copy.de.resx
  2. Copy.es.resx
  3. Copy.fr.resx
  4. Copy.resx

The accessibility modifier needs to become "Public" for each of these. If you open up one of these files in Visual Studio you will see a dropdown menu labeled "Access Modifier" for changing the setting running across the top of the pane holding the opened file. Clearly, Copy.resx is the catch-all which will catch almost all and the other three files are for German, Spanish, and French language support. I made another project inheirt the "Resources" project and in the other project (ASP.NET MVC) I was able to summon copy out of the resources like so:

string whatever = Resources.Copy.Whatever;

 
 

Moreover, I was able to experiment with retrieving the result for a specific culture like so:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr");
string whatever = Resources.Copy.Whatever;

 
 

While we are talking about reading and accessibility, this is my first blog posting since Malala Yousafzai has won the Nobel Peace Prize overnight. Kudos to her.

There is something pessimistic in me that is waiting for her to fall over dead from the bullet to the head that she has supposedly fully recovered from. Perhaps she'll have trouble later in life. Then again, perhaps she'll upstage all of my cynicism too and be a smiling face with us for another sixty or seventy years. I am grateful for the "day in the sun" she is having today. She's the youngest person ever to win the Nobel Peace Prize! She does share it this year with a Mr. Kailash Satyarthi who has been working to stop child labor abuses in India. I recall that there was an upset last year when the Organisation (British spelling, not Americanized "organization") for the Prohibition of Chemical Weapons or OPCW won the award instead of Malala... but the Nobel Prizes are not the Academy Awards where one has to impress in the most immediate year to be a nominee, so... it's her day ladies and gentlemen.

Thursday, October 9, 2014

Embedding resources in a satellite assembly doesn't look trivial.

I've been fighting with it all day and this makes me just want to give up. It suggests a separate program named al.exe is needed for the act beyond Visual Studio!

Addendum 10/10/2014: I found an easy way to approach this problem after all. See: this

Wednesday, October 8, 2014

What if an asp:ListView is empty? Specify what should happen with EmptyDataTemplate.

Like so, immediately inside the ListView's tag:

<EmptyDataTemplate>
   <div class="whatever">
      No Results Found
   </div>
</EmptyDataTemplate>

How do I decorate a web forms HTML tag already decorated with runat="server" with an onload event?

Like so from the C# side:

IFrame.Attributes.Add("onload", "compensateIfFormFailsToLoad()");

 
 

...or like so:

IFrame.Attributes["onload"] = "compensateIfFormFailsToLoad()";

Make the ruler go away in Google Chrome Developer Tools.

I did it by going into "Settings" (the gear icon at the upper right) and clicking the "Restore defaults and reload" button. The rulers disappeared anew.

Addendum 9/6/2015: I tried this anew a minute ago and it didn't work. I ended up just uninstalling and reinstalling Google Chrome. That did the trick.

Put an onload attribute on an iframe HTML tag to have a JavaScript event occur when the iFrame's contents are done loading!

This gave me the idea!

Time Warner may "quarantine" your router!

When I got home from work yesterday I could not connect to the internet. I reset the router and modem a bunch of times and restarted my laptop some too. That's how we solve these problems, right? No dice. I navigated through the Time Warner phone tree to speak to a Time Warner tech who had to defer to a second tech a level up who struggled to ping my router. Eventually he realized that a "quarantine" had been placed on my router and took the quarantine off. Even then I was yet unreachable and we scheduled a visit for a technician to see me on what would have been tomorrow. I was cut off from the internet all night and then my service was magically restored this morning so I could cancel the pending appointment. Perhaps they figured out their embarrassing problem. The second tech admitted that a quarantine has specifically been placed on my router to make it stop working as it was an old model. He suggested the idea was to force me to call in so that they could talk to me about a better, more modern router with more features!

an end of unlimited wireless?

Supposedly Verizon Wireless no longer has unlimited wireless and will force me to pick a plan with a cap of X amount of data if I ever change phones. I only still have unlimited wireless because I'm still on a preexisting plan. This is one more reason to just stick with my iPhone 4S and not get a "better" phone. This may only be the shape of things Texas-side. I'm not sure of the scope of this. A coworker who also has Verizon was telling me about how she had to give up unlimited wireless when she got a new phone and was of course forced to leave her preexisting plan. I wonder how long I may cling to my existing plan. The peeps who already have unlimited wireless cannot be shoved out of it at least. A different coworker at the same lunch outing today said that it's almost the same thing with AT&T in Texas with just a few exceptions.

What is EBITDA everyone?

Why it's Earnings Before Interest, Taxes, Depreciation and Amortization.

(Amortization is the act of doing away with debt by paying it off/down, and, while we're doing acronyms, LASER is light amplification by stimulated emission of radiation.)

Tuesday, October 7, 2014

E-Commerce Indicator (ECI)

This suggests that you must give an ECI code when submitting a Visa or MasterCard payment. The codes are:

  1. cardholder was authenticated
  2. an attempt to authenticate was made but the cardholder or issuer didn't participate
  3. no authentication but we do have https!
  4. not secure at all (all terminals use this code)
  5. not secure at all

 
 

By the way, the way to start an ordered list with a number other than one in HTML looks like this:

<ol start="5">
   <li>five</li>
   <li>six</li>
   <li>seven</li>
   <li>eight</li>
   <li>nine</li>
</ol>

Monday, October 6, 2014

Is there to be a CSS4?

This sure seems to thinks so and offers some markup. One of my superiors mentioned today that something that is to be is the abililty to hover over a child a element and affect the styles of its parent!

window.open in JavaScript seems to replace the current window in JavaScript at a web clip instead of actually opening a new window!

Curiously, if you look at what is in window.opener.name from the window you opened it will be the name you gave to the second window from its "parent" and not undefined. window.opener.someMethodOnTheParentPage will however be undefined in this circumstance when window.opener.someMethodOnTheParentPage might otherwise be legitimate at the parent page. closeChildWindow (in a prior blog posting) would be an example of a method hanging off of window.opener that would only exist at the parent page. The fact that there is a window.opener whatsoever suggests that whenever you open a new window in a web clip that you are just replacing the existing window with the new window and not staging some circumstance in which a new window is sitting over top of the old window and hiding it completely. I have observed these behaviors at an iPad, yet in Safari at the same iPad window.open just opens the new window in a new tab instead of replacing the existing tab with new contents. Two very different behaviors occur contrasting the regular Safari experience to that of the web clip.

Non-repudiation conceptually encompasses scenarios in which neither the sender nor the receiver of a communication may deny that a communication was communicated.

An example would be a scenario in which one receives and email and approves the sending of a receipt acknowledging that the email was received.

Icons have eight sizes?

I experimented with IcoFx yesterday and beyond the four sizes I mention here another four seem to be:

  1. 256 x 256 pixels
  2. 128 x 128 pixels
  3. 96 x 96 pixels
  4. 48 x 48 pixels

Saturday, October 4, 2014

tech insights from my sister

I saw my sister today. Her birthday is four days away but we got together to celebrate early today. She mentioned to me that if you charge an iPhone in "Airplane Mode" that it charges quicker than otherwise. Beyond this revelation, I saw something interesting in her apartment. It was a Power Sentry Powersquid Surge Protector. I had never seen a power supply of this shape before and it fascinated me.

Friday, October 3, 2014

Two Dead Ends

I suppose I'll offer some notes on two things I've tried to make progress on in the name of offering up real blog postings. In both cases I'm running into brick walls and am hung up, unable to go forward. First I tried to recreate a simple OWIN example as offered up by Reaz Haq in this Austin .NET User Group talk. I recreated his code from a photo of his projection that I took with my phone like so:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Owin;
namespace Whatever
{
   using AppFunc = Func<IDictionary<string, object>, Task>;
   
   public class Startup
   {
      public void Configuration(IAppBuilder appBuilder)
      {
         appBuilder.Use(new Func<AppFunc, AppFunc>(Middleware));
      }
      
      public AppFunc Middleware(AppFunc nextMiddleware)
      {
         AppFunc appFunc = (IDictionary<string, object> environment) =>
         {
            var bytes = Encoding.UTF8.GetBytes("<h1>Hello adnug</h1>");
            var headers = (IDictionary<string, string[]>) environment["owin.ResponseBody"];
            
            headers["Content-Length"] = new[]
                  {bytes.Length.ToString(CultureInfo.CurrentCulture)};
            headers["Content-Type"] = new[] { "text/html" };
            
            var response = (Stream)environment["owin.ResponseBody"];
            response.WriteAsync(bytes, 0, bytes.Length);
            
            return nextMiddleware(environment);
         };
         return appFunc;
      }
   }
}

 
 

If it worked it should just spin up a web page with this HTML in it:

<h1>Hello adnug</h1>

 
 

...adnug being the Austin .NET User Group. Things Reaz did to get this working:

  • install OWIN from Nuget with: Install-Package Owin
  • also get the executable with: Install-Package OwinHost ...perhaps? ...we will need the executable and this Nuget command will put it at C:\yourprojectnamehere\packages\OwinHost.3.0.0\tools\OwinHost.exe
  • create a class library as a project where it is the only project in a solution
  • rename the one .cs file that comes with the project to be "Startup" and change its code to be what I advertise above
  • set it to be the startup project
  • in the project properties, under "Debug" pick "Start external program" under the "Start Action" subsection and here in you will pick the OwinHost.exe executable to run the Katana web server

 
 

Alright, this all works, but then when you debug the application the shell for OwinHost.exe flickers open and then shuts again. In Reaz's example, the shell stayed open and advertised a locale to reach out to to see the HMTL it was crafting at something like http://localhost:5000 and Reaz would pull up a browser and be able to hit the URL, displaying the "Hello adnug" message for the room to see. How do I keep the shell from closing right away? Anyone know? I tried to give -interactive:true -debug:true as command line arguments to no avail. What am I missing? The other thing I've been struggling with is trying to earn myself one of the free, green C# T-shirts by installing Xamarin and then running the dummy Xamarin Store application. As best as I can tell one is supposed to run Xamarin studio side by side with Visual Studio so that one may spin up an Android emulator in Xamarin studio and then debug in Visual Studio to have the debugging manifest in the emulator.

The app comes with two emulators which don’t support version of 19 of Android which you will need. You may install SDKs under the "Open Android SDK Manager..." option under the "Tools" menu in Xamarin Studio and then may create your own emulator under the "Open Android Emulator Manager..." option under the "Tools" menu, but I still can't get things to work. I keep running into an error reading "Deployment failed because the device does not support the package's minimum Android version. You can change the minimum Android version in the Android Application section of the Project Options." ...and as it turns out I cannot just roll back to an earlier version of Android as the Xamarin Store code breaks.