2 months Ago

 

Final Sochi 2014 notes

Published by marco on in Sports

U.S. Olympic Hockey

 Patrick Kane has a sadOh my God, what an ass-kicking. Canada put on a clinic for America and then Finland did the same, with even more success.

Patrick Kane never showed up—he missed again and again and took horrible penalties. His face after his second penalty sums things up nicely for the U.S. (see left).

And the US didn’t even both covering the greatest Olympic goal-scorer ever, warming the hearts of 40+ year-old guys everywhere by letting Teemu score not once, but twice.

Continental Snowboarding

 Regular snowboarder – ready to go French snowboarder – ready to goI noticed the following during one of the boarder-cross races: almost everyone stood in the gate at the top with hands on the posts, ready to jump at the sound of the bell (picture at left). The French guy, though, was just leaning back, arm akimbo and relaxed (picture at right). All that was missing was a cigarette and a shot of espresso.

Do you see the difference? I think he won the qualifier race as well, but who really cares? He’d already won our hearts on style.

 

Podunk City, USA

Published by marco on in Fun

 Surprised cowWhen you grew up in the countryside, you tend to have to prove the extreme rurality of your origin to others who share a similarly bucolic provenance. Should I become embroiled in future such contests of micturial prowess and find myself in trouble, struggling to triumph against a backwoods foe prodigiously well-equipped with a backwoods background that threatens to overshadow my own, I will rest assured that I can break the glass in case of such an emergency to retrieve the following link to end the discussion.

Oh, you guys used to tip cows when you got drunk?

Wow, that’s crazy.

No, really.

Sexual misconduct with cows reported in Herkimer Co. (Herkimer Evening Telegram)

“They were caught on videotape after a local farmer set up a camera in his barn after noticing his cows all of a sudden appeared anxious and were not producing as usual.”

So the farmer filmed them filming themselves “hav[ing] sexual contact with several cows”? Will Ilion police be pressing charges against the farmer for producing bestiality porn as well?

 

LESS vs. SASS: Variable semantics

Published by root on in Programming

I’ve been using CSS since pretty much its inception. It’s powerful but quite low-level and lacks support for DRY. So, I switched to generating CSS with LESS a while back. This has gone quite well and I’ve been pretty happy with it.

Recently, I was converting some older, theme stylesheets for earthli. A theme stylesheet provides no structural CSS, mostly setting text, background and border colors to let users choose the basic color set. This is a perfect candidate for LESS.

So I constructed a common stylesheet that referenced LESS variables that I would define in the theme stylesheet. Very basically, it looks like this:

crimson.less

@body_color: #800;
@import "theme-base";

theme-base.less

body
{
  background-color: @body_color;
}

This is just about the most basic use of LESS that even an amateur user could possibly imagine. I’m keeping it simple because I’d like to illustrate a subtlety to variables in LESS that tripped me up at first—but for which I’m very thankful. I’ll give you a hint: LESS treats variables as a stylesheet would, whereas SASS treats them as one would expect in a programming language.

Let’s expand the theme-base.less file with some more default definitions. I’m going to define some other variables in terms of the body color so that themes don’t have to explicitly set all values. Instead, a theme can set a base value and let the base stylesheet calculate derived values. If a calculated value isn’t OK for a theme, the theme can set that value explicitly to override.

Let’s see an example before we continue.

theme-base.less

@title_color: darken(@body_color, 25%);
@border_color: @title_color;

body
{
  background-color: @body_color;
}

h2
{
  color: @title_color;
  border: 1px solid @border_color;
}

You’ll notice that I avoided setting a value for @body_color because I didn’t want to override the value set previously in the theme. But then wouldn’t it be impossible for the theme to override the values for @title_color and @border_color? We seem to have a problem here.[1]

I want to be able to set some values and just use defaults for everything that I don’t want to override. There is a construct in SASS called !default that does exactly this. It indicates that an assignment should only take place if the variable has not yet been assigned.[2] Searching around for an equivalent in LESS took me to this page, Add support for “default” variables (similar to !default in SASS) #1706 (GitHub). There users suggested various solutions and the original poster became ever more adamant—“Suffice it to say that we believe we need default variable setting as we’ve proposed here”—until a LESS developer waded in to state that it would be “a pointless feature in less”, which seemed harsh until an example showed that he was quite right.

The clue is further down in one of the answers:

“If users define overrides after then it works as if it had a default on it. [T]hat’s because even in the imported file it will take the last definition in the same way as css, even if defined after usage. (Emphasis added.)”

It was at this point that the lightbulb went on for me. I was thinking like a programmer where a file is processed top-down and variable values can vary depending on location in the source text. That the output of the following C# code is 12 should amaze no one.

var a = 1;
Console.Write(a);
a = 2;
Console.Write(a);
a = 3;

In fact, we would totally expect our IDE to indicate that the value in the final assignment is never used and can be removed. Using LESS variable semantics, though, where variables are global in scope[3] and assignment are treated as they are in CSS, we would get 33 as output. Why? Because the value of the variable a has the value 3 because that’s the last value assigned to it. That is, LESS has a cascading approach to variable assignment.

This is exactly as the developer from LESS said: stop fighting it and just let LESS do what it does best. Do you want default values? Define the defaults first, then define your override values. The overridden value will be used even when used for setting the value of another default value that you didn’t even override.

Now let’s go fix our stylesheet to use these terse semantics of LESS. Here’s a first cut at a setup that feels pretty right. I put the files in the order that you would read them so that you can see the overridden values and everything makes sense again.[4]

theme-variables.less

@body_color: white;
@title_color: darken(@body_color, 25%);
@border_color: @title_color;

crimson.less

@import "theme-variables";
@body_color: #800;
@import "theme-base";

theme-base.less

body
{
  background-color: @body_color;
}

h2
{
  color: @title_color;
  border: 1px solid @border_color;
}

You can see in the example above that the required variables are all declared, then overridden and then used. From what we learned above, we know that the value of @title_color in the file theme-variables.less will use a value of #800 for @body_color because that was the last value it was assigned.

We can do better though. The example above hasn’t quite embraced the power of LESS fully. Let’s try again.

theme-base.less

@body_color: white;
@title_color: darken(@body_color, 25%);
@border_color: @title_color;

body
{
  background-color: @body_color;
}

h2
{
  color: @title_color;
  border: 1px solid @border_color;
}

crimson.less

@import "theme-base";
@body_color: #800;

Boom! That’s all you have to do. Set up everything in your base stylesheet file. Define all variables and define them in terms of each other in as convoluted a manner as you like. The final value of each value is determined before any CSS is generated.

This final version also has the added advantage that a syntax-checking IDE like JetBrains WebStorm or PHPStorm will be able to provide perfect assistance and validity checking. That wasn’t true at all for any of the previous versions, where variable declarations were in different files.

Although I was seriously considering moving away from LESS and over to SASS—because at least they didn’t leave out such a basic feature, as I had thought crossly to myself—I’m quite happy to have learned this lesson and am more happy with LESS than ever.

[1] For those of you who already know how to fix this, stop smirking. I’m writing this post because it wasn’t intuitive for me—although now I see the utter elegance of it.
[2] I’d also seen the same concept in NAnt property tasks where you can use the now-deprecated overwrite=“false” directive. For the curious, now you’re supposed to use unless=“${property::exists(‘property-name’)}” instead, which is just hideous.
[3] There are exceptions, but “variables are global in LESS is a good rule of thumb”. One example is that if a parameter for a mixin has the same name as a globally assigned variable, the value within that mixin is taken from the parameter rather than the global.
[4] Seriously, LESS experts, stop smirking. I’m taking a long time to get there because a programmer’s intuitive understanding of how variables work is a hard habit to break. Almost there.
 

How to configure Visual Studio 2013 with licenses from a multi-pack

Published by marco on in Tips & Tricks

The following article was originally published on the Encodo blogs and is cross-published here.

If you’re only interesting in what we promised to show you in the title of the article, then you can jump to the tl;dr at the end.

Silver Partnership

Encodo is a member of the Microsoft Partner Program with a Silver Competency. We maintain this competency through a combination of the following:

  • A yearly fee
  • Registration of .NET products developed by Encodo (Punchclock and Quino in our case)
  • Customer endorsements for .NET products that Encodo has developed
  • Competency exams

This involves no small amount of work and means that the competency isn’t that easy to get. You can also use Microsoft competencies (e.g. MCSE) but we don’t have any of those (yet).

We’ve had this membership for a while in order to get partner benefits, which basically translates to having licenses for Microsoft software at our disposal in order to develop and test .NET software. This includes 10 licenses for all premium versions of Visual Studio, up to and including the latest and greatest.

The partner web site

In previous versions, we were able to go to the partner web site and, after a lot of effort, get license keys for our 10 licenses and distribute them among our developers.

I mention the effort only because the partner site(s) and page(s) and application(s) are so notoriously hard to navigate. Every year, Microsoft improves something on the site, generally to the style but not the usability. I pluralized the components above because it’s hard to tell how many different teams, applications and technologies are actually behind the site.[1]

 Internet Explorer 11 highly recommended

  • You have to log in with your official LiveID but some pages mysteriously don’t use the common login whereas others do use it and still others just log you out entirely, forcing you to log in again.
  • Some pages work in any browser whereas others highly recommend using Internet Explorer, some even recommending version 11. If you don’t use IE, you’ll always wonder whether the site failed to work because it’s so buggy or because your browser is not properly supported.
  • The downloads page includes Windows operating systems and server software of all kinds as well as productivity software like Office and Visio but mentions nothing about Visual Studio.

It’s basically always been a mess and still is a mess and our suspicion is that Microsoft deliberately makes it hard to redeem your licenses so that you’ll either (A) just purchase more licenses via a channel that actually delivers them or (B) call their for-fee hotline and spend a bunch of money waiting on hold before you get forwarded from one person to another until finally ending up with someone who can answer your question.

[1] You can confirm our impressions just by looking at the screenshots attached below.

The convoluted path to licenses

That question being, in case we’ve forgotten, “how can I please get your software to recognize the licenses that I purchased instead of threatening me that it will go dark in 90 days?”

The magical answer to that question is below.

First, what are we actually trying to accomplish? We have a multi-pack license and we want some way of letting our users/developers register products. In most cases, this still works as it always has: get a license key and enter it/register it with the local installation of the product (e.g. Office, Windows, etc.)

With Visual Studio 2013 (VS2013), things are slightly different. There are no multi-pack license keys anymore. Instead, users log in to their Visual Studio with a particular user. VS2013 checks that account for a license on the MSDN server and enables its functionality accordingly. If you have no license registered, then you get a 90-day trial license.

If the license is a multi-pack and the user accounts are individual…how does that work? Easy: just associate individual users with the partner account and assign them licenses. However, this all works via MSDN, so it’s not enough to just have a Windows Live account. That user must also be registered as an MSDN subscriber.

So, for each user, you’re going to have to do the following:

  1. Get them a Windows Live account if they don’t already have one
  2. Add that account ID to the partner account
  3. Enable that user to get premium benefits (this can take up to 72 hours; see below for more detail)
  4. Register that Windows Live account as an MSDN subscriber
  5. Enter your credentials into VS2013 or refresh your license

The solution (with screenshots)

Sounds easy, right?. Once you know what to do, it’s not so bad. But we had a lot of trouble discovering this process on our own. So here are the exact steps you need to take, with screenshots and hints to help you along.

  1. Log in with the Windows LiveID that corresponds to the account under which the Silver Membership is registered.
  2. Navigate to the account settings where you can see the list of members registered with your account.
  3. Add the email address of the user to that list of members[2]
  4. Make sure that the “Premium” box is checked at the end of the list[3]
  5. A six-character TechID will be generated for that user. The site claims that it can take up to 72 hours for this number to be ready for use on the MSDN site. Our experience was that it took considerably less time.
  6. Give that user their ID and have them register with MSDN to create a subscriber
    1. Get the Tech ID for your user from the steps above;
    2. Browse to the MSDN home page and click “Downloads”[4]
    3. Click “MSDN Subscriptions” in the sub-menu under “Downloads” (totally intuitive, right?)[5]
    4. Ignore the gigantic blue button enticing you to check out “Access benefits” and click “Register a subscription”[6]
    5. You’ll finally be on the page to “Activate your subscription”. Use the exact same address as registered with the partner account and enter your Tech ID.[7]
  7. Once the user has a subscriber, that user can log in to VS2013 from the registration dialog to enable that license[8]

Logging in has other benefits: you can store your VS2013 settings on the Live server and use them wherever you work with VS2013 and have logged in.

 

Olympic hockey; why choose?

Published by marco on in Sports

I shelled out CHF8.– for Zattoo for this month so that I can watch the Olympics on my own schedule. It’s pretty sweet, especially for hockey games.

 USA/Czech Republic & Canada/Latvia

Zattoo keeps a 7-day buffer for over 100 channels. You can actually watch for free, but you don’t get HD and you have to watch extra, Zattoo-specific commercials. The Olympics coverage is remarkably commercial-free, at least on the Swiss (Swiss-German, German, French and Italian) and Austrian channels. The German channels have more advertisements but mostly between events. They tend to prefer live coverage. BBC2 I’ve hardly watched at all because they show more interviews and adverts than sports.

What did I think of the hockey games? Latvia played with tremendous heart, proving once again that teamwork can be (almost) equal to loading up on raw NHL talent. Canada played hard but seemed to be thinking about the next match already.

In the US-Czech game, the US showed off a lot of talent but also benefited from more than its share of lucky bounces. They are to be credited with going at the net, but the 5 goals they got (on 25 shots) included a few ugly ones. The right team definitely moved on, though.

The Russians would have loved to have had half the luck of the Americans in their game against Finland. With 38 shots and only 1 goal, it was kind of a sad loss because they, perhaps even more than the US, play an absolutely lovely, balletic passing-style hockey with lots of speed and chances. They dominated the offensive zone for long minutes at a time—even at 5 on 5—but they just couldn’t score.

The story of the Olympics, at least over here in good ol’ Switzerland, is the Swiss women’s hockey team, who showed a tremendous will to deliver what I think is the only rally-win of this Olympics. That almost never happens to Swiss teams—rallying isn’t our thing. It was an exciting game with some decent (non-checking) hockey.