Pages about StackOverflow

Signing in to Azure Artifacts using npm on Mac

Microsoft Azure Artifacts uses your email address for logging in. If you are on Linux or a Mac, that can make it difficult to sign in to its npm registry using npm-login or npm-adduser. Here I show you how to configure your .npmrc file manually to avoid the problem.

Allowing "at" characters in npm usernames

Some npm registries use email addresses for usernames. That is incompatible with the npm commandline tools, like npm-login and npm-adduser. I found out how to configure the .npmrc file manually to avoid the problem.

Kafka Unrecognized option PrintGCDateStamps

There is a bug in the Java version detection mechanism in Kafka, that prevents you from running Kafka on newer versions of Java. There is a quick way to fix it, while the issue is being resolved.

Using Source Maps with CSS

When CSS or JavaScript is minified, there is a mechanism called Source Maps that can help you inspect the original code directly in the browser. Sometimes it requires some extra configuration.

Converting from Type to SqlDbType

The .NET type system and SQL Server types are not very easy to map to each other. In SQL, variables don't just have a type, but can also have precision and maximum length, which is not possible to translate into simple .NET types. Here I show a naïve approach at translating from one type system to another.

Overriding console.log in JavaScript

JavaScript is a dynamic language, where even functions are just object variables, pointing to some runnable code. This makes it possible to replace default implementations with your own implementations. However, if you are not careful, it can lead to problems that are hard to debug.

JavaScript countdown using localStorage

Using localStorage, it's possible to implement a countdown clock in JavaScript that survives a reboot of the user's computer. However, it's not possible to know when the user clears their localStorage contents.

Formatting a truncated float in JavaScript

By combining multiplication, division, and Math.floor(), it is possible to truncate a floating point number to a chosen number of decimals in JavaScript. Here, I explain every step of the way, and show how it's done in a one-liner.

Control data alignment in C# struct

Using the StructLayout and FieldOffset attributes, it's possible to control detailed data alignment when transmitting data between .NET-base and C++/C-based or assembler software.

How to load jQuery programatically

Loading JavaScript dynamically, and knowing then the script is done loading, can be difficult. There are working solutions available, but it is also possible to write some code to solve the problem.

Check if string contains a character in C#

There are multiple ways of checking if a string contains a specific character in C#. There are methods built into the String class, and there are extension methods in System.Linq.

What is Device Pixel Ratio?

The device pixel ratio is the ratio between physical pixels and logical pixels on a high-resolution screen. Different devices report different values, including non-integer ones. You should use media queries to handle varying screen densities correctly.

How to add a custom header in HttpWebRequest

Adding a custom HTTP header to an HttpWebRequest object, targetting Windows Phone 7, is done through the Headers property. The good thing that it works for a lot of other .NET target platforms as well.