Friday, February 28, 2014

"concrete" in Java

...implies that which actually does something as opposed to that which has placeholder methods for something that inheirts it to override. Concrete means "not interface" per a coworker. A class which does not contain any undefined method is a concrete class.

TimTowTdi

I ran into this Perl term for "there is more than one way to do it" just now when Googling for a less awful way to say: There is more than one way to skin a cat.

  1. http://en.wiktionary.org/wiki/TIMTOWTDI
  2. http://slang.org/TIMTOWTDI-meaning-definition
  3. http://c2.com/cgi/wiki?ThereIsMoreThanOneWayToDoIt

Thursday, February 27, 2014

for swizzle

I overheard a conversation today on pointer swizzling of which Wikipedia says that it is the art of replacing a soft reference from one object to another by way of a number, Guid, or name with an actual pointer. Imagine a serialized collection of objects which holds parent/child relationships getting cast back to objects in C#.

grab the value of a parameter off of an HTML element in plain Jane JavaScript

if (element.getAttribute("data-dojo-attach-point").indexOf("whatever") != -1) {

Wednesday, February 26, 2014

Add a new closing form tag and then open a new form tag to make an ASP.NET web form post to someplace other than itself.

The new form tag will have an action pointing to the URL of where you wish to head to. This is a classic old hack.

my old notes on integrating with a merchant account

This is a blast from the past. I think this goes back to 2007. I haven't done this sort of thing in a long, long time. I never hear anything about anyone rolling their own shopping cart anymore for a simple web presence. It seems like most people will use a canned package these days.

Google, Grande Communications, and AT&T will each bring 1gbps Fiber to Austin, Texas.

nice

subselect in SQL

SELECT * FROM Whatever WHERE myKey IN (SELECT myKeyReference FROM SomethingElse WHERE YetAnotherThing = 42)

Filtering arrays in JavaScript without Underscore.js!

Twelve, one hundred thirty, and forty-four end up in the variable in the blob of code below (which comes from here).

function isBigEnough(element) {
   return element >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);

 
 

This would have been a cleaner way to approach this challenge. :(

What keeps the Firefox burning?

How can Firefox compete as a browser when it does not have a huge company behind it like IE (Mircosoft) or Chrome (Google)? How has it kept apace for years? A coworker explained that Mozilla is a non-profit which is kept alive by donations. Google gives heavily as Firefox defaults to google.com for its home page. There may eventually be ads in Firefox too. I pulled away from it myself in 2013 when I realized I could do everything I used to do in Firebug (and more) in Google Chrome's Developer Tools. JavaScript, developed by Brendan Eich at Sun Microsystems is being formally versioned and kept by Mozilla. The JavaScript that exists outside of Firefox and Mozilla in other browsers is technically just ECMAScript, a scripting language standard (Ecma International's ECMA-262 spec), of which what Mozilla calls its version is JavaScript and of which what Microsoft calls its version is JScript. (You've seen that silliness in Visual Studio, correct?) Adobe's ActionScript for Flash is of this specification too.

Is this burning an eternal flame?

text-overflow: ellipsis;

...as a CSS style will put three dots (...) at the end of truncated text. See: this

display: inline-block;

...is awesome. If you decorate a series of divs WITH FIXED WIDTHS with this CSS style too they will end up sitting side by side on a horizontal row as if they all had...

float: left;

...on them, but they are not floating. They push other content down.

gradients in CSS

This markup:

<div style="
   width: 100px;
   height: 100px;
   background-image: -webkit-gradient(linear, 0% 0, 0% 100%, from(#decaff),
         color-stop(0.33, #decaff), to(#c0ffee));
   background-image: linear-gradient(to bottom, #decaff 0%, #decaff 33%,
         #c0ffee 100%);">
</div>

 
 

Makes this:

 
 

Links that helped me with this:

Tuesday, February 25, 2014

Objective-Clean

...was mentioned by a coworker a moment ago in a meeting, and it does linting for Objective-C.

Wipe Out Workspace

...is an option in Jenkins beneath the Workspace option at the upper left. This gets rid of some sort of cache and thus may unburden you of some nastiness. I don't really understand it yet but this has some more details on this clean up trick.

Monday, February 24, 2014

C:\Fluffy Nothing\src\FluffyNothing.UserInterface\home\index

...is an example of what an ASP.NET MVC route at /home/index/ looks like when it it summoned from C# with:

System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"])

With 'dojo/dom-class' one may "remove" a class decorating an element without any sanity checking to ensure the class actually decorates the element.

If the class is not there, the call to remove will throw no errors. This minimizes if/then logic obviously. In the example below domClass is a variable mapped to 'dojo/dom-class' at the AMD signature and countLineList is a data-dojo-attach-point designation in a dojox view.

var fourColumns = "cascading-effect-for-four-columns";
var fiveColumns = "cascading-effect-for-five-columns";
var fourColumnsOrFive = fourColumns;
if (this.mdoElt.ahType != i18n.typeUnplanned) {
   if (app.appSettings.AHS_ShowSystemQtyInCount) {
      fourColumnsOrFive = fiveColumns;
   }
}
domClass.remove(this.countLineList, fourColumns);
domClass.remove(this.countLineList, fiveColumns);
domClass.add(this.countLineList, fourColumnsOrFive);

Add current location to Favorites

in Windows 7, if you open up a path to a file share on your LAN at "My Computer" (Windows Explorer) then you right-click on "Favorites" at the upper-left, there should be an option for "Add current location to Favorites" which should let you keep a shortcut to where you are at the left navigation

can't find grunt.cmd even though Grunt is installed?

Try running this command line command: path=%PATH%;%APPDATA%\npm

This command will let you know if you're successful: where grunt

http://nodejs.org/dist/v0.10.26/node-v0.10.26-x86.msi

...is the place to download Node for Windows.

Friday, February 21, 2014

There is no if/then logic in dojox templates.

All you can really do is cough something up from a variable like this:

<div>${Whatever.Foo}</div>

 
 

All manipulations need to come from the controller side. If you want to conditionally hide something you could latch onto an attach point and conditionally swap out a CSS style.

Uncheck the checkbox for: "Straight quotes" with "smart quotes" ...under the "Replace as you type" heading in Microsoft Word 2013 to get rid of slanted quotes.

at: File > Options > Proofing > AutoCorrect Options... > AutoFormat As You Type

SMAC

...stands for: Social, Mobile, Analytics, Cloud ...I learned of this acronym today.

Dart!

Lars Bak who developed the V8 JavaScript engine for Chrome and has done extensive work in the name of optimizing performance for virtual machines, lead in a talk by a John Talley on Lars' new scripting language, Dart, in a prerecorded video displayed on a wall at Spanning Thursday night. He said that one could learn Dart in just one hour and supposedly there is a tutorial online as a part of something called Dart Flight School which shows you how to do just that, but the one hour timebox became clearly comedic once John started showing off code from an entirely new scripting language and descended into how out to override operators. The examples given during a fire hose or syntax-heavy geek out were really too much for me to memorize and I just sort of took it in numbly. To me Dart looks just as complicated a C#. Dart is Google's C#, by which I mean it is to be its premiere scripting language that it pushes, and I'd take it seriously as I'd take Google seriously if I were you. Some things about Dart are that it has been in version 1.0 since November, it is dynamic, and compiles to JavaScript. dart2js is the name of the compiler. There was much talk of Dart one day just running uncompiled, as is, in Chrome (and then, hopefully, other browsers) but presently the only way you may run it uncompiled is through Dartium (built in Chromium which is the open source project from which Google crafts its Chrome browser and also the Canary browser which is like the latest version of Chrome that is not yet well tested) which is the preview browser of sorts within the Dart IDE which is called "The Dart Editor" which is in fact a doctored up Eclipse. Just as you might preview an ASP.NET MVC project in Cassini, you might preview a Dart project in Dartium. Dart is for both the front end and the back end. You may use it with AngularJS or Polymer (a comparable framework to AngularJS) in much the same way you might use C# with Razor in an MVC app, and you may also use Dart to touch a database or write to flat files thus allowing you to work front-to-back in JavaScriptland without having to use Node.js for the backend stuff! You'd use the familiar moustache notation of AngularJS in your HTML. Dart itself has interfaces, and mixins, and garbage, collection, and lots of other things you can't hope to understand in an hour's time. Every Dart app gets a pubspec.yaml file for package management, which allows Dart to know what it needs to bake in when it compiles. Unused code is dropped from the compiled code. It is shaken out in "tree shaking." Dart supports the asynchronous qualities of JavaScript but not truthiness vagueness. Let's see, what else do I want to say? I think it jives with Firebase which is an API for storing JSON objects "in the cloud." Hmmm... A Mr. Charles d'Harcourt spoke after John and showed off a simple app that he made.

add a property to a JavaScript object based on dynamic content

var foo = {};
var bar = "baz";
foo[bar] = "qux";

 
 

If one calls foo.baz after the lines of code above, "qux" will be returned. The "baz" magic string may not be "dynamic" really, but you get the idea, right?

a return inside a forEach loop in JavaScript seems to sabotage the forEach loop

call: function(app, key) {
   if(app._appSettings === undefined) {
      return null;
   } else {
      app._appSettings.forEach(function(setting) {
         if (setting.ahCode == key) {
            if (setting.ahValue) {
               return setting.ahValue;
            } else {
               return setting.ahBooleanValue;
            }
         }
      });
   }
}

 
 

What is above ALWAYS returned null no matter the circumstance because a return inside a forEach loop in JavaScript seems to sabotage the forEach loop. I had to change it to:

call: function(app, key) {
   if(app._appSettings === undefined) {
      return null;
   } else {
      var returnMe = "null";
      app._appSettings.forEach(function(setting) {
         if (setting.ahCode == key) {
            if (setting.ahValue) {
               returnMe = setting.ahValue;
            } else {
               if (setting.ahBooleanValue == null) {
                  
//return null
               } else {
                  if (setting.ahBooleanValue) {
                     returnMe = "true";
                  } else {
                     returnMe = "false";
                  }
               }
            }
         }
      });
      if (returnMe == "null") {
         return null;
      }
      if (returnMe == "true") {
         return true;
      }
      if (returnMe == "false") {
         return false;
      }
      return returnMe;
   }
}

Thursday, February 20, 2014

Cryptography Basics

I saw Bankim Tejani of ServiceMesh speak on cryptography at a Wednesday meeting of IEEE (Institute of Electrical and Electronics Engineers). The talk gave a great 10,000 foot view of cryptography in general. Did you know?
 

  • A cipher is that which takes readable text and turns it into ciphertext which is either encoded or encrypted. Encoded text may be cast back to readable text by reversing the cipher so to speak. Caesarian-8 is an example of a cipher in which every letter is replaced by the letter 8 places forward again in the alphabet also that "Cat" becomes "Kib" as the T wraps around past the Z two positions back to the B. You can probably see how one decodes Kib back to Cat, but Kib only makes sense if you know what the cipher is!
     
     
  • A hash is a cipher process in which text is encrypted not encoded. You cannot cast the encrypted back to readable text. Hashes are used for keeping passwords. To see if a password matches a hashed password, you do not unhash the hashed, but instead you hash the unhashed and see if it matches the otherwise unreadable string you keep for a password.
     
     
  • A salt is an additional piece of data that goes into a function for creating a hash to make the algorithm harder for an outsider to decode. Every user account which has a salt for a password should get an independent random salt. The salt doesn't help (much) if it doesn't vary. A code-side object for a user could thus be improved from this:
    User record {
       userid
       pwhash
       attributes
    }

     
    ...by adding a field for a salt as seen below. A salt is an example of entropy which could be defined as something which randomizes a cipher. If one is not ciphering one letter at a time, but instead chunks of 512 bytes, one could write a cipher that takes the first chunk "regularly" and then adds entropy to each chunk in the subsequent stream based upon the prior chunk. But, not to digress...
    User record {
       userid
       pwhash
       salt
       attributes
    }

 
 

...but while we are on this subject, note that this is even better yet!

User record {
   userid
   pwhash
   salt
   algorithm
   attributes
}

 

Why not keep in a field a note of what algorithm was used the last time the password was reset? This allows for a maintainable system wherein the algorithm used may be swapped out with another one day. Why would you want to upgrade the algorithm used? Because every algorithm will eventually become antiquated. MD5 and SHA1 are types of algorithms for hashing which are no longer considered safe by way of just not being complicated enough. Modern day hackers can break these. Every possible value for a six to twelve alphanumeric string (for example) may be put in a list and used to eventually match a password in an "endless" (not really infinite) series of tries for each item on the list. There is too much complexity in SHA512 today to use this trick to break SHA512 which is encouraged as of this writing, but that won't last forever. Also, breaking the passwords out to their own collection offers a way to keep a history of passwords and force users to not reuse the last few passwords they used.

User record {
   userid
   attributes
}
 
Passwords {
   userid
   pwhash
   salt
   algorithm
   status (active or expired)
   lastUsedTime
}

 

The Zimmerman Telegraph is an example of a cipher fail. During World War I, Germany sent it to Mexico in an attempt to bait Mexico into attacking America. America intercepted the communication and was able to break the code inside. America would end up fighting Germany and not Mexico as things turned out. PGP (Pretty Good Privacy) uses public and private keys to send messages between parties. Any one individual has a both a public (advertised) and a private (secret) key. If Mr. Smith wants to send an encoded message to Mr. Jones then he would use Jones' public key and his own private key in the algorithm. Jones would use Smith's public key and his own public key to decode the message. This is not a typo on my part. Jones never gets handed the private key of Smith. So how could Jones possibly decode Smith's message? I asked about this at the talk and was told that it's just "magic." Somewhere deep inside the mathematics of PGP lives a trick for this. How to manage keys that need to be shared is the great unsolved problem of cryptography. Bankim mentioned that the key for decoding Blu-ray was accidentally published on Intel's web site. Beyond big mistakes like this, one has to assume that such a key would eventually slip out into the public domain anyways. As long as the key for decoding needs to be shared between multiple parties, the key will eventually leak out. Other things I should mention include:
 

  • Homomorphic is a concept in which both a blob of text and blob of corresponding ciphertext may be queried for key pieces of information with the SAME means. This is something cryptographers are trying to figure out presently.
  • AES stands for Advanced Encryption Standard and it is... a standard.
  • Many in cryptography are paranoid the American government has placed "backdoors" in ciphers in the name of spying on companies and individuals.
  • Slow algorithms rerun an algorithm over and over again to cipher. To break one of these you'd have to know the increment of reruns.
  • Export Control Classification Number (ECCN) is a code for categorizing American exports.
  • American laws are lax in the cryptography space. Anyone may use any encryption or no encryption unless they are: giving to parties in another nation, keeping financial data, doing a few key industry-specific things (there are regulations governing Healthcare for example)
  • Woodrow Wilson didn't like the Zimmerman Telegraph.

Wednesday, February 19, 2014

Glyphicons!

glyphicons.com is a neat resource for using icons in the form of a font in lieu of images. Using the cheatsheet at the base of this blog posting to find an encoding for a bomb, one may make a class that will put a bomb icon before copy like so:

.bomb:before {
   font: 24px/1em 'Glyphicons Regular';
   -webkit-font-smoothing: antialiased;
   line-height: 29px;
   vertical-align: middle;
   content: "\1F4A3";
}

In Team Explorer, right-click on your "DefaultCollection" (or whatever the directory is named) and select "New Team Project..." to make a new project in TFS.

This touches on some Team Foundation Server basics including how to make a new repository outright which is new to me.

If it takes forever to copy files from one folder to another in Windowsland...

...it might be your antivirus. Also if Outlook stops working and Chrome can't seem to load a web site, it might be your antivirus. In the later cases there is going to be a dialog box somewhere alerting you that the program has changed and waiting for you to affirm that it is still alright for the program to access the outside.

Add a question mark followed by a string of random characters to the end of a URL in Google Chrome to force it to refresh the HTML it gets for a site it has cached.

This trick for disabling the cache in Google Chrome Developer Tools will not reach into files that do not show up under the "Sources" tab (in Google Chrome Developer Tools) which may include HTML files in views which are slurped into a Dojox application which are specified in config.json.

Tuesday, February 18, 2014

a better way to destroy a cookie

HttpCookie cookie = Request.Cookies[MagicStrings.IdentityName];
if (cookie != null)
{
   cookie.Value = "";
   cookie.Expires = clock.GiveTime().AddDays(-1);
   Response.Cookies.Add(cookie);
}

 
 

What is above should really replace what is below in this. What is below isn't so wonderful.

HttpCookie cookie = new HttpCookie(MagicStrings.IdentityName, "");
cookie.Expires = clock.GiveTime();
Response.Cookies.Add(cookie);

make a text type input in HTML read only by decorating it with "readonly"

<input type="text" name="whatever" readonly />

Make a number type input field accommodate decimals.

<input type="number" name="whatever" step="0.01" />

...is a "paraphrased" example given here which shows off the step parameter which is the key to the trick.

Monday, February 17, 2014

cookies and session variables in modern ASP.NET MVC

Here is how to set cookies and session variables in modern ASP.NET MVC. This is a method from a controller:

private void SetIdentity(string id)
{
   IClock clock = ObjectFactory.GetInstance<IClock>();
   string carat = "^";
   if (id != null && id.Contains(carat))
   {
      string[] instructionAndIdentity = id.Replace("^^", ".").Replace("||",
            "+").Split(carat.ToCharArray());
      string pipeSymbol = "|";
      if (instructionAndIdentity[1].Contains(pipeSymbol))
      {
         if (instructionAndIdentity[0] == MagicStrings.MakeCookieOnMatch)
         {
            HttpCookie cookie = new HttpCookie(MagicStrings.IdentityName,
                  instructionAndIdentity[1]);
            cookie.Expires = clock.GiveTime().AddDays(30);
            Response.Cookies.Add(cookie);
         } else {
            HttpCookie cookie = new HttpCookie(MagicStrings.IdentityName, "");
            cookie.Expires = clock.GiveTime();
            Response.Cookies.Add(cookie);
         }
         HttpContext.Session[MagicStrings.IdentityName] = instructionAndIdentity[1];
      }
   }
}

 
 

There is plenty of noise here, but I think you can see what you need beyond what I wrote for myself for a project I am tinkering with. Note how a cookie is destroyed by being set to nothing. You may comparably kill a session variable by setting it to null or an empty string. Here is how to fish for the settings once they are set. Again, forgive the noise. Again, this is a method in a controller.

protected Person GetIdentity()
{
   IPersonRepository personRepository =
         ObjectFactory.GetInstance<IPersonRepository>();
   HttpCookie cookie = Request.Cookies[MagicStrings.IdentityName];
   if (cookie != null)
   {
      string emailAndPassword = cookie.Value;
      if (emailAndPassword.Contains("|"))
      {
         return PersonFinder.FindPersonByEncryptedPassword(emailAndPassword,
               personRepository);
      }
   }
   if (HttpContext.Session[MagicStrings.IdentityName] != null)
   {
      string emailAndPassword = HttpContext.Session[MagicStrings.IdentityName] as
            string;
      if (emailAndPassword != null && emailAndPassword.Contains("|"))
      {
         return PersonFinder.FindPersonByEncryptedPassword(emailAndPassword,
               personRepository);
      }
   }
   return null;
}

 
 

Addendum 2/18/2014: The way I am destroying cookies above is bad as it turns out. Please see this instead.

Trim away trailing whitespace in Sublime Text 3.

JSHint is behaving differently for our team between Sumblime Text 2 and Sublime Text 3 (in spite of identical settings) on our team. Trailing whitespace in .js files is not highlighted in the later version for some reason. There is some good news however in that this explains how you may make Sublime Text 3 always trim away the trailing whitespace from a file upon a saving, and that addresses our problem in a roundabout way. A trim_trailing_white_space_on_save setting needs to end up in the file one exposes by picking the "Settings - User" option under the "Preferences" menu. My own settings file looks like so:

{
   "color_scheme": "Packages/User/Monokai (SL).tmTheme",
   "font_size": 11,
   "ignored_packages":
   [
      "Vintage",
      "SublimeLinter-jshint"
   ],
   "trim_trailing_white_space_on_save": true
}

 
 

While I am running my mouth, Trailing Spaces is a plugin for Sublime that I tried to install today to solve the same problem. This and this touch on installing plugins and this is a place to find plugins online which may be installed at the console while there is also a way to manually install a plugin and this is where you'd get the particular file to put at what is on my computer at:

C:\Users\tjaeschke\AppData\Roaming\Sublime Text 3\Installed Packages

 
 

...to install Trailing Spaces. And installed plugins will, I think, end up at what is on my laptop at:

C:\Users\tjaeschke\AppData\Roaming\Sublime Text 3\Packages

 
 

...which is a folder exposed by going to "Browse Packages..." under the "Preferences" menu. Going to "Show Console" under the "View" menu will alternatively expose the console. I tried an install at the console and a manual install and I couldn't get it to work however. Whatever.

Saturday, February 15, 2014

generate a random password

Challenge: You want to make a random password for a password reset feature in C#. You can make a new Guid and just strip out the hyphens, but you've noticed that you cannot just build a string by returning (several times over) a character based upon a random number. The random numbers in C# are based on the ticks and if you call something that generates a random number ten times in a row back to back you will get the same random number ten times over. Another approach:

  1. Make a Random number using a big range of possible values such as one billion.
  2. Cast the number to a string.
  3. Encrypt the string.

Friday, February 14, 2014

Ctrl-Shift-F in Sublime Text 3 seems to unlock the Find and Replace feature.

...as opposed to merely Ctrl-F.

Redgate .NET Demon

...will constantly recompile your work in the background as you use Visual Studio (2010 or better). The .NET Demon will expose compilation errors in realtime and let you thus know if there is drama in associations between solutions and projects.

debug minimized .js?

Click on the {} at the lowerleft of the debugger in Google Chrome Developer Tools to turn on "Pretty print" which should allow you to set breakpoints in "lines" of code which have been snugged up into one big line of code together. (think minimized .js)

Automatically generated documentation for C#?

GhostDoc makes documentation for C# methods. It will try to parse a method's name and make sense of it in the name of crafting a descriptive sentence. It is a Visual Studio plugin.

Thursday, February 13, 2014

I learned today that one may quickly preview a selected web site or virtual folder in Internet Information Services (IIS) Manager.

Just click the link at the right nav (the "Actions") which reads: "Browse *:80 (http)" ...or some variant of this.

Web.config hacks around ASP.NET Forms Authentication pain points!

This and this touch on how to open up permissions in a folder full of stylesheets and/or images (or even .js files) so that a user may see the images and the effects of the stylesheets without being logged in. The trick is to put a Web.config file inside of the folder full of content you wish to expose to everyone in all circumstances which has this in it:

<configuration>
   <system.web>
      <authorization>
      <allow users="*"/>
      </authorization>
   </system.web>
</configuration>

 
 

This tells us the following is required just to get an application with forms authentication to run in IIS.

<system.webServer>
   <validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

Sketch

I think Sketch may be a tool like Balsamiq as a coworker offered some prototypes today that were made in it.

Press the right or left arrow key in tandem with the Windows key in Windows 8 to make a window snap to and fill one half of the screen.

The feature detailed here may be easily achieved via this hotkey approach.

Create a local branch in TortoiseHg

You may have noticed the "Phase" column in TortoiseHg. A value of "draft" suggests a local commit while a value of "public" suggests a commit that exists in greater source control beyond mere local scope.

 
 

If you right-click on the "draft" designation for a detached head (and pick "Change Phase to" from the menu which appears) and set it to "secret" instead...

 
 

...you will create a local branch.

Don't update to the detached head or pull down from source control into it. If you do not, the detached head will otherwise be ignored and TortoiseHg will not complain when you try to make future commits with the detached head in existence. Turn "secret" back into "draft" to merge the local branch back in later.

Tuesday, February 11, 2014

Sass!

Syntactically Awesome Style Sheets (or Sass) is something akin to LESS (Leaner CSS) in that it provides a way to "use variables in style sheets" which is to say you may compile from its markup with variables to a .css file where variables end up becoming whatever they become. There is a Chirpy thing going on with Sass in that it can be smart enough to know when a Sass file has changed and that a new CSS file should be generated. (Chirpy will render out minified .js files for regular readable .js files and, I believe, CSS files for LESS files upon changeups.)

C:\Program Files (x86)\Cisco Systems\VPN Client\Profiles\ ...is where your .pcf lives.

This has the data for the line item (Connection Entry) for a saved connection that shows up in the little Cisco "VPN Client" window. You should be able to just open this file in Notepad and make sense of it.

an example of authenticating when sending email from C# via System.Net.Mail

public void Send(string to, string message)
{
   MailMessage alert = new MailMessage("something@example.com", to);
   alert.Subject = "Communication!";
   alert.Body = message;
   NetworkCredential credentials = new NetworkCredential("something@example.com",
         "letmein");
   SmtpClient emailSender = new SmtpClient();
   emailSender.Host = "smtp.example.com";
   emailSender.UseDefaultCredentials = false;
   emailSender.Credentials = credentials;
   emailSender.Send(alert);
}

Monday, February 10, 2014

When JavaScript integers are put into string fields at Web SQL databases they seem to end up with a one place decimal precision.

You will see a decimal followed by a zero at the end of your "number." One hacky cure is to add an empty string to the integer (making it a string) before sending it to Web SQL.

Using dojo/on to react to a change in a dropdown list in dojo.

A coworker suggested that a better, modern (dojo 1.9.2) way to do this is:

define([
   "dojo/dom",
   "dojo/on"
], function (dom, on) {
   return {
      init: function(current, data) {
         var self = this;
         dojo.addOnLoad( function() {
            on(dom.byId('locale'), "change", function(evt) {
               alert(self.locale.value);
               dojo.stopEvent(evt);
            });
         });
      },

Sunday, February 9, 2014

Mutex

A mutex (mutual exclusion) is synchronization primitive (lock) which ensures that no two concurrent processes are in their critical section at the same time which in C# terms means a lock that is compiler-wide in lieu of merely assembly-wide.

CSS trick to make text align to the bottom of a div!

#mydiv {
   width: 200px;
   height: 300px;
   display: table-cell;
   vertical-align: bottom;
}

Saturday, February 8, 2014

how the sun looked to the original iPhone

A tweet of mine from Friday, October 16, 2009:

 
 

I am just as hypnotized and entranced with this as Bjarne Stroustrup is with his projector.

 
 

Ha. And, we think we are tech people. Yet, we are so easily distracted. I'd better avoid this Kool-Aid:

Friday, February 7, 2014

Get the value of a dojox.mobile.TextBox control.

var whatever = this.myControl.get('value');

Set the value of a dojox.mobile.TextBox control.

this.myControl.set('value', 'whatever');

React to a change in a dropdown list in dojox!

init: function(current, data) {
   var self = this;
   dojo.addOnLoad( function() {
      dojo.connect(dom.byId('locale'), "onchange", function(evt) {
         alert(self.locale.value);
         dojo.stopEvent(evt);
      });
   });
},

 
 

In order for the above to work in a dojox controller...

  1. One must have dojo/dom in the define signature of the AMD module.
  2. One must have "locale" as the value for both the id and the data-dojo-attach-point settings on a select tag like so:
    <select data-dojo-attach-point="locale" id="locale">

Thursday, February 6, 2014

list-style: none;

...is the CSS style which hides bullets at an unordered list. It will work at li and should be able to cascade down from ul.

putting quotes inside of quotes inside of quotes in HTML

<div data-dojo-props='Foo: "bar", Baz: "<div class=title>{{qux|default:\"NOT SPECIFIED\"}}</div>\n" + "<div class=description>{{quux|default}}</div>"'>

Wednesday, February 5, 2014

a modern HTML head tag for a mobile app

<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=480,initial-scale=1,maximum-
            scale=1,minimum-scale=1,user-scalable=no"/>
      <meta name="apple-mobile-web-app-capable" content="yes" />
      <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
      <title>AntMill</title>
   </head>

Fatal error: Unable to find local grunt.

This grunt error when unexpected and run from a command line at a folder where it should work...

 
 

...means you need to run this command again to reinstall:

npm install

Tuesday, February 4, 2014

'onClick' of object [object Object] is not a function

Getting this error when using dojox.mobile.ListItem likely means you need to change something like this:

<li data-dojo-type="dojox.mobile.ListItem"
   data-dojo-props="clickable:true, onClick:this.app.openView(null,{target:'Something'})"
   >Whatever</li>

 
 

...to something like this:

<li data-dojo-type="dojox.mobile.ListItem"
   data-dojo-props="clickable:true, app: this.app, onClick:function()
         {this.app.openView(null,{target:'Something'})}"
   >Whatever</li>

top level domains

http://data.iana.org/TLD/tlds-alpha-by-domain.txt today has the following list of top level domains which is always growing:

  1. AC
  2. ACADEMY
  3. AD
  4. AE
  5. AERO
  6. AF
  7. AG
  8. AGENCY
  9. AI
  10. AL
  11. AM
  12. AN
  13. AO
  14. AQ
  15. AR
  16. ARPA
  17. AS
  18. ASIA
  19. AT
  20. AU
  21. AW
  22. AX
  23. AZ
  24. BA
  25. BARGAINS
  26. BB
  27. BD
  28. BE
  29. BERLIN
  30. BF
  31. BG
  32. BH
  33. BI
  34. BIKE
  35. BIZ
  36. BJ
  37. BM
  38. BN
  39. BO
  40. BOUTIQUE
  41. BR
  42. BS
  43. BT
  44. BUILD
  45. BUILDERS
  46. BUZZ
  47. BV
  48. BW
  49. BY
  50. BZ
  51. CA
  52. CAB
  53. CAMERA
  54. CAMP
  55. CAREERS
  56. CAT
  57. CC
  58. CD
  59. CENTER
  60. CEO
  61. CF
  62. CG
  63. CH
  64. CHEAP
  65. CI
  66. CK
  67. CL
  68. CLOTHING
  69. CLUB
  70. CM
  71. CN
  72. CO
  73. CODES
  74. COFFEE
  75. COM
  76. COMMUNITY
  77. COMPANY
  78. COMPUTER
  79. CONSTRUCTION
  80. CONTRACTORS
  81. COOL
  82. COOP
  83. CR
  84. CU
  85. CV
  86. CW
  87. CX
  88. CY
  89. CZ
  90. DANCE
  91. DATING
  92. DE
  93. DEMOCRAT
  94. DIAMONDS
  95. DIRECTORY
  96. DJ
  97. DK
  98. DM
  99. DO
  100. DOMAINS
  101. DZ
  102. EC
  103. EDU
  104. EDUCATION
  105. EE
  106. EG
  107. EMAIL
  108. ENTERPRISES
  109. EQUIPMENT
  110. ER
  111. ES
  112. ESTATE
  113. ET
  114. EU
  115. EXPERT
  116. FARM
  117. FI
  118. FJ
  119. FK
  120. FLORIST
  121. FM
  122. FO
  123. FR
  124. GA
  125. GALLERY
  126. GB
  127. GD
  128. GE
  129. GF
  130. GG
  131. GH
  132. GI
  133. GIFT
  134. GL
  135. GLASS
  136. GM
  137. GN
  138. GOV
  139. GP
  140. GQ
  141. GR
  142. GRAPHICS
  143. GS
  144. GT
  145. GU
  146. GUITARS
  147. GURU
  148. GW
  149. GY
  150. HK
  151. HM
  152. HN
  153. HOLDINGS
  154. HOLIDAY
  155. HOUSE
  156. HR
  157. HT
  158. HU
  159. ID
  160. IE
  161. IL
  162. IM
  163. IMMOBILIEN
  164. IN
  165. INFO
  166. INSTITUTE
  167. INT
  168. INTERNATIONAL
  169. IO
  170. IQ
  171. IR
  172. IS
  173. IT
  174. JE
  175. JM
  176. JO
  177. JOBS
  178. JP
  179. KAUFEN
  180. KE
  181. KG
  182. KH
  183. KI
  184. KIM
  185. KITCHEN
  186. KIWI
  187. KM
  188. KN
  189. KP
  190. KR
  191. KW
  192. KY
  193. KZ
  194. LA
  195. LAND
  196. LB
  197. LC
  198. LI
  199. LIGHTING
  200. LIMO
  201. LINK
  202. LK
  203. LR
  204. LS
  205. LT
  206. LU
  207. LUXURY
  208. LV
  209. LY
  210. MA
  211. MANAGEMENT
  212. MARKETING
  213. MC
  214. MD
  215. ME
  216. MENU
  217. MG
  218. MH
  219. MIL
  220. MK
  221. ML
  222. MM
  223. MN
  224. MO
  225. MOBI
  226. MODA
  227. MONASH
  228. MP
  229. MQ
  230. MR
  231. MS
  232. MT
  233. MU
  234. MUSEUM
  235. MV
  236. MW
  237. MX
  238. MY
  239. MZ
  240. NA
  241. NAGOYA
  242. NAME
  243. NC
  244. NE
  245. NET
  246. NF
  247. NG
  248. NI
  249. NINJA
  250. NL
  251. NO
  252. NP
  253. NR
  254. NU
  255. NZ
  256. OM
  257. ONL
  258. ORG
  259. PA
  260. PE
  261. PF
  262. PG
  263. PH
  264. PHOTO
  265. PHOTOGRAPHY
  266. PHOTOS
  267. PICS
  268. PINK
  269. PK
  270. PL
  271. PLUMBING
  272. PM
  273. PN
  274. POST
  275. PR
  276. PRO
  277. PS
  278. PT
  279. PW
  280. PY
  281. QA
  282. RE
  283. RECIPES
  284. RED
  285. REPAIR
  286. RICH
  287. RO
  288. RS
  289. RU
  290. RUHR
  291. RW
  292. SA
  293. SB
  294. SC
  295. SD
  296. SE
  297. SEXY
  298. SG
  299. SH
  300. SHIKSHA
  301. SHOES
  302. SI
  303. SINGLES
  304. SJ
  305. SK
  306. SL
  307. SM
  308. SN
  309. SO
  310. SOCIAL
  311. SOLAR
  312. SOLUTIONS
  313. SR
  314. ST
  315. SU
  316. SUPPORT
  317. SV
  318. SX
  319. SY
  320. SYSTEMS
  321. SZ
  322. TATTOO
  323. TC
  324. TD
  325. TECHNOLOGY
  326. TEL
  327. TF
  328. TG
  329. TH
  330. TIENDA
  331. TIPS
  332. TJ
  333. TK
  334. TL
  335. TM
  336. TN
  337. TO
  338. TODAY
  339. TOKYO
  340. TOOLS
  341. TP
  342. TR
  343. TRAINING
  344. TRAVEL
  345. TT
  346. TV
  347. TW
  348. TZ
  349. UA
  350. UG
  351. UK
  352. UNO
  353. US
  354. UY
  355. UZ
  356. VA
  357. VC
  358. VE
  359. VENTURES
  360. VG
  361. VI
  362. VIAJES
  363. VN
  364. VOTING
  365. VOYAGE
  366. VU
  367. WANG
  368. WATCH
  369. WED
  370. WF
  371. WIEN
  372. WORKS
  373. WS
  374. XN--3BST00M
  375. XN--3DS443G
  376. XN--3E0B707E
  377. XN--45BRJ9C
  378. XN--55QW42G
  379. XN--55QX5D
  380. XN--6QQ986B3XL
  381. XN--80AO21A
  382. XN--80ASEHDB
  383. XN--80ASWG
  384. XN--90A3AC
  385. XN--CLCHC0EA0B2G2A9GCD
  386. XN--FIQ228C5HS
  387. XN--FIQ64B
  388. XN--FIQS8S
  389. XN--FIQZ9S
  390. XN--FPCRJ9C3D
  391. XN--FZC2C9E2C
  392. XN--GECRJ9C
  393. XN--H2BRJ9C
  394. XN--IO0A7I
  395. XN--J1AMH
  396. XN--J6W193G
  397. XN--KPRW13D
  398. XN--KPRY57D
  399. XN--L1ACC
  400. XN--LGBBAT1AD8J
  401. XN--MGB9AWBF
  402. XN--MGBA3A4F16A
  403. XN--MGBAAM7A8H
  404. XN--MGBAYH7GPA
  405. XN--MGBBH1A71E
  406. XN--MGBC0A9AZCG
  407. XN--MGBERP4A5D4AR
  408. XN--MGBX4CD0AB
  409. XN--NGBC5AZD
  410. XN--O3CW4H
  411. XN--OGBPF8FL
  412. XN--P1AI
  413. XN--PGBS0DH
  414. XN--Q9JYB4C
  415. XN--S9BRJ9C
  416. XN--UNUP4Y
  417. XN--WGBH1C
  418. XN--WGBL6A
  419. XN--XKC2AL3HYE2A
  420. XN--XKC2DL3A5EE0H
  421. XN--YFRO4I67O
  422. XN--YGBI2AMMX
  423. XN--ZFR164B
  424. XXX
  425. YE
  426. YT
  427. ZA
  428. ZM
  429. ZONE
  430. ZW

Monday, February 3, 2014

.attr('style'); will behave badly in Internet Explorer!

var bar = $("#Foo").attr('style');
if (bar == 'display:block;') {

 
 

Per this the above will not work in IE and I can attest that as much is true. The better jQuery to use is:

if ($("#Foo").css('display') == 'block') {

Sunday, February 2, 2014

I'm playing with Inkscape for the first time this morning.

  1. Ctrl-Shift-C seems to convert to text into what would be called "curves" (paths) in Adobe Illustrator.
  2. Cario doesn't support CMYK and as Cario is used by Inkscape for rending... there are no CMYK features. :(
  3. Ctrl-Shift-D followed by a navigation to the "Color Management" tab of the dialog box which appears takes one to a place for managing color swatches, but who cares? There are no Pantone colors.

Saturday, February 1, 2014

JavaScript "code behinds" in ASP.NET MVC applications.

At an ASP.NET MVC application, let's say you have a .cshtml view at /Views/Aardvark/AardvarkCountingWidget.cshtml. Let's also suppose that AardvarkCountingWidget.cshtml has a bunch of jQuery in it inside a script tag and you eventually wish to pull it out to a .js file. Well, I suppose that .js file could go at /Scripts/AardvarkCountingWidget.js, but what if it instead accompanied /Views/Aardvark/AardvarkCountingWidget.cshtml by living at /Views/Aardvark/AardvarkCountingWidget.js? In this convention a .cshtml file will have, if applicable, a .js "code behind" of the same name in the same folder. This is sort of like the code behinds of web forms... Mmmmm, maybe that's a stretch. Anyhow, this idea came from Joel Holder and it was going on at the AMD application I was a part of. That was an MVC3 project. /Views/Web.config prevents you from touching content inside of the Views folder in later versions of MVC save for using .cshtml views in the very different than usual way in Razor. So how do you allow access to .js files in the Views folder? Great question. I did it by removing everything between <httpHandlers> and </httpHandlers> and also between <handlers> and </handlers> at /Views/Web.config!