Tuesday, June 30, 2015

You can't make a .bak file at SQL Server 2012 and expect to restore it in SQL Server 2008.

You could migrate from the existing database to an empty database with Red Gate SQL Data Compare however.

When you cannot ping into a new VMware VM...

try setting the "Network Adapter" setting for the VM at the left nav to "Bridged"

When adding a NOT NULL column to a database table...

...expect your app to break. The logic for doing inserts into such a table needs love.

When you cannot open a file share on the network from a VMware VM...

Try the following command line command:

net use \\abc123\whatever

 
 

Then, try again.

Turn off automatic updating of Windows.

Type "Update" at the Start Menu and then pick "Change Settings" at the left of the box which appears. This seemed applicable in Windows Server 2008 R2. I don't seem to have the actual administrative privileges to make the change however.

Monday, June 29, 2015

SQL Server blocked access to procedure 'dbo.sp_send_dbmail' of component 'Database Mail XPs' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Database Mail XPs' by using sp_configure. For more information about enabling 'Database Mail XPs', search for 'Database Mail XPs' in SQL Server Books Online.

To get around this goofy gremlin in SSMS, open the Object Explorer and expand "Management." You will see "Database Mail" inside and if you right-click upon it and pick "Configure Database Mail" you will be allowed to walk through a wizard to set up an email account. This has a more verbose explanation of the same thing.

console.log("foo", "bar", "baz", "qux");

Adding extra parameters to console.log in JavaScript will just ask it to log extra things. All of the things logged will appear horizontally on the same line sequentially as they were handed in with a single space between each item like so:

foo bar baz qux

ping /a 192.168.13.42

... the forward slash a will report back to you the name of the server if the server is successfully pinged. This works at the command prompt and in PowerShell.

ways to mess with a remote VM without remote desktop or Citrix or virtual private network or the like

  1. through a file share
  2. through vSphere
  3. the Event Viewer may connect to Event Viewers on other machines

Sunday, June 28, 2015

Built-in Functions in JavaScript

...are the canned bits of functionality like .toString() that you don't have to build out yourself. Almost none of these allow for explicit binding in a .call manner. I can't think of a single example.

 
 

Addendum 12/7/2018: .toString() in JavaScript is a lot like .ToString() in C#. It makes something else into a string.

Thursday, June 25, 2015

The trust relationship between the workstation and the primary domain failed.

When you get this error at a VMware VM (when you restore an old snapshot), you need to drop the association with the domain are remake it. For Windows Server 2008 R2:

  1. right-click on the "My Computer" equivalent and pick "Properties"
  2. click "Change Settings" at the center far right of the box which appears
  3. at the "Computer Name" tab of the set of tab which shows up next, click the "Change..." button
  4. you will see a radio button toggle for switching between Domain and Workgroup and you should switch to a bogus Workgroup, just making up a silly name for it
  5. enter a username and password for the domain when prompted for something
  6. restart
  7. go back to where you just were and switch back to the domain
  8. log in for real
  9. restart again

Do not bother with running "dsa.msc" from the start menu which opens the "Active Directory Users and Computers" tool. I found this in Googling but it didn't help.

Pass variables from a .bat file to .cmd file.

If the .bat file holds:

./ExecuteStuff.cmd Foo Bar

 
 

...and ExecuteStuff.cmd sits in the same folder and has this in it at some point:

set Baz=%1
set Qux=%2

 
 

...then Foo will get mapped to Baz and and Bar will get mapped to Qux!

Make a copy of a database in SSMS!

  1. Make a .bak file backup.
     
  2. Run this SQL referencing the file you just made:
    RESTORE FILELISTONLY FROM DISK = 'C:\Backups\Backup.bak'
     
  3. This will give you details about the .mdf (datastore), .ndf (secondary data), and .ldf (transaction log) files which need to be copied elsewhere.
     
  4. With that information do something like this:
    RESTORE DATABASE Foo_Rollback FROM DISK = 'C:\Backups\backup.bak' WITH MOVE 'Foo' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\test_rollback.mdf', MOVE 'Foo_History' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\test_rollback.ndf', MOVE 'Foo_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\test_rollback.ldf', STATS = 1
     

Above we copy Foo to Foo_Rollback. Not to do: When you right-click on a database in SSMS and then pick "Tasks" there will be a "Copy Database..." option beneath "Tasks" ...This will bring up the Copy Database Wizard which should do what you might think but I couldn't get it to work. You may see an error along the way saying "SQL Server Agent does not appear to be running on the destination server. If SQL Server Agent is not running on the destination server, Copy Database Wizard will not function properly. Do you want to continue?" and if so go into Services and manually start the SQL Server Agent.

Addendum 6/26/2015: The second step will return a LogicalName column in its recordset and this value should be used where I have Foo, Foo_History, and Foo_log in the fourth step.

Addendum 6/29/2015: The paths to files need to be unique paths to new files to be created upon the script running.

Addendum 7/1/2015: If you'll notice the piece of the paths above which read MSSQL11.MSSQLSERVER this piece gives away a version number. Version 11 is MSSQL Server 2012 while version 10 is MSSQL Server 2008.

how to use RedGate SQL Compare 11 to compare the difference between two database

  1. open the app and go through the wizard picking the two databases to compare
  2. you will get a comparison summary wherein you should click the checkboxes for all of the items which appear
  3. click the "Deployment Wizard..." button at the top nav
  4. at the "Deployment" pane which appears, keep the "Create a deployment script" option
  5. finish up the wizard... next, next, next
  6. you will end up with a SQL script that will do what it needs to to reshape the second database to be like the first and by default it should open up in SSMS

when DotNetNuke vaguely says: "An error has occurred."

Look in the EventLog table of the DotNetNuke database for the most recent details on what is going wrong like so:

SELECT LogTypeKey, LogProperties, LogCreateDate FROM EventLog ORDER BY LogCreateDate DESC

 
 

You will want to copy the XML contents of the LogProperties column out to Notepad++ and look at it. You should see some message as to what is going on in there. If you use the LogCreateDate column to look at the time you may notice that several entries happen back to back and in these cases the topmost entry may not be the most important. You may want to look down the list a bit, but just a bit. LogTypeKey denotes different categories of entries.

The Web Essentials way of doing LESS-to-CSS and minifying JavaScript is deprecated with Visual Studio 2015.

Gulp will be a part of the new way though I don't really understand it yet. When I saw this talk by Kyle Simpson he badmouthed Gulp and expressed frustration at how there may be assumptions that your folder structure is set up a particular way which end up causing Gulp's processes to break when you try to pull stuff down from Gulp. That certainly seems to be my experience too. The thing that really keeps me from learning anything dependeding on npm-based installation in my spare time is that the first step of the process, getting dependencies, always seems to go South for me leaving me a tangled half working starting point that I cannot go forward from. Maybe there is an assumption that I'm using a Mac instead of a PC which is not the case.

Addendum 7/22/2015: This is no longer true. An update to Web Essentials has arrived with the arrival of Visual Studio 2015 this week and it is revelant again!

Wednesday, June 24, 2015

When DotNetNuke suddenly starts acting like it is not yet installed...

...that most likely means it cannot see the database. This happened to me today when I reverted to a VM snapshot from months ago. I think this is because a password I have saved for my LAN user is no longer appropriate and up to date.

Did you know that you may bolt properties onto a function just like an object in JavaScript?

In this example notice has a property called message:

function notice(action) {
   notice.message = notice.message + " feels like " + action;
}
notice.message = "coding";
notice("fighting");
alert("if " + notice.message + " you are in the wrong profession");

 
 

When I saw this talk by Kyle Simpson he was giving out copies of books he authored, which was a surprise, and I came away from the talk with a copy of "this & OBJECT PROTOTYPES" which one of many books in his greater "You Don't Know JS" series. (JS being JavaScript, not jack shit.) I see an opportunity to comb through this book and put together little coding examples for myself not unlike I did for C# 4.0 in a Nutshell by Joseph and Ben Albahari.

The trick here comes up in the first chapter which tries to explain the this keyword and also talks about how you may do what I do above with lexical scoping. Inside the function you have to have notice.message and not just message or certainly not this.message as the later two will not fly. This way of the function explicitly referring to itself is kinda gross and counterintuitive and hence I have never thought to do this before. I like that message can be defined after the fact (i.e. after the function itself is defined) as anything can be monkey-patched in JavaScript. Er, maybe monkey-patched is the wrong term. That might refer to overpowering (replacing) one setting with another sidestepping any type safety or comparable restraints. We are instead bolting on a property, right? Oh, it's all so confusing. ;)

Tuesday, June 23, 2015

DataTables seems like a pretty good pagination control for jQuery.

You may use it in an ASP.NET MVC application by making a table and then having a foreach loop in your Razor markup to have a row for each object in your collection. DataTables cleans up what comes up to the browser from being a table with a thousand rows to being a paginated list complete with both sortable headers and First, Previous, Next, and Last buttons. Obviously this means bringing in all the records upfront in what could be a lot of HTML. At a glance I think there may also be some server-side paging capabilities, but I don't know firsthand. I helped a friend with DataTables last night and we removed the numbered buttons in the pagination control in favor of just having the First, Previous, Next, and Last buttons, but tweaking the setting defined here to be:

$(document).ready(function() {
   $('#example').dataTable( {
      "pagingType": "full"
   } );
} );

 
 

...in lieu of:

$(document).ready(function() {
   $('#example').dataTable( {
      "pagingType": "full_numbers"
   } );
} );

 
 

The other settings are "simple" and "simple_numbers" which it would seem are like their "full" and "full_numbers" cousins but without the First and Last buttons in both variations. We needed also to move the pagination control above the record rows from where it sat below by default and I didn't quickly see a canned way to do this in their paradigm so a CSS solution was needed. The controls sit in a div beneath the table of rows and both elements sit one after another inside of another div that wraps them. At first I tried to just move the grid of control upwards with absolute positioning and a negative top-margin, but when one went to the last page of the pagination and there were less records than the norm, this caused a problem and the pagination controls set too high up on the page. I'm not sure how my friend solved it, but I brainstormed an idea after the fact of setting both the table and the div of controls to float in absolute positioning and to just set a fixed height on the div wrapping them both to accommodate for the height of the table. I guess that wouldn't work if one was allowing for the changing of the pagination size. I wonder if my friend kept the pagination size control around or hid it with display:none. We hid the search box with display:none. Fun stuff.

sp_rename packs a lot of magic, but there are some things it can't do.

I worried that if I renamed a table in T-SQL that the keys for joins would get jacked up. It looks like sp_rename takes care of that problem under the hood as part of what it does, but there is another problem yet that does require manual clean up and consideration. Let me illustrate. In this silly example, a bridge table called Shores straddles Lands and Lakes:

CREATE TABLE Lands
(
   LandId int IDENTITY NOT NULL,
   Land varchar(50) NOT NULL
) ON [PRIMARY]
ALTER TABLE Lands ADD CONSTRAINT
   PK_LandId PRIMARY KEY CLUSTERED
   (
      LandId
   ) WITH (
      STATISTICS_NORECOMPUTE = OFF,
      IGNORE_DUP_KEY = OFF,
      ALLOW_ROW_LOCKS = ON,
      ALLOW_PAGE_LOCKS = ON
   ) ON [PRIMARY]
 
Insert INTO Lands (Land) VALUES ('Indiana')
Insert INTO Lands (Land) VALUES ('Michigan')
Insert INTO Lands (Land) VALUES ('Minnesota')
Insert INTO Lands (Land) VALUES ('New York')
Insert INTO Lands (Land) VALUES ('Ohio')
Insert INTO Lands (Land) VALUES ('Ontario')
Insert INTO Lands (Land) VALUES ('Pennsylvania')
Insert INTO Lands (Land) VALUES ('Wisconsin')
 
CREATE TABLE Lakes
(
   LakeId int IDENTITY NOT NULL,
   Lake varchar(50) NOT NULL
) ON [PRIMARY]
ALTER TABLE Lakes ADD CONSTRAINT
   PK_LakeId PRIMARY KEY CLUSTERED
   (
      LakeId
   ) WITH (
      STATISTICS_NORECOMPUTE = OFF,
      IGNORE_DUP_KEY = OFF,
      ALLOW_ROW_LOCKS = ON,
      ALLOW_PAGE_LOCKS = ON
   ) ON [PRIMARY]
 
Insert INTO Lakes (Lake) VALUES ('Erie')
Insert INTO Lakes (Lake) VALUES ('Huron')
Insert INTO Lakes (Lake) VALUES ('Michigan')
Insert INTO Lakes (Lake) VALUES ('Ontario')
Insert INTO Lakes (Lake) VALUES ('Superior')
 
CREATE TABLE Shores
(
   ShoreId int IDENTITY NOT NULL,
   LandId int NOT NULL,
   LakeId int NOT NULL
) ON [PRIMARY]
ALTER TABLE Shores ADD CONSTRAINT
   PK_ShoreId PRIMARY KEY CLUSTERED
   (
      ShoreId
   ) WITH (
      STATISTICS_NORECOMPUTE = OFF,
      IGNORE_DUP_KEY = OFF,
      ALLOW_ROW_LOCKS = ON,
      ALLOW_PAGE_LOCKS = ON
   ) ON [PRIMARY]
ALTER TABLE Shores ADD CONSTRAINT
   FK_LandId FOREIGN KEY
   (
      LandId
   ) REFERENCES Lands (
      LandId
   ) ON UPDATE NO ACTION ON DELETE NO ACTION
ALTER TABLE Shores ADD CONSTRAINT
   FK_LakeId FOREIGN KEY
   (
      LakeId
   ) REFERENCES Lakes (
      LakeId
   ) ON UPDATE NO ACTION ON DELETE NO ACTION

 
 

If we stick an entry into the Shores table with say 7 for LandId and 1 for LakeId that should represent the shore of Lake Erie at Erie, Pennsylvania. Get it? I know, it's silly. Anyways, what if we turn around and rename Lakes to GreatLakes like this?

EXEC sp_rename 'Lakes', 'GreatLakes';
EXEC sp_rename 'GreatLakes.LakeId', 'GreatLakeId', 'COLUMN'
EXEC sp_rename 'GreatLakes.Lake', 'GreatLake', 'COLUMN'

 
 

Well, if we try to add an entry it will work just fine as, again, the key wire-ups are not undermined. They are also not renamed however as the names for constraints are just kept in magic strings and could have been anything, without any imposed convention, to begin with. Observe:

 
 

What should be done? Drop and recreate all the tables, slurping data off to temporary tables first? No, of course not. You should just rename the restraints with sp_rename.

Check to see if a constraint exists in MSSQL.

The basic pattern for the check looks like this...

IF((SELECT COUNT(*) FROM Whatever) > 0)
   BEGIN
      PRINT 'It exists.'
   END
ELSE
   BEGIN
      PRINT 'It does not exist.'
   END

 
 

The select statement will vary from case to case however. Here is what is needed for four circumstances:

  1. foreign key constraint:
    SELECT COUNT(*) FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME = 'FK_Foo'
     
  2. primary key constraint:
    SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_NAME = 'PK_Foo'
     
  3. unique constraint:
    SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_NAME = 'UQ_Foo'
     
  4. default constraint:
    SELECT COUNT(*) FROM sys.columns AS c JOIN sys.default_constraints AS d ON c.column_id = d.parent_column_id WHERE d.name = 'DF_Foo'
     

The unique constraint is approached just like a primary key constraint, these are restraints on varchar columns and the like to make sure that no two items have the same name if names need to be unique. Default constraints are "special cases" for column defaults. This example, for example, shows auto-populating a Guid for a column that uses a Guid as an ID. If you look at the Object Explorer in SSMS and you look at a table in the Databases, the Constraints "folder" below the table will hold the default constraints and the other three types here will be kept in the Keys "folder." All four of the the constraints above may be renamed like this:

EXEC sp_rename 'this', 'that'

Renaming a stored procedure is just one more thing you may do with sp_rename in T-SQL!

If your sproc is named "Whatever" then...

IF OBJECT_ID(N'Whatever') IS NOT NULL
   BEGIN
      PRINT 'We are renaming Whatever.'
      EXEC sp_rename 'Whatever', 'SomethingElse'
   END
ELSE
   BEGIN
      PRINT 'Whatever does not exist and will not be renamed.'
   END
GO

Get rid of a constraint with MSSQL.

ALTER TABLE dbo.Whatever DROP CONSTRAINT FK_Whatever_Id

the classic MSSQL bridge table

For many-to-many joins...

---$ Create table dbo.MyBridge
IF OBJECT_ID(N'dbo.MyBridge') IS NULL
BEGIN
   PRINT 'Create table dbo.MyBridge'
   CREATE TABLE dbo.MyBridge
   (
      MyBridgeId int IDENTITY NOT NULL,
      NorthShoreId int NOT NULL,
      SouthShoreId int NOT NULL
   ) ON [PRIMARY]
   ALTER TABLE dbo.MyBridgeId ADD CONSTRAINT
      PK_MyBridgeId PRIMARY KEY CLUSTERED
      (
         MyBridgeIdId
      ) WITH (
         STATISTICS_NORECOMPUTE = OFF,
         IGNORE_DUP_KEY = OFF,
         ALLOW_ROW_LOCKS = ON,
         ALLOW_PAGE_LOCKS = ON
      ) ON [PRIMARY]
   ALTER TABLE dbo.MyBridgeId ADD CONSTRAINT
      FK_MyBridge_To_NewEngland FOREIGN KEY
      (
         NorthShoreId
      ) REFERENCES dbo.NewEngland (
         NewEnglandId
      ) ON UPDATE NO ACTION ON DELETE NO ACTION
   ALTER TABLE dbo.MyBridgeId ADD CONSTRAINT
      FK_MyBridgeId_To_Texas FOREIGN KEY
      (
         SouthShoreId
      ) REFERENCES dbo.Texas (
         TexasId
      ) ON UPDATE NO ACTION ON DELETE NO ACTION
END
GO

 
 

Addendum 5/7/2016: I am realizing that what is above is messed up but I'm just gonna let it be. It makes sense to me. ;)

Rename a column on a table in MSSQL.

EXEC sp_rename 'Bar.FooId', 'BarId', 'COLUMN'

...is the way to go. Note that we are again using the sp_rename sproc. In this example rename a column in the Bar table sort of assuming we just renamed the table itself to Bar from Foo just beforehand.

Monday, June 22, 2015

WebAssembly is to let you compile C and C++ to... JavaScript?!

This suggests as much. You know I've always done just fine in life knowing C# but not C nor C++ so when I see stuff that makes me think I need to know that old garbage... sigh. I guess there is always going to be something I don't know that will make me feel inadequate given my profession.

Friday, June 19, 2015

rename a table is MSSQL with the sp_rename sproc

EXEC sp_rename 'Foo', 'Bar';

... will rename the table named Foo to: "Bar"

delete a table in MSSQL

DROP TABLE Whatever

@echo OFF

...seems to commonly be the first line in a .bat file. echo commands following it will write the contents of their lines to the console, while echoing in general is otherwise more or less turned off by @echo off preventing every line in the .bat file from writing gunk out to the console (unless one is, yes, explictly echoing) and also hiding the command prompt.

Add search capabilities to a DevExpress GridView in web forms.

Per this, something like this...

<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" />

 
 

...should sit outside of the dx:ASPxGridView tag and something like this...

<SettingsSearchPanel CustomEditorID="ASPxTextBox1" />

 
 

...should sit within it! That seems to be it. There isn't a wireup needed on the C# side. It just works.

RedGate SQL Search

...is a search bar which will appear in SSMS and help you search for helpful things like what stored procedures touch a given table in MSSQL.

Thursday, June 18, 2015

how to edit styles in the Web folder in a DevExpress theme

CardView, Chart, Editors, GridView, HtmlEditors, PivotGrid, RichEdit, Scheduler, Spreadsheet, TreeList, Web, and XtraReports are the folders that seem to get made by default for a DevExpress theme (or perhaps just the copies made from the default theme). I notice that when I select a control to style at the left pane in the Theme Builder that sometimes there is a one-to-one correspondence with one of these folders (GridView to GridView for example) while the Web folder contains global stuff. Each folder has a styles.css in it which drives everything and really you can edit these files outside of the Theme Builder too. To edit Web's stuff inside the Theme Builder when it doesn't have a control to select, just select any control. All of the files that style that control will be given at a tab at the lower right pane and there should thus be a tab for styles.css in Web as that will be looped in too.... or at least it was for GridView. I'm kinda assuming that it, the Web styles.css, straddles everything.

grep with PowerShell!

Select-String -Path C:\Whatever\* -Pattern "foo"

...should crawl every file within the Whatever folder for foo and return a list of matches. This does not seem to crawl folders within the folder specified. Instead I am seeing errors wherein PowerShell seems to be trying to read a folder like a file and is failing.

 
 

Select-String -Path C:\Whatever\*.txt -Pattern "foo"

...should alternatively search just the .txt files and not throw up errors about how subfolders cannot be accessed. I'm not yet sure of how to grep across numerous folders.

Add a custom DevExpress theme with its goofy theme builder.

Here are the steps I took:

  1. I set up a fresh new VMware VM and I put Visual Studio 2013 on it.
     
  2. I downloaded DevExpress from here and installed it. This put a DEVEXPRESS menu within Visual Studio.
     
  3. I spun up a new DevExpress friendly ASP.NET MVC project (with C#) with:
    DEVEXPRESS > All Platforms > New Project...
     
  4. The default app that gets made which ties into that corny Northwind database has a GridView in it in a .cshtml partial which looks like this:
    @Html.DevExpress().GridView(
    settings =>
    {
       settings.Name = "GridView";
       settings.CallbackRouteValues = new { Controller = "Home",
             Action = "GridViewPartialView" };
       settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
       settings.SettingsPager.PageSize = 32;
       settings.Settings.VerticalScrollBarMode = ScrollBarMode.Visible;
       settings.Settings.VerticalScrollableHeight = 350;
       settings.ControlStyle.Paddings.Padding =
             System.Web.UI.WebControls.Unit.Pixel(0);
       settings.ControlStyle.Border.BorderWidth =
             System.Web.UI.WebControls.Unit.Pixel(0);
       settings.ControlStyle.BorderBottom.BorderWidth =
             System.Web.UI.WebControls.Unit.Pixel(1);
       settings.Columns.Add("ContactName");
       settings.Columns.Add("CompanyName");
       settings.Columns.Add("ContactTitle");
       settings.Columns.Add("City");
       settings.Columns.Add("Phone");
    }).Bind(Model).GetHtml()

     
  5. I then opened the theme builder from Visual Studio (even though it is a standalone application independent from Visual Studio and I may open it independently) with:
    DEVEXPRESS > ASP.NET Controls v15.1.3 > Run ASP.NET Theme Builder...
     
  6. I tweaked an existing theme into my own (you'll see CSS to edit) and saved it, giving it a name, and then I built an assembly with a different name yet, which got saved out to a .dll, with:
    DEVEXPRESS > All Platforms > New Project...
     
  7. Back in Visual Studio, I added a reference to the .dll.
     
  8. I founf the DevExpress blob of the Web.config file which looked like this:
    <devExpress>
       <themes enableThemesAssembly="true" styleSheetTheme="" theme="DevEx"
             customThemeAssemblies="" />
       <compression enableHtmlCompression="false"
             enableCallbackCompression="true" enableResourceCompression="true"
             enableResourceMerging="true" />
       <settings doctypeMode="Html5" rightToLeft="false"
             embedRequiredClientLibraries="true" ieCompatibilityVersion="edge" />
       <errors callbackErrorRedirectUrl="" />
    </devExpress>

     
  9. The settings for theme and customThemeAssemblies both needed to change. I filled in the two separate names I gave to both my theme and the assembly I rendered out from it to a .dll.
     
  10. I ran the application in Cassini and my theme was biasing things as expected.

Wednesday, June 17, 2015

SQL Server Management Studio 2014 is now more or less running atop the Visual Studio IDE.

I noticed folders for Visual Studio 2005, Visual Studio 2008, and Visual Studio 2010 in "My Documents" this morning and I thought I was going to have a nose bleed as I certainly had not installed Visual Studio 2005 or of any other shape. My superior explained that SSMS was to blame.

The "Active Scripting" radio button under the settings under the Security tab under Internet Options at the Tools menu is supposedly the key to letting IE used JavaScript.

This suggested it. It seemed to work in IE11 on Windows Server 2012 R2 Datacenter.

I saw Kyle Simpson give a talk on wrangling transpilation at Austin JavaScript last night.

This was quite different from the one other transpilation talk I've ever seen, and in some ways in conflict thematically. Kyle was quick to point out that transpilation is an invented word and that he felt academics don't take in serious as it can, yes, mean different things to different people. In collision with the other presentation I've seen he suggested that transpilation is not the act of how-do-I-make-sense-of-things-to-compile-them-as-a-compiler, as one is not casting down a level from a lofty language to a more rudimentary one (as he would define compiling) but instead one is casting from the lofty language to a different shape of the lofty language. In his example ES6 gets cast to ES5 in the name of developers writing in modern JavaScript while being able to render out JavaScript which will be capable of running in most modern browsers which really only support ES5. Babel was suggested to be the best tool for this, and it was suggested that, yes, this is something you should want to do. Just waiting ten years for all of the browsers to support ES6 is not the mature way to solve the problem. It is nearly time to now think of JavaScript are evergreen and versionless given... Babel. While traceur is another tool like Babel, Kyle suggested Babel is really the one player in its space to care about. Different browsers support different features in ES6, with Edge having to date the most support so far, and there is a way to test to see if your browser can hang, but it's NOT like this:

try {
   x = y => y;
   arrows = true;
}
catch (err) {
   arrows = false;
}

 
 

Uncaught SyntaxError: Unexpected token => ...will be shoved up to Google Chrome's console, in this scenario, if the arrow cannot be supported well before the try/catch ever is run because the arrow cannot be compiled, as, yes, browsers are compiling your JavaScript to understand them. The thing to do instead is:

try {
   new Function("x = y => y;");
   arrows = true;
}
catch (err) {
   arrows = false;
}

 
 

es6-shim was offered as a good tool for polyfills for the stuff which is not compatible. Ecma International is to bless ES6 with its approval tomorrow! It's on everyone. The let keyword beckons:

let obj = {
   foo(x) {
      this.x = x;
      setTimeout(() => console.log(this.x), this.x);
   }
};

Tuesday, June 16, 2015

either Outline or Preview will be the first item under the View menu in Adobe Illustrator

Selecting this option toggles the state between the two and lets you jump in and out of wireframe mode. This worked in the 2015.0.0 Release of version 19.0.0 (64-bit). I write of this because I accidentally went into that outline state and had to Google for how to get back out.

the painless modern way to read a flat file's copy to a bytes array in C#

byte[] bytes = File.ReadAllBytes(pathToFlatFile);
string[] pieces = ASCIIEncoding.ASCII.GetString(bytes).Split(",".ToCharArray());

Set the ToolTip for a DevExpress ASPxButton on the C# side.

MyButton.ToolTip = "Whatever";

 
 

This is a lot better than wiring up something on the jQuery side to set the title parameter inside of an html tag like so:

$('.dxb').live('mouseover', function () {
   var child = $(this)[0].children[0];
   var attribute = $(child).attr("saveddisabledstateitemcolor");
   if (attribute) {
      $(this).attr("title", $("#MyResourceBubblesUpHere").val());
   }
});

 
 

...especially so as that dxb class may change out from under you when you upgrade DevExpress. Even if the control wasn't a DevExpress control or even if it was, you can always just set an attribute for the title inline parameter too from C#.

If you do not click the "Update" link at the bottom of the "Host Settings" in a DotNetNuke application...

When you test a change to DotNetNuke's SMTP setting at the "Host Settings" page itself you will see positive results when you test with the "Test" link next to the fill-in-the-blank box for "SMTP Server and port:" which you will not see in your app beyond, and... it won't make any sense as to why. Duh!

I found a hack in modern Adobe Illustrator to get the Bezier curve handles to snap to grid points.

This worked in the 2015.0.0 Release of version 19.0.0 (64-bit):

  1. While snapping to the grid with "Snap to Grid" checked under the "View" menu just make a square with the rectangle tool such that all of the corners line up on grid intersections.
  2. Put one of the corners where you want a handle to snap to.
  3. With "Snap to Point" also on, drag the handle's end to the corner of the square!

Ghetto!

Slurp down YouTube movies as .mp4 files?

This is a little online tool for doing so. It seemed to work just fine.

Addendum 6/16/2015: This suggests http://www.clipconverter.cc/ as a comparable tool, and it allow you to specify a time to start and and a time to end within a bigger video clip in the name of just stealing a bit of the online content. It looks like I have to add a "Musix Search" plugin to try it out so I am going to procrastinate on trying this tool for now. I don't know if this is legit or not yet.

Monday, June 15, 2015

dealing with Request in MVC controllers

Request.UrlReferrer.OriginalString and Request.RawUrl are things which should be generally accessible in an ASP.NET MVC Controller yet blow up in unit testing. StackOverflow suggests there are ways to mock them with both MOQ and NSubstitute but I haven't tried either because we don't use MOQ where I work and the NSubstitute example looks more complicated than I had hoped. While I am writing of testing controllers I want to mention that this shows off how to test against a model a Controller hands back by getting an ActionResult casting it to a ViewResult and then casting .ViewData.Model off of that to your POCO's type. I wanted to write of it because I had to Google it this morning when I couldn't find an example at my own blog. As it turns out, I did have an example.

The title inline attribute inside most HTML tags will allow for the text inside to be displayed like a tooltip.

<div title="This is an x.">X</div>

...is an example, and by "like a tooltip" I mean upon mouseover. The alt setting on an img tag may work similarly but can also show up in the classic broken image box.

Visual Studio 2015!

The release candidates are here.

Sunday, June 14, 2015

Wow! What is vaporwave?

It's the new elevator music!

Addendum 6/16/2015: The Floral Shoppe YouTube movie is sort of the sterotypically example of vaporwave. This shows off how to make vaporwave, and yes, anyone can. It's alright to rip stuff off and play old 80's music slowly, etc. Roman busts seems to be a theme in the memes of the visuals that accompany the sounds in YouTube clips.

Addendum 6/20/2015: Now I've made some vaporwave. Here it is:

By the way, Ctrl-K in Adobe Premiere Pro CC will put a cut in a piece of media, breaking it in two.

What were you working on ten years ago?

If you want to rename a file in a FreeBSD environment you may move it to the same folder with a new name with: mv

Saturday, June 13, 2015

Vine a victim of no Net Neutrality?

Maybe so? I can't bring vine.co up on my laptop at home via the WiFi even though it comes up on my iPad via cellular service. This suggests it just being deemed expensive and thus choked off by CenturyLink which is here in Austin with me.

I can no longer see the photos on my iPhone when I plug it into my laptop like it’s a USB drive with that cord that powers the phone on one end and has a USB port on the other.

Instead, I just see an empty drive called "Internal Storage." This is all new as of the upgrade to iOS 8.1.3 (12B466). Wait, not true... I can see the photos if I go into the photos at the iPhone and answer yes to a question about whether I want to allow my computer to have access. Whew! I cannot however, not drag a drop photos into the folders of photos it seems. This seems to be a change up, I think. I've done some Googling as to how to use the iPhone like a USB drive but in everything I've seen I have to go into iTunes to make it happen and I don't even want to think about iTunes.

There are now two levels of zoom at your iPhone's pictures.

For iOS 8.1.3 (12B466) one may do the thing wherein one pinches the screen, only sort of unpinches the screen (moves the fingers apart), to zoom farther into a photo than one might if one just taps on a photo which is the old way to zoom. It didn't used to be this way. The unpinching would not hold when you took your fingers away. I'm new to noticing these things. I don't know how long this has been around. I took a big leap from one iOS to another recently.

Friday, June 12, 2015

transition-timing-function: cubic-bezier(0, 1, 0.5, 1);

This should warp the timing of a transition in CSS. Imagine a box one unit tall. A line runs from point 0,0 (horizontal,vertical) at the lower left to point 1,1 at the upper right. The end points may be warped by bezier curve handles not unlike those in Adobe Illustrator. This has a little GUI control letting you experiment with as much for example. As you move the endpoints the line bends and the line represents how an animation will behave during its duration. Will it move at a consistent speed the entire time? Will it start fast and end slow? etc. Read from left-to-right, a trend hoziontally in the bend means "slow down" and a trend vertically means "speed up." The four numbers in the CSS represent the position of the handle for the lower left end followed by the position of the handle for the upper right end.

Much of an accordion control may be written in CSS anymore, but it looks like you'll still need some JavaScript to grease the wheels.

Based on this I made this:

<!DOCTYPE html>
<html lang="en">
   <head>
      <style type="text/css" media="all">
         #accordion {
            background-color: #EECCFF;
            height: 200px;
            width: 200px;
            overflow-y: hidden;
            max-height: 200px;
            transition-property: all;
            transition-duration: .5s;
         }
         #accordion.closed {
            max-height: 0;
         }
      </style>
      <title>Whatever</title>
   </head>
   <body>
      <button onclick="act()">touch me</button>
      <div id="accordion">Hi there!</div>
      <script type="text/javascript">
         function act() {
            var accordion = document.getElementById('accordion');
            accordion.classList.toggle('closed');
         }
      </script>
   </body>
</html>

Export CSS from an Abode Photoshop text layer!

I am just learning today that one may right-click on a text layer in Adobe Photoshop and pick "Copy CSS" from the menu that appears and then turn around and paste into Notepad to get a CSS representation of the copy in the text layer! This may be a starting point of sorts for some of your CSS if you are building a web site from a Photoshop comp (comprehensive layout) or two, but I would not blindly use the CSS created. It is a little nasty. If you open Microsoft Word and make a table and type some stuff in it and then save it out to a .html file and finally turn around and look at the HTML generated in Notepad, you will notice that the stuff that was generated for you is markup you would never haven penned yourself. A lot of tags start out with a lower case o followed by a colon and a lot of corny classes like MsoNormal are tossed in there. The stuff one gets back from Photoshop for CSS is not a horrible as the HTML that comes out of Word, but... I make the comparison for a reason. Be wary of what you cough out. It's not pretty, not without some love on your part anyways.

If you copy and paste a file from one locale to another in Windowsland...

Obviously the "Date created" will be updated to the moment at hand in the new environment, but I was surprised to see that the "Date modified" does not similarly get updated. It will be maintained even though it is not really the file you are looking at that got modified at that date. Whatever. Right-click on a file and pick "Properties" and then go to the "Details" tab of the box which appears to see these settings in Windows 7. It's the same thing in Windows Server 2008 and Windows Server 2012.

The most interesting thing today is that someone has hacked my personal web site.

It is hosted at Network Solutions. Someone hid an HTML table at the base of the home page with this in it:

<a href="http://www.familylawassociates.ca/images/">Cheap Canada Goose 2014,Canada Goose Outlet Store</a>

 
 

Clicking the link takes one to http://www.domspec.ru/ where the process died. I think this is a gateway which routes different traffic to different places. If you Google http://www.domspec.ru/ the first link to it will take you to http://www.tedbakerdressessale4ou.com/ instead of nothing. I just spoke to Network Solutions and they said that they had to migrate the Windows hosting to Server 2008 from Server 2003 as Server 2003 had a loophole allowing people to push content up to web hosting accounts once Microsoft stopped supporting it. It sounded like a lot of people got hacked as I did.

Thursday, June 11, 2015

Serialization and encapsulation are not friends.

namespace ReverseEngineering.Core
{
   public class Cat
   {
      public int? NumberOfLegs { get; private set; }
      public int? NumberOfEyes { get; private set; }
      public int? NumberOfTails { get; private set; }
      
      public Cat(int? magicNumber=null)
      {
         if(magicNumber!=null) Magic(magicNumber);
      }
      
      private void Magic(int? magicNumber)
      {
         NumberOfLegs = magicNumber*4;
         NumberOfEyes = magicNumber*2;
         NumberOfTails = magicNumber*1;
      }
   }
}

 
 

When I try to serialize the above with this approach. I get...

  • InvalidOperationException was unhandled by user code
    • An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code
    • Additional information: ReverseEngineering.Core.Cat cannot be serialized because it does not have a parameterless constructor.

 
 

When I hack around this problem by just adding a harmless parameterless constructor (which adds no new functionality to the class) I get this...

  • InvalidOperationException was unhandled by user code
    • An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code
    • Additional information: Cannot deserialize type 'ReverseEngineering.Core.Cat' because it contains property 'NumberOfLegs' which has no public setter.

 
 

It's too bad my encapsulation can't be serialized because look at how awesome my encapsulation is! :P

Wednesday, June 10, 2015

ClientSideEvent-Click="Whatever"

...might be the way to do what is done here in DevExpress without nesting a ClientSideEvents tag inside the dx:ASPxButton tag. You would instead specify this setting as an inline parameter on the dx:ASPxButton tag.

Monday, June 8, 2015

KeyFieldName maybe needs to be specified at a DevExpress ASPxGridView first before doing things like setting a GroupIndex on a column.

We saw some interesting errors around this challenge at work today.

$9.99 per month Apple Music was announced today by Apple CEO Tim Cook.

This will rival Spotify, Pandora, and the like.

In writing an application that sends email notifications to a bunch of people you might want to send everyone a separate email instead of jamming them into one email together.

Sending emails is not like reading from a database where you want to avoid n+1 problems. You could be exposing too much by revealing to everyone on the email list who else is on the email list. Don't try to save resources by sending just one email.

the canned way to send an email with DotNetNuke from C#

DotNetNuke.Services.Mail.Mail.SendEmail(from, to, subject, body);

In this from, to, subject, body are all just strings for what you'd think they'd be for and DotNetNuke.Services.Mail. leading up to the second Mail are the namespace for the second Mail. This touches on where the SMTP settings are set.

sqlParameter in C#!

SqlParameter sqlParameter = new SqlParameter();
sqlParameter.SqlDbType = SqlDbType.Structured;
sqlParameter.Value = myDataTable;
sqlParameter.ParameterName = "Whatever";
sqlParameter.Direction = ParameterDirection.Input;
sqlParameter.IsNullable = false;

Sunday, June 7, 2015

a colspan and rowspan example

The table here has the following markup:

<table style="border-spacing: 0; padding: 0; margin: 0 0 30px 0; border: none;">
   <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-right:1px solid #FFFFFF;" colspan="2">Extinct?</td>
   </tr>
   <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF;">Yes</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-right:1px solid #FFFFFF;">No</td>
   </tr>
   <tr>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-bottom:1px solid #FFFFFF;" rowspan="2">Flying?</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF;">Yes</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF;"><a href="http://www.50birds.com/birds/extinct-birds-4.htm"
         target="_blank">Argentavis</a></td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-right:1px solid #FFFFFF;">Flamingo and Duck</td>
   </tr>
   <tr>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-bottom:1px solid #FFFFFF;">No</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-bottom:1px solid #FFFFFF;" nowrap>Dodo</td>
      <td style="padding: 10px; border-top:1px solid #FFFFFF; border-left:1px solid
         #FFFFFF; border-right:1px solid #FFFFFF; border-bottom:1px solid #FFFFFF;"
         nowrap>Ostrich and Emu</td>
   </tr>
</table>

Ubuntu

...is one variety of Linux (GUI and Unixesque) OS. I've never used it. Whatever.

Strategy???

I'm developing a theory that I don't really see the classic design patterns of "Head First Design Patterns" by Eric and Elizabeth Freeman (with Kathy Sierra and Bert Bates) so much in production code. The first pattern in the book is the Strategy pattern and its example is just awful and makes me want to not continue reading the book. In it a decoy duck is a type of a duck in child-to-parent inheritance and right away that smells bad. I recreated their decoy duck example with my own RubberDuck example in C# instead of Java. Let's talk through it and why I'm slow to both fall in love with the Strategy pattern and come up with excuses to use it everywhere. First of all, these three tests all pass in my example:

using FowlApp.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FowlApp.Tests
{
   [TestClass]
   public class RubberDuckTests
   {
      private RubberDuck _rubberDuck;
      
      [TestInitialize()]
      public void SetupTests()
      {
         _rubberDuck = new RubberDuck();
      }
      
      [TestMethod]
      public void RubberDuck_cannot_fly()
      {
         Assert.AreEqual(_rubberDuck.Fly(), "I can't fly.");
      }
      
      [TestMethod]
      public void RubberDuck_cannot_quack()
      {
         Assert.AreEqual(_rubberDuck.Quack(), "I can't quack.");
      }
      
      [TestMethod]
      public void RubberDuck_looks_rubbery()
      {
         Assert.AreEqual(_rubberDuck.Display(), "I look rubbery.");
      }
   }
}

 
 

Alright, let's say you have a variety of common things that merit a child-to-parent inheritance of some shape, and let's say that many of the children, but not all of them, have some common functionality. In the name of maintainability and not repeating oneself, it would be nice if the common code could be kept in one spot and there is no way to really tuck it into the parent without getting hacky as not every child has the common behavior. The Strategy pattern would have you keep a field for the common behavior as an interface. The Duck that RubberDuck inherits from has two such fields, one for flight and one for speech. It looks like this:

namespace FowlApp.Core
{
   public abstract class Duck
   {
      public IFlyBehavior FlyBehavior { get; set; }
      public IQuackBehavior QuackBehavior { get; set; }
      public abstract string Display();
      
      public string Fly()
      {
         return FlyBehavior.Fly();
      }
      
      public string Quack()
      {
         return QuackBehavior.Quack();
      }
   }
}

 
 

The "problem" with this, and the thing that is going to make it, in my opinion, esoteric and infrequent in occurrence as opposed to a use-it-daily staple of my tool belt is that you have to have two or more categorized concerns to merit using the pattern as otherwise the problem may simply be solved by inheritance. If we more generically imagine a pattern using Bird in lieu of more specifically Duck, and Ostrich, Emu, Flamingo, and, yes, Duck are types of Bird, we can handle a limited repetition of flight behavior in which Ostrich and Emu can't fly and Flamingo and Duck can by introducing two middlemen in the inheritance chain. FlightlessBird and FlyingBird could inherit from Bird and Ostrich and Emu could inherit from FlightlessBird while Flamingo and Duck inherit from FlyingBird. Problem solved!

namespace FowlApp.Core
{
   public interface IFlyBehavior
   {
      string Fly();
   }
}

 
 

I see the inheritance chain thing a lot in code I work upon, and not just in my current role, also in my three years of little jobs here and there before my current job. I've seen a variety of things in many Austin environments and I see Eric Evans-flavored call-things-what-they-are (in a ubiquitous language way) simple structures a lot more than the "design patterns." What I do not see is the Strategy solution. What would be a second category in our Bird example that would force this example into the Strategy Pattern shape? Perhaps if the bird is extinct or not? If the prior examples were examples of birds both flightless and flighty while not extinct then perhaps Dodo could be an example of an extinct flightless bird and, I dunno, AmericanBaldEagle could be an example of an extinct bird that could fly? I guess I'm getting ahead of myself a little with that example. At least these are all legitimate inheritances for Bird. Going back to the original Duck example, though, I don't know that IQuackBehavior merits differentiation that merits the Strategy thing. It really seems like a bad example making me wonder what a good example would look like.

namespace FowlApp.Core
{
   public interface IQuackBehavior
   {
      string Quack();
   }
}

 
 

The problem with this is that all ducks quack and the ones that don't quack which are jammed into this example are teaching us bad uses of inheritance. Here and here are examples from a "motivational calendar" on the SOLID principles and yes, if it looks like a duck, quacks like a duck, but needs batteries, you probably have the wrong abstraction. I don't know if this example is explicitly supposed to poke fun at the silly example in "Head First Design Patterns." It feels like it, huh? A rocket-powered model duck is even given in the book of an example of a duck which cannot quack, yet fly!

namespace FowlApp.Core
{
   public class NoFlyBehavior : IFlyBehavior
   {
      public string Fly()
      {
         return "I can't fly.";
      }
   }
}

 
 

This SOLID talk by Chris Weldon touched on how it is a Liskov bug to have inheritances overload the save method in a parent so that it did nothing, and the not flying, not quacking duck thing seems to smell the same way. They, the authors of "Head First Design Patterns," really had to club together a bad example to give us an example at all making me wonder what a good example even looks like. The crisscross of managed bags of somewhat common functionality could be thought of in a grid shape like so...

    Extinct?
    Yes No
Flying? Yes Argentavis Flamingo and Duck
No Dodo Ostrich and Emu

...or in a cube shape if there were three such concerns, and so on. It has to make sense though. Something else Chander Dhall mentioned in the talk detailed here, here, and here is that it a bunch of rockstars on a team acting like rockstars may be counterintuitive. A simple solution is probably better than a slick one. The tricks the Strategy and Decorator patterns bring in with inheritance are, well, tricks, and sort of fly in the face of what one might usually think of as inheritance. A non-quacking duck really doesn't make sense.

namespace FowlApp.Core
{
   public class NoQuackBehavior : IQuackBehavior
   {
      public string Quack()
      {
         return "I can't quack.";
      }
   }
}

 
 

When I started doing .NET in coming from a recent history of PHP, I found I had to learn some OOP like it or not. Even if I jammed everything I could into the code behind for a web form there was still a divide between a button click event and the event for loading a page so I had to understand methods. I think most of us have embraced OOP more and more, but only so much as our surroundings have pushed us to. We've all finally gotten on board with Onion Architecture and writing tests, but in just about everything I've bumped into it stops there. We don't stray wildly out into the crazy stuff because our peers are also not doing it. We do want to keep it somewhat simple so that our code is easy to read, and to that end we keep doing what we've done which is what everyone knows how to handle. If we are to dive deeper we need a good reason to do so and I'm not seeing one in some of the "common patterns."

namespace FowlApp.Core
{
   public class RubberDuck : Duck
   {
      public RubberDuck()
      {
         FlyBehavior = new NoFlyBehavior();
         QuackBehavior = new NoQuackBehavior();
      }
      
      public override string Display()
      {
         return "I look rubbery.";
      }
   }
}

Saturday, June 6, 2015

interesting

<link rel="stylesheet" id="coToolbarStyle" href="chrome-extension://nppllibpnmahfaklnpggkibhkapjkeob/toolbar/styles/placeholder.css" type="text/css">

...seems to be injected in Google Chrome at the head tag of my web site by way of either Norton Identity Safe or Norton Security Toolbar which are the two extensions I see active at: Hotdog menu > More tools > Extensions ...and I guess it is more likely the second of the two extensions given its name, huh? This injection goes away when I disable the extensions. A few references to .js files get slipped in too in this process. I guess it is harmless or even helpful instead of sinister so it's OK.

Thirty-three

I was 33 when this was taken. It was in Lampasas, Texas. I was married at the time and it was taken by my wife, Cézanné. This was on our patio in 2007 and I think in September. I didn't own that dog and I never finished that book. The photo was taken by a digital camera we had and a print or two was made at Lampasas' Wal-Mart. After my wife and I split she snail-mailed me this photo and another with some notes written on the back. It was both melancholy and an unexpected pleasant surprise all at once. I scanned the print to have a digital copy. I like the picture because it is in the moment and carries a good story.

Google Chrome will have a release which will, going forward, block autoplaying Flash movies that start talking to you while you try to read something else at a given site full of ads.

This is one of the threads I've seen on the subject.

Update numerous rows at once in MSSQL with an inner join to a DataTable handed in from C#!

In the "Object Explorer" beneath "Programmability" at your database, find "Types" and create a new entry in "User-Defined Table Types" like so:

USE [Whatever]
GO
CREATE TYPE [dbo].[YinYang] AS TABLE(
   [Yin] [INT] NOT NULL,
   [Yang] [INT] NOT NULL,
   PRIMARY KEY CLUSTERED
(
   [Yin] ASC,
   [Yang] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
GO

 
 

Use the type in a stored procedure like this:

ALTER PROCEDURE [dbo].[MarkQuizesAsCompleted]
(
   @Pairs YinYang READONLY
)
AS
UPDATE q
SET q.IsCompleted=1
FROM dbo.Quiz q
INNER JOIN @Pairs p
ON q.InstructorId = p.Yin AND q.StudentId = p.Yang
RETURN @@ERROR
GO

 
 

This will work! On the C# side, you need to make a DataTable in the same shape as the one specified in your new type. An example:

var yinYang = new DataTable();
yinYang.Columns.Add("Yin", typeof(int));
yinYang.Columns.Add("Yang", typeof(int));
 
var foo = yinYang.NewRow();
foo["Yin"] = 1002;
foo["Yang"] = 1;
yinYang.Rows.Add(foo);
 
var bar = yinYang.NewRow();
bar["Yin"] = 2;
bar["Yang"] = 13;
yinYang.Rows.Add(bar);
 
var baz = yinYang.NewRow();
baz["Yin"] = 2;
baz["Yang"] = 22;
yinYang.Rows.Add(baz);
 
var qux = yinYang.NewRow();
qux["Yin"] = 2;
qux["Yang"] = 42;
yinYang.Rows.Add(qux);

 
 

When it comes time to actually call the sproc, do it more or less as suggested here with the exception that this line of code...

sqlCommand.Parameters.Add("@Item", SqlDbType.VarChar).Value = newEntry;

 
 

...needs to be replaced with a different line of code to handle the DataTable. I recommend something like this:

sqlCommand.Parameters.Add("@Pairs", SqlDbType.Structured).Value = yinYang;

Aurelia!

I've been going through the Aurelia tutorial here and I have the following dirty notes:

  • Get the latest node.js here.
  • Confirm the version of node at the command prompt with:
    npm -v
  • Install Gulp for builds and jspm for getting client-side packages with:
    npm install -g gulp
    npm install -g jspm
  • The tutorial suggests starting with the skeleton-navigation! It also suggests downloading the zip file from here, getting the one folder inside to your PC, and then renaming it to be: navigation-app
  • The next step is to open Node, open the command prompt as an Administrator, navigate to navigation-app and run npm install at the command prompt to bring in devDependencies as speced in packages.json in the root of navigation-app into play (install 'em) and then jspm install -y to install the dependencies stuff in the jspm spec in packages.json. This cantankerous stuff is likely to just break. Mine did. For jspm I see an error message suggesting I download git from http://git-scm.com/downloads.
  • I tried to install http://git-scm.com/downloads selecting an option to allow for use at the command prompt. Afterwards, jspm install -y ran a little bit better and now I only see four console errors when I bring up the home page of the application.
  • jspm_packages/system.js is called out to on line 15 and it cannot be found! I tried to sidestep this by just making a new, empty file.
  • Uncaught ReferenceError: System is not defined ..shows up as an error in the other cases. The first of which is on the first line of config.js! Looks like I really need system.js! It looks like it loads ES6 modules. Can I get it at https://github.com/systemjs/systemjs? Maybe with npm install systemjs
  • \node_modules\systemjs\dist seems to contain system.js ...I'll copy it to jspm_packages ...still breaking trying to load bootstrapper though I am past the hurdle from a moment ago... the error: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
  • This suggests that I need to set the app up as a web site and not run it from a file so I'll try that next I guess. (I know I'm talking to myself at this point in the notes.)
  • I'm past that problem, but now there are a bunch of other dependencies that system.js can't find.
  • I could try to manually download https://github.com/aurelia/logging and set it up.... it and many other things are missing from the dist folder. Maybe it's time to cool my jets at this point. Perhaps I should try to set all this up in another environment???

Friday, June 5, 2015

A GridViewDataColumn decorated with GroupIndex="0" at a DevExpress ASPxGridView cannot just be hidden by setting its visibility to false.

This won't fly:

MyGrid.Columns[0].Visible = false;

 
 

The fix is to remove the GroupIndex setting from the markup and manage it a the C# side. You will notice that .GroupIndex does not hang off of MyGrid.Columns[0] the way .Visible does so you will also have to do some casting to get the specific type of column in question like so:

GridViewDataColumn subset = (GridViewDataColumn)MyGrid.Columns[0];
if (_isToShowMoreThanOneSubsetOfSuperset)
{
   subset.GroupIndex = 0;
   subset.Visible = true;
}
else
{
   subset.GroupIndex = -1;
   subset.Visible = false;
}

Thursday, June 4, 2015

MSSQL's "nolock" standalone is deprecated in MSSQL and the full table hint of "with (nolock)" should be used instead.

This has the following examples of the two:

  1. select * from table1 as mytable (nolock)
  2. select * from table1 as mytable with(nolock)

If you want to rathole on data, yes, set partway through transactions, the second way above is better.

Make a GridViewDataColumn show some HTML and not just the Caption setting at a DevExpress ASPxGridView.

<dx:GridViewDataColumn FieldName="MerchantName" VisibleIndex="1">
   <GroupRowTemplate>
      <a href="Whatever.aspx"><%# Eval("MerchantName") %></a>
   </GroupRowTemplate>
</dx:GridViewDataColumn>

 
 

...or, if you need something smarter than a hyperlink...

<dx:GridViewDataColumn FieldName="MerchantName" VisibleIndex="1">
   <DataItemTemplate>
      <asp:LinkButton ID="MerchantLink" runat="server" CommandName="ViewMerchant"
            CausesValidation="false" Text='<%# Eval("MerchantName")%>'>
      </asp:LinkButton>
   </DataItemTemplate>
</dx:GridViewDataColumn>

 
 

For the later, you will need to wire up an event like so:

MyGrid.RowCommand += MyGrid_RowCommand;

 
 

...and then make it do stuff in C# like this:

void MyGrid_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e)
{

 
 

Note that the GroupIndex="0" setting will sabotage the DataItemTemplate stuff, keeping it from working.

Addendum 8/28/2015: You're going to need a tag like so...

<SettingsBehavior AutoExpandAllGroups="True"></SettingsBehavior>

 
 

...just inside the ASPxGridView tag and you will want GroupIndex="0" inside of the GridViewDataColumn tag in spite of what I say above.

GroupIndex="0"

...put inline in a dx:GridViewDataColumn at a dx:ASPxGridView will allow the column to sit as a row above the other columns and allow the other columns to be expandable/collapsible content. There may be more than one expandable/collapsible rows of columns in the DevExpress grid too as we are now "grouping by" the GroupIndex row. A negative one is the default value for this setting in lieu of the zero. By default, the rows of columns will be collasped. The way around this is with a DataBound event which you'd wire up like so:

Foo.DataBound += Foo_DataBound;

 
 

Make the event do this:

protected void Foo_DataBound(object sender, System.EventArgs e)
{
   ((ASPxGridView)sender).ExpandAll();
}

 
 

In contrast, this will open by default the DetailRows content in a ASPxGridView.

protected void Foo_DataBound(object sender, System.EventArgs e)
{
   ((ASPxGridView)sender).DetailRows.ExpandAllRows();
}

 
 

...er, wait. A better way to make the rows expanded may be at the web form side like this:

<SettingsBehavior AutoExpandAllGroups="True"></SettingsBehavior>

 
 

The other way comes with some wackiness in which if one collaspes a row the others all spring open. Boo.

An apartment contains one or more threads?

Apartment, as a term, seems to suggest a group for processes with x number of threads walled off to it. I remember seeing "Apartment" come up in a type name when writing WatiN tests and I thought it strange at the time. It came up in a conversation at work yesterday in another context and I suspected it corresponded to a greater concept. It does.

Wednesday, June 3, 2015

Make rows expandable in a DevExpress ASPxGridView to show further goodies.

  1. at the code behind this...
    Foo.DataSource = whatever;
    Foo.DataBind();

    ...needs to be changed up like so...
    Foo.DataSource = whatever;
    Foo.KeyFieldName = "KeyID";
    Foo.DataBind();
     
  2. at the web form this...
       </Columns>
    </dx:ASPxGridView>

    ...needs to be changed up like so...
       </Columns>
       <Templates>
          <DetailRow>
             <div>Whatever</div>
          </DetailRow>
       </Templates>
       <SettingsDetail IsDetailGrid="True" ShowDetailRow="True"
             AllowOnlyOneMasterRowExpanded="false" />
    </dx:ASPxGridView>
     

Alright, well, what if you want to put another ASPxGridView nested in your ASPxGridView where the word "Whatever" is above? First, you'd need to wire up an event for expanding the rows to reveal the content like so:

Foo.DetailRowExpandedChanged += Foo_DetailRowExpandedChanged;

 
 

Assuming before that MyChildGrid is the name of your child grid and that FirstId and SecondId are int values kept in columns in Foo (the parent grid) that you will need to query data for each row in Foo for populating MyChildGrid, you might do this:

void Foo_DetailRowExpandedChanged(object sender,
      ASPxGridViewDetailRowEventArgs e)
{
   if (e.Expanded)
   {
      object[] keys = (object[])Foo.GetRowValues(e.VisibleIndex, new string[] { "FirstId",
            "SecondId" });
      ASPxGridView child = Foo.FindDetailRowTemplateControl(e.VisibleIndex,
            "MyChildGrid") as ASPxGridView;
      child.DataSource = _whatever.GetWhatever(keys[0], keys[1]);
      child.DataBind();
   }
}

 
 

Addendum 12/7/2015: This will make it so only one detail row may be expanded at once.

MyGrid.SettingsDetail.AllowOnlyOneMasterRowExpanded = true;

Restore SSMS IntelliSense!

If you type... EXECUTE [dbo].[Your_Sproc_Name] ...and then press tab you should get some helpers for filling in the sprocs inbound values. The IntelliSense comes from a calculation made when SSMS is spun up and thus if you've added stuff since the spin up it may not be reflected in the IntelliSense. To jog a refresh in the IntelliSense, click Ctrl-Shift-R. This should do the trick UNLESS you are using Redgate SQL Prompt and then the hotkey is Ctrl-Shift-D instead and the other won't fly.

ReSharper will put a white blue squiggly line beneath a variable which has few back-to-back uppercase letters in it, breaking with Pascal case and camel case conventions.

But what if the CATS in your iLikeCATS variable is a legit acronym? Here's how to make ReSharper stop complaining:

  1. Click to put your cursor in the middle of iLikeCATS which should make a pryamid with one black side and one white side appear at the left of the line of code.
  2. Click the pryamid icon to expand a menu.
  3. Mouse over: Options for "Inconsistent Naming" inspection
  4. Mouse over: Add 'CATS' to the abbreviations list (save to: This computer).
  5. Click: Add 'CATS' to the abbreviations list (save to: Solution "Whatever" team-shared).

.delay in jQuery

...is kinda discussed here. An example given is:

$("#whatever").slideUp(300).delay(800).fadeIn(400);

.trigger(""click"); and .click(); are not really the same thing in jQuery.

This suggests that when you do this:

$("#whatever").trigger(""click");

 
 

...you are trying to get an .on event specified upstream in code like so:

$("#whatever").on("click", function() { alert('whatever'); });

 
 

...to fire off.

Grab a hold of an element by its name instead of its id with jQuery.

$("input[name='foo']").click();

The data source does not support server-side data paging.

I was getting this error at a DevExpress ASPxGridView. I got around it by removing this from being inline within the dx:ASPxGridView tag:

DataSourceForceStandardPaging="true"

 
 

Alternatively, this suggests this may rear its head when inappropriately hydrating a grid with IQueryable instead of IEnumerable.

Is there a better way to hide a caption at a GridViewDataColumn in a DevExpress ASPxGridView?

Caption="&nbsp;"

An empty string or a lack of a caption specification will fall over to using the FieldName setting as the caption setting.

Tuesday, June 2, 2015

Ben Burns/Ben Harris/Ben DeSilva/Ace

...was my best friend.

He died in 2011.

I thought I'd share some pictures.

And, yes, that's Felisha Storring with him.

When an object inherits from IHydratable given the DotNetDuke paradigm...

You have to implement KeyID as a getsetter for an int. This could use another field, public or private, for getting and setting if need be obviously. You will also have to implement the Fill method for mapping what comes back from a SELECT-flavored sproc to the POCO like this:

public void Fill(System.Data.IDataReader dataReader)
{
   KeyID = Convert.ToInt32(dataReader["FooId"]);
   SomethingMore = dataReader["Whatever"] as string;
}

Alt-Ctrl-Shift-8

...with ReSharper will supposedly toggle between enabling and disabling code analysis, but I don't see it affecting the "Enable code analysis" checkbox one sees at "Settings" beneath "Code Inspection" inside the "Options" dialog box for ReSharper 8.1.23.546 when I try it myself. Whatever. A four key hotkey is... something else. A decade ago I once went with Joel Holder to a meeting of the Perl Mongers which was a Perl users group for freaks who did cowboy coding in that convoluted crap and one of the guys mentioned a four key hotkey for doing something-er-other and dubbed it the Vulcan nerve pinch. Not off-base, you can tell that something is amiss when you are holding four keys for a hotkey. Something feels wrong, you know? I guess I can put on blinders and a smile and not care though as the hotkey doesn't work for me.

Monday, June 1, 2015

Revert to this revision

If you are looking at the history of just one file in TortoiseSVN and you right-click on a line item of history and pick "Revert to this revision" it will do what you'd expect. The change will not be in sync with everything else (well, unless it is the very latest item in the history) and thus you may turn around and commit the change to fall back to the way things were.

temporary Windows account locking (based on botched passwords) on a timer

Keep trying to log in until the timer runs its course and your account is unlocked. Your fails won't reset the timer. You don't need to tiptoe.

text-shadow is kinda like box-shadow, only for text

text-shadow: rgba(0, 0, 0, 0.5) 0 0 15px;

We have the offsets like box-shadow followed by a fatness. When a color is given as an rgba value in CSS3 the r stands for red, the g stands for green, the b stands for blue, and the a stands for... ALPHA! The alpha setting denotes how opaque or transparent the thing being colored is allowing it to be partially see-through.