-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
date: 2023-10-16 | ||
--- | ||
|
||
# Conditional logic in pipelines YAML | ||
|
||
#til that you can have conditional expressions in Azure Pipelines YAML files: | ||
|
||
```yaml | ||
steps: | ||
- script: tool | ||
env: | ||
${{ if parameters.debug }}: | ||
TOOL_DEBUG: true | ||
TOOL_DEBUG_DIR: _dbg | ||
${{ else }}: | ||
TOOL_DEBUG: false | ||
TOOL_DEBUG_DIR: _dbg | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
date: 2023-10-19 | ||
--- | ||
|
||
# Calling an extension method on a null instance | ||
|
||
Today I learned that you can call an extension method on a null instance of the type. | ||
I had always assumed without thinking about it too hard, that the reason `string.IsNullOrEmpty` isn't defined as an extension method in the framework is because you would get `NullReferenceException`. | ||
|
||
But if we were to define an extension method like `public static bool IsNullOrEmpty(this string s)`, and call it like `if(s.IsNullOrEmpty())` | ||
this is just syntactic sugar for `if(StringExtensions.IsNullOrEmpty(s))` and therefore it's safe to call on a null instance. | ||
|
||
Apparently the argument against this is that it could be confusing or counterintuitive when looking at the code if you think it's an instance method. | ||
I personally fall on the side of adding convenient extension methods like this - if nothing else to add a `NotNullOrEmpty` method. | ||
|
||
To me I've always found it very easy to miss the `!` operator in a conditional and so avoiding those makes the condition much easier to read. | ||
|
||
I much perfer: | ||
`if(userName.NotNullOrEmpty)` | ||
over | ||
`if(!string.IsNullOrEmpty(userName))` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
date: 2023-10-13 | ||
--- | ||
|
||
# Toggle CSS classes in Devtools | ||
|
||
#til that the little `.cls` button in the Chrome devtools is a handy way to toggle classes on an element: | ||
|
||
![toggle class screenshot](toggle-css-classes.png) | ||
|
||
I imagine the trend of using utility classes was the main motivation for this feature (although apparently it's been there for a few years and I only just figured out what it was for). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
date: 2023-10-18 | ||
--- | ||
|
||
# Zeal offline documentation browser | ||
|
||
#til about a cool project called [Zeal](https://zealdocs.org/) that let's download and browse the documentation for a bunch of projects. I've always liked the idea being able to continue working even without internet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
date: 2023-11-02 | ||
--- | ||
|
||
# Blob URLs | ||
|
||
#til that in a web page, when you're working with Blob or File objects you can call `URL.createObjectURL()` to create a Blob URL that can be used as the source for anything that normally takes a URL like images or download links. | ||
|
||
It's also apparently a good alternative to base64 encoded Data-URIs especially when dealing with larger amounts of data since a base64 encoded file will be 33% larger than the raw binary. | ||
|
||
I was running into issues trying to embed a large PDF with the `<object>` element and instead of setting a massive base64 string as the data source, I was able to convert it to a blob and use a blob url so it ends up looking something like: | ||
|
||
`<object data="blob:https://localhost/d827ea99-9e80-496a-a8e0-e107b83080e9" type="application/pdf"></object>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
date: 2023-11-01 | ||
--- | ||
|
||
# `every()` returns true for an empty array | ||
|
||
#til that the javascript array method `.every()` will always return true for an empty array. | ||
|
||
``` js | ||
[].every((x) => x > 1); // true | ||
[].every(() => true); // true | ||
[].every(() => false); // true | ||
``` | ||
|
||
For me at least, this was a bit surprising and I realized I'd been thinking about this function works incorrectly. | ||
Your first thought might be that this is another one of javascript's quirks, but this is actually how most languages implement similar functions including Rust, Python, and C#: | ||
|
||
``` csharp | ||
result = new List<int>().All(x => x > 0); // true | ||
result = new List<int>().All(x => false); // true | ||
``` | ||
|
||
Apparently this is because of Math. Specifically, it's meant to behave the same as the "for all" quantifier in mathematics. | ||
|
||
[Nicholas Zakas has a good article](https://humanwhocodes.com/blog/2023/09/javascript-wtf-why-does-every-return-true-for-empty-array/#user-content-fn-10) that goes into more detail and this nice tip if you also found this behavior surprising: | ||
|
||
> Instead of reading every() as “does every item in this array match this condition?” read it as, “is there any item in this array that doesn’t match this condition?” |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
date: 2023-10-11 | ||
--- | ||
|
||
# Copy git link extension | ||
|
||
Today I learned about the [Copy Git Link](https://marketplace.visualstudio.com/items?itemName=EtienneBAUDOUX.CopyGitLink2022&ssr=false#overview) extension for Visual Studio which will give you the url of currently selected lines on your git hosting provider i.e azure devops or GitHub. | ||
|
||
Especially handy for quickly pointing a teammate to a particular part of the codebase. |