Monday, February 29, 2016

Visual Studio 2015 doesn't tell us which CSS classes are not being used.

It doesn't allow for a "find usages" against stuff in a .css file either. Lazy Microsoft! I'm just kidding. Visual Studio 2015 is so awesome that I'm surprised that this "missing thing" isn't a feature too.

Sunday, February 28, 2016

May I cast a dictionary to a list in C#?

Not exactly, no. The following is as close as one may get. This test passes:

[TestMethod]
public void may_cast_dictionary_to_list()
{
   
//arange
   Dictionary<string, string> deepSouthCapitals = new Dictionary<string, string>();
   deepSouthCapitals["Alabama"] = "Montgomery";
   deepSouthCapitals["Georgia"] = "Atlanta";
   deepSouthCapitals["Louisiana"] = "Baton Rouge";
   deepSouthCapitals["Mississippi"] = "Jackson";
   deepSouthCapitals["South Carolina"] = "Columbia";
   
   
//act
   List<string> states = deepSouthCapitals.Keys.ToList();
   List<string> cities = deepSouthCapitals.Values.OrderBy(x => x).ToList();
   
   
//assert
   Assert.AreEqual(states.Count, 5);
   Assert.AreEqual(states[0], "Alabama");
   Assert.AreEqual(states[1], "Georgia");
   Assert.AreEqual(states[2], "Louisiana");
   Assert.AreEqual(states[3], "Mississippi");
   Assert.AreEqual(states[4], "South Carolina");
   Assert.AreEqual(cities.Count, 5);
   Assert.AreEqual(cities[0], "Atlanta");
   Assert.AreEqual(cities[1], "Baton Rouge");
   Assert.AreEqual(cities[2], "Columbia");
   Assert.AreEqual(cities[3], "Jackson");
   Assert.AreEqual(cities[4], "Montgomery");
}

BIM is building information modeling

This has to do with building digital models of the goings on at a physical location such as perhaps the process waste water goes through at a water treatment plant. 3D graphics and architecture can come into play.

Saturday, February 27, 2016

MyGrid.SettingsBehavior.AllowSelectByRowClick = true;

This is the trick to make DevExpress' ASPxGridView grids have clickable rows.

function EditButton_Click(s, e) {
   var keys = MyGrid.SettingBehavior.GetSelectedKeysOnPage();
   if (keys.length < 0) {
      alert('no row is selected');
      return;
   }
   var key = keys[0];
   doWhateverIsNext(key);
}

How will the backdoor work?

At "Erase Data" under "Passcode" under "Settings" at your iPhone you may flip the setting on and when someone is trying to punch in the pin for your phone with a bad guess ten times in a row it will wipe your phone's data. This is the only way to protect your data from a circumstance in which someone takes physical possession of your cellie and then guesses your 4 digit pin with a brute force attack as there are only ten thousand possibilities for a 4 digit pin. The American government would like the ability to push an update to an iPhone in DFU (data firmware update) mode which undoes this safeguard setting allowing for brute force entry without consequence. They request as much from Apple and so far Apple will not oblige. One enters DFU mode by plugging their phone into iTunes and then pressing the top button and the main button together as if otherwise powering the phone off. In DFU mode, updates may be pushed to the device without a password being entered!

Friday, February 26, 2016

Use dynamic to fish for web forms controls?

The dynamic trick here for catching a Dog instead of an Animal can be used to catch a specific web forms control like a Textbox if a list of controls (from inside a Panel perhaps) are just pushed to a method that takes a control. This should allow you to easily find the Textbox if you don't know where it will be mixed in with other controls and do things to it specific to a Textbox.

Glassdoor and Yelp

Glassdoor has reviews of places to work and Yelp has reviews of restaurants. I don't mean formal reviews by a newspaper. I mean that anyone can add a review.

How do I make a DevExpress button use a callback instead of a postback?

This will will postback:

<dx:ASPxButton runat="server" ID="Button" />

 
 

This revamp can postback:

<dx:ASPxButton runat="server" ID="Button" AutoPostBack="False">
   <ClientSideEvents Click="AddEditButton_Click" />
</dx:ASPxButton>

 
 

You will need a JavaScript event like so:

function AddEditButton_Click(s, e) {
   MyCallback.PerformCallback("whatever");
}

 
 

MyCallback would be the name of a ASPxCallbackPanel wrapping all of the controls that use it. It will have a callback event.

How do I make the EditForm Template in an ASPxGridView appear as a modal?

I put this just inside the ASPxGridView. I seeing some bad behavior in which the modal sometimes does not stay open, but that may be a different problem altogether...

<SettingsEditing Mode="PopupEditForm"
   PopupEditFormHorizontalAlign="WindowCenter"
   PopupEditFormVerticalAlign="WindowCenter" PopupEditFormModal="True">
</SettingsEditing>

 
 

Bonus! I fixed the flickering form. You have to wire up this event.

MyGrid.RowDeleting += MyGrid_RowDeleting;

 
 

Like so:

private void MyGrid_RowDeleting(object sender, ASPxDataDeletingEventArgs e)
{
}

 
 

Also, open the form in JavaScript like this:

function MyButton_Click(s, e) {
   AdaptersGrid.AddNewRow();
   AdaptersCallback.PerformCallback(CreateCallbackParam("edit", "-1"));
}

 
 

Maybe I was supposed to be using RowInserting and RowUpdating events? This doesn't work after all. No! I needed to have the .AddNewRow without it being followed by the .PerformCallback.

Thursday, February 25, 2016

When networking servers one may have parent domains which cascade settings to child domains.

Things like users and groups and their permissions may be handed on in this manner.

Yahoo wraps Bing.

It doesn't have its own search anymore. It just uses Bing for it.

Outbound Engine is not owned by WP Engine. The two companies have nothing to do with each other.

Just because they have similar names and office in the name Austin, Texas building does not mean you should think they're cozy. (Though, I suppose they don't hate each other either.) Outbound Engine does mailchimpesque email campaign stuff and WP Engine does WordPress hosting.

Can the life of a session be expanded past 15 minutes in a .NET app?

Yes! This and my own blog posting here both touch on it. And... yet... 15 minutes in the max allowed to be PCI compliant!

Wednesday, February 24, 2016

Leeroy Jenkins

...not to be confused with Leroy Jenkins the Jazz musician, is a WOW (World of Warcraft, a massively multiplayer online role-playing game or MMORPG) avatar who screwed up plans in a raid by just doing his own thing. Characters like this exist in real life in our workplaces, huh? I've been this character myself a time or two.

If you create a code review in SmartBear Collaborator and assign yourself and someone else as reviewer...

...then when you approve the code review it will not be completed yet. The other party will also need to approve. This allows one expert to approve the C# and one expert to approve the SQL and that sort of thing.

NetBurst microarchitecture from Intel!

AMD may be awful and appear to only serve to keep Intel from having an monopoly, but it also helps Intel in another way. It keeps Intel from being lazy. I caught lunch with an old colleague and he suggested that NetBurst was an example of a bad, marketing-driven design from Intel that occurred in complacency. I know that half of the AMD campus in Austin is now rented out to other businesses as the company itself goes farther and farther down the tubes, and, yet, we all need AMD.

Do you want Google Chrome to save your credit card numbers?

No, you do not. It will not be encrypted. I found a Stack Overflow thread which said as much. Don't fall into this guys.

Tuesday, February 23, 2016

What is Watson from IBM?

I watch a lot of cnn.com video clips and I am always sitting through commercials about Watson (named for the original CEO) when I do so. I thought I'd Google it and figure out what it was all about. Wikipedia says: "Watson is a question answering computer system capable of answering questions posed in natural language"

PostNet

...is a rival to the once-was-Kinko's arm of FedEx. You can get business cards and the like printed here. They do the disposable signs you can put in your front yard to advertise your support for a politician, etc.

Make a sproc go away!

DROP PROCEDURE [dbo].[Whatever]

Monday, February 22, 2016

How do I nest a .min.js file below it's .js "parent" in Visual Studio?

It's basically a variation of this trick.

the gear is gone

...from Google Chrome Developer Tools! Instead press F1 (with the tools open) to get at the settings where you may disable the caching of JavaScript files as suggested here.

partials instead of regions?

This touches on an alternate way to break up a fat C# class without using regions and in particular if you inherit from multiple interfaces maybe you could have a different partial to satisfy each interface's neediness. I'm not sure this is better honestly. In my imagination I thought of code-generated code that cannot compile until some love is given to it at a dev-rolled partial. I shared the following over that stupid Slack app that explains my thoughts:

  • In particular the idea of using partials in lieu of regions in a fat C# class. I'm not sure it isn't even more gross though. And yet... In the typical code generation pattern one associates with partials wherein one partial is generated code and one partial is a hand-rolled extension, you could force the hand-rolled extension to have certain requirements by using this interface trick and thus babysit devs a little bit. i.e. “You must write your own error handling method and the code generation tool ain’t gonna do it for you.” ...that sort of encouraging straitjacket ...if you're playing God and making a T4 template abomination anyways, why not go apeshit?

Saturday, February 20, 2016

Lambda getsetter which only gets one thing in C#?

If SumpremeCourtJustice were an enum you could have...

public SumpremeCourtJustice VacantSeat => SumpremeCourtJustice.Scalia;

 
 

This is basically just like this...

public const SumpremeCourtJustice VacantSeat = SumpremeCourtJustice.Scalia;

 
 

...however the first thing could be augmented with virtual and/or override keywords which do not jive with the const keyword. ...But, what if the parent is an abstract class and just has something like this:

public abstract SumpremeCourtJustice VacantSeat { get; }

 
 

If there is no default setting, then the overriding looks like:

public override SumpremeCourtJustice VacantSeat { get; } =
      SumpremeCourtJustice.Scalia;

Sunday, February 14, 2016

When putting strings in T-SQL for inserts, you wrap the strings in single quotes so how do you have a single quote in a string itself?

You use a double single quote to represent a single quote. That's a single quote typed twice and not to be confused with a double tick.

Insert INTO Techies (Name) Values ('O''May')

How do I compare the alphabetic order of things in C#?

You can't compare strings, but you can compare characters like so:

[TestMethod]
public void compare_strings()
{
   char a = 'a';
   char b = 'b';
   Assert.IsTrue(a < b);
}

 
 

This test passes. a is less than b as it comes earlier in alphabetic order. Note that char types are declared in single ticks while a string is declared in double quotes. This test won't compile. This is the wrong way:

[TestMethod]
public void compare_strings()
{
   string a = "a";
   string b = "b";
   Assert.IsTrue(a < b);
}

 
 

Addendum 2/18/2016: It has been pointed out to me in the comments below that ASCII values are compared and thus there may be unexpected results when comparing a capital letter to a lowercase letter. To make my trick here work you will have to cast strings to lowercase before looping through their characters if you want a fair comparison.

Friday, February 12, 2016

Don't slap a vertical gradient on a web page's body.

The problem is that when you scroll down beyond what is immediately visible the gradient will start anew, sort of like a tiling effect.

Thursday, February 11, 2016

Microsoft Hololens

This is more that just Microsoft's Google Glass. It is augmented reality. You can see rendered 3D objects in tandem with the real physical objects in the room together and they fit in perspective.

Keep a CSS effect from cascading to child elements of the thing being skinned.

This has this:

#parent {
   white-space: pre-wrap;
}
#parent * {
   white-space: initial;
}

 
 

The asterisk is the magicmaker.

 
 

Addendum 7/7/2018: The asterisk is the Universal Selector and matches any type.

make a string of capital Ws

This is a good way to test if x number of characters will fit in a certain space. It may not be the perfect measuring stick, because who would realistically type a string of Ws?

Wednesday, February 10, 2016

the books pushed upon us at work

  1. How to Win Friends and Influence People by Dale Carnegie was suggested by Pierre Kerbage when he ran Network Logistic, Inc. which is that place that became White Glove which then became mindSHIFT. Copies of the book were just given out in one meeting and I read a chunk of mine. However, there was no follow up and I knew no one else was reading it so... whatever.
  2. Clean Code by Robert C. Martin was selectively read (some chapters, not others) at my next place of employment in a book club format. We all talked every week about the reading for the week.
  3. The 360 Degree Leader by John C. Maxwell was similarly digested in a weekly way at the @hand Corporation and this is an example of a book not to read. It's mostly filler. There are some gold nuggets of wisdom here and there in the sea of nothing like "don't chase two rabbits" yet it's mostly an exercise for the sake of an exercise. John tells you not to do anything at the expense of your family and that if you can't champion your leaders that you should probably find other employment and then turns around and suggests that it is admirable to "do what others won't" and an example of as much has a guy running out a bookstore to buy up all of the copies of a book with his own money to make them available when they were expected while the usual channel to facilitate as much had fallen through. Isn't that at the expense of his family? Why should I champion John as a leader?
  4. Who Moved My Cheese? by Spencer Johnson, M.D. was just given to me at my current workplace and this is the best of the four. It was just handed to me without a coordinated effort to get my feedback as was the case with Dale Carnegie's book, but this book is a really easy read. You could maybe read it in one sitting. That made it easy for me to just do the reading and hand it back in so that someone else could enjoy it. Unlike John's book or, for that matter, Dale's book, this book isn't vaguely about improving oneself in a greater sense and instead focuses on something in particular, dealing with change. The lessons are that you should ask yourself how you would behave if you were not afraid and also that you should be able to laugh at yourself. The story inside is outright surreal which made it captivating. It seems like most authors have head trash telling them that analogies have to make sense, but as it turns out analogies can be wacky. You'll have to read it for yourself to see what I'm talking about. This gimmick makes the book really engaging. Supposedly the yellow brick road in the Wizard of Oz represents the 19th century gold standard. It's that sort of silly abstraction. Fun!

Sunday, February 7, 2016

SignalR in web forms?

Sure! It's not too hard. Just install these NuGet packages:

  1. Microsoft ASP.Net SignalR System.Web
  2. Microsoft ASP.Net SignalR JavaScript Client

 
 

These script tags need to adorn your .aspx markup where you want the magic to happen:

<script src="Scripts/jquery-1.6.4.js"></script>
<script src="Scripts/jquery.signalR-2.2.0.js"></script>

 
 

Beyond that it is really just like this MVC example. I did hit one painpoint, but it should happen with MVC too honestly. In an IIS application, where \ is not the root of the site but one folder up from that, the setting in the OWIN Startup class should stay the same, but the setting in jQuery where one actually makes the connection needs to be adjusted. At...

var conn = $.connection("/author");

 
 

...one is literally trying to find something at /author and that won't work in an IIS application. Use a full path here as a best practice.

nopCommerce

It'a an open-source & free e-commerce solution written in C# and MVC.

The tilde of web forms is now the tilde of MVC!

As of MVC4? This has the following example:

<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

DAMP stands for “descriptive and meaningful phrases"

...per this and in contrast with the Don't Repeat Yourself (DRY) unit tests, DAMP tests are going to have common code across many tests just copied test to test to make the tests easy to read. The TestInitialize stuff of the C# space could be skipped.

Saturday, February 6, 2016

Why do the emails I send from C# have double periods in them, sabotaging URLs?

This explains what is happening with System.Net.Mail and offers that the solution lies in this setting:

using (var email = new MailMessage(foo, bar, baz, qux))
{
      email.BodyEncoding = System.Text.Encoding.UTF8;
      email.IsBodyHtml = true;
      mySmtpClient.Send(email);
}

I saw Sean McComb speak on regular expressions at SQL Saturday.

In SSMS if you just press Ctrl-F in the midst of typing SQL you will get a dialog box for the finding and if you expand the "Find options" you will see an option for using regular expressions. It's in a dropdown wherein you may either select regular expressions or wildcards to augment your searching. As T-SQL is not case sensitive neither is the regular expression searching which surprised me. What if you want to find against copy being inserted into a table cell enclosed in quotes where casing means something more. I suppose that is a fringe case. The rightward pointing arrow by the "Find what:" field will give you a helpful cheat sheet of RegEx pattern parts to use. A period represents any character so if you search against just . you will progress through every character in your SQL. A carat signifies the beginning of a line and a dollar sign the end of a line so searching for ^. will progressively find the beginning of every line (first character) which holds more than nothing while searching for .$ will progressively find the ends. You have to escape special characters if you actually want to search for the special characters as characters so \. will allow you to search for a period. * will match against zero or more characters and + will match against one or more characters. These modifiers apply to the pattern part immediately to their left so SE+ will find an S followed by one or more Es and the Es too while SE* is also just gonna find all of the Ss. I could go on. This is all pretty much what you'd expect from regular expressions, right?

Friday, February 5, 2016

Ctrl-A is a Windowsland select all!

Use it to select all of the copy in a database cell in SSMS.

Allow your VMWare VMs to see (ping) your main machine.

Use this trick. Get rid of that "NAT" setting. It will help to run ipconfig /flushdns at your main machine and ipconfig /registerdns at the VM. At "Server Manager" in Windows Server 2012 R2 click "Tools" and pick "Windows Firewall with Advanced Security" and then at the dialog box which appears right-click on "Windows Firewall with Advanced Security on Local Computer" and pick "Properties" to turn the firewall off.

Let just about everything but angle brackets through at an asp:RegularExpressionValidator at the C# side.

string quote = "\"";
MyControl.ValidationExpression = @"([a-z]*[A-Z]*[0-9]*[\.]*[\s]*[\']*[?]*[!]*[-]*[=]*[\*]*[:]*[;]*
      [,]*[\\]*[/]*[{]*[}]*[|]*[\[]*[\]]*[\(]*[\)]*[+]*[`]*[~]*[@]*[_]*[#]*[\$]*[%]*[\^]*[&]*[\" + quote +
      "]*)*";

Thursday, February 4, 2016

SmtpException

You may try to catch this exception in lieu of just the Exception type exception in C# when try-wrapping mechanics that use System.Net.Mail to send emails.

Wednesday, February 3, 2016

placeholder="whatever"

This is an inline tag setting for an input in modern HTML. It is a better way to do a watermark effect. This has some mechanics for throwing in some CSS with a placeholder. Meh.

Use a asp:RegularExpressionValidator in web forms to keep users from passing in the angle brackets.

The regular expression here allows, letters, numbers, spaces, apostrophes, hyphens, periods, question marks, and exclamation marks:

<asp:RegularExpressionValidator ID="EmailTemplateRegularExpressionValidator"
      runat="server" ControlToValidate="EmailTemplate" Display="Dynamic"
      ErrorMessage="Please enter standard characters."
      ValidationExpression="([a-z]*[A-Z]*[0-9]*[\.]*[\s]*[\']*[?]*[!]*[-]*)*">
</asp:RegularExpressionValidator>

remove all angle brackets from a string in JavaScript and not just the first ones as is that problem with .replace

$('.emailTemplateHeader').each(function () {
   var value = $(this).val();
   value = value.split("<").join("");
   value = value.split(">").join("");
   $(this).val(value);
});

YNAB or You Need A Budget

...is a moblie app for micromanaging your spending.

asp:Panel magic

Did you know that if you wrap things in an asp:Panel in a web form that you may then dictate which button click gets emulated when a user submits the form by way of pressing enter while in one of the fields within that panel? Nice. The "DefaultButton" inline setting in the markup gets the id of the button to click as its setting and that button doesn't even have to be inside of the panel itself!

Tuesday, February 2, 2016

Cron Maker

It's simple junk software for punching the clock.

How do I force a refresh of an iFrame in web forms?

Change instead a asp:HiddenField! You then need a jQuery middleman like so?

function listenForIFrameRefresh() {
   var listener = function() {
      var backingstorewrapper = $(".emailTrigger")[0];
      var backingstore = $(backingstorewrapper).children()[0];
      if ($(backingstore).val()) {
         document.getElementById("refreshme").src = "IFrameForLogo.aspx?" +
               $(backingstore).val() + "=" + (new Date());
         $(backingstore).val("");
      }
   }
   var interval = setInterval(listener, 100);
}

cpp in the preprocessor for C and it stands for "C preprocessor"

You can jam in header files and macros with it.

StyleCop

This allows for yet more ReSharper suggestions for C#. It's a plugin on top of ReSharper and the link I provide here suggests it is dated as it won't jive with Roslyn.

Monday, February 1, 2016

Set the html height to 100%; to accomodate old IE.

Have you ever tried to make something hang out midpage only to find it all smashed against the top in old versions of Internet Explorer? Me too. I had a table cell 100% tall and wide to cover the whole page and I was trying to put onto it styles like...

.whatever {
   vertical-align: middle;
   text-align: center;
}

 
 

...to kick into life this line effect which just wasn't working for some infuriating reason...

<td width="100%" height="100%" valign="middle" align="center">

 
 

...but of course the last place that is gonna work is in old IE. Something else was wrong. It turns out that the fix looks like this:

html {
   height: 100%;
}