Skip to content

Commit

Permalink
Add all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
bpugh committed Nov 3, 2023
1 parent 39b6fb7 commit 0367f4b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 0 deletions.
19 changes: 19 additions & 0 deletions azure-devops/conditional-yaml.md
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
```
21 changes: 21 additions & 0 deletions csharp/string-extension-method.md
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))`
11 changes: 11 additions & 0 deletions devtools/toggle-css-classes.md
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).
Binary file added devtools/toggle-css-classes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions documentation/zeal.md
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.
6 changes: 6 additions & 0 deletions git/update-refs-working-directory.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ Andrew Lock has excellet write-ups on them:

* [Working on two git branches at once with git worktree](https://andrewlock.net/working-on-two-git-branches-at-once-with-git-worktree/)
* [Working with stacked branches in Git is easier with --update-refs](https://andrewlock.net/working-with-stacked-branches-in-git-is-easier-with-update-refs/)


Update:

Turns out this feature also added an `update-ref` command to interactive rebase.

13 changes: 13 additions & 0 deletions html/blob-url.md
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>`
27 changes: 27 additions & 0 deletions javascript/every-returns-true-empty-array.md
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?”
9 changes: 9 additions & 0 deletions visual-studio/copy-git-link.md
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.

0 comments on commit 0367f4b

Please sign in to comment.