You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/_data/site.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
module.exports={
2
2
url: "https://rupertmckay.com",
3
3
title: "Rupert Foggo McKay",
4
-
description: "Rupert's website.",
4
+
description: "Technical blog exploring TypeScript, React, JavaScript, and computer science fundamentals. In-depth articles on software development, testing, and mathematical concepts.",
Copy file name to clipboardExpand all lines: src/blog/2021-05-23-generics-arent-as-scary-as-you-think/index.md
+29-28Lines changed: 29 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
---
2
2
title: Generics aren't as scary as you think
3
-
description: You already understand generics... you just don't know you do.
3
+
description: Learn TypeScript generics through familiar examples like Arrays and Promises. Discover how you're already using generics without realizing it.
4
4
date: 2021-05-23
5
5
layout: layouts/post.njk
6
6
---
7
+
7
8
I'll be demonstrating generics using TypeScript, but the core principles of generics are the same in any programming language.
8
9
9
10
## First things first
@@ -39,16 +40,16 @@ Now let's pretend `filter` didn't already exist, and we wanted to make our own f
39
40
40
41
```ts
41
42
function numberFilter(
42
-
array:Array<number>,
43
-
callback: (num:number) =>boolean
43
+
array:Array<number>,
44
+
callback: (num:number) =>boolean,
44
45
) {
45
-
const result:Array<number> = [];
46
-
for (const num ofarray) {
47
-
if (callback(num)) {
48
-
result.push(num);
49
-
}
50
-
}
51
-
returnresult;
46
+
const result:Array<number> = [];
47
+
for (const num ofarray) {
48
+
if (callback(num)) {
49
+
result.push(num);
50
+
}
51
+
}
52
+
returnresult;
52
53
}
53
54
54
55
const numbers = [1, 31, 12, 40];
@@ -64,16 +65,16 @@ To really prove this point, lets show what a custom string filter function might
Copy file name to clipboardExpand all lines: src/blog/2021-06-09-how-to-create-custom-hooks/index.md
+23-22Lines changed: 23 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
---
2
2
title: How to Create Custom Hooks
3
-
description: DRY component logic and separation of rendering from state management.
3
+
description: Master React custom hooks to encapsulate reusable functionality, keep components clean, and separate rendering from state management.
4
4
date: 2021-06-09
5
5
layout: layouts/post.njk
6
6
---
7
+
7
8
React hooks are a powerful tool for managing state in your React components. In this post I'll be demonstrating how we can compose existing React hooks to make custom hooks that encapsulate reusable functionality.
8
9
9
10
React's built-in hooks provide a great deal of power and flexibility, between `useState`, `useEffect` and `useCallback` we can cover very many use cases. But often times we'll find ourselves repeating a pattern of hooks over and over again, or maybe we'd simply prefer to pull out a custom hook to keep our component definitions short and expressive.
@@ -28,7 +29,7 @@ Here we have a `WelcomePage` component which makes a call to some utility method
28
29
29
30
```ts
30
31
const useOnMount = (callback: () =>void) => {
31
-
React.useEffect(callback, []);
32
+
React.useEffect(callback, []);
32
33
};
33
34
```
34
35
@@ -50,10 +51,10 @@ For simple pieces of boolean state we typically only want a way to read the curr
That test will pass! But how? It doesn't do anything, yet somehow it is still true that the mock was called with that argument. Well, just like mock implementations persist through the whole test file, so too does the mock's "memory" of when it has been called. To prevent this confusing behavior, we should clear the "memory" of mocks between tests:
247
248
248
249
```ts
249
250
beforeEach(() => {
250
-
jest.clearAllMocks();
251
+
jest.clearAllMocks();
251
252
});
252
253
```
253
254
@@ -356,8 +357,8 @@ But when we inevitably do want to test a component rendered within a context, I
Copy file name to clipboardExpand all lines: src/blog/2022-01-03-what-is-a-number/index.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
---
2
2
title: What is a number?
3
-
description: Rounding errors are inevitable.
3
+
description: Explore why JavaScript's 0.1 * 0.2 doesn't equal 0.02, understanding floating-point arithmetic and the fundamental limits of numeric representation.
4
4
date: 2022-01-03
5
5
layout: layouts/post.njk
6
6
---
7
+
7
8
TL;DR:
8
9
9
10
- No datatype will ever be able to represent all numeric values perfectly
@@ -129,16 +130,19 @@ We call the leading bits the "Mantissa" and the power of 2 the "Exponent".
129
130
To demonstrate this, consider the following numbers:
130
131
131
132
5 in binary is 101:
133
+
132
134
- Mantissa: 1.01
133
135
- Exponent: 10
134
136
135
137
> Note that the exponent is _also_ in binary so "10" here is not "ten" but rather "two".
136
138
137
139
9 in binary is 1001:
140
+
138
141
- Mantissa: 1.001
139
142
- Exponent: 11
140
143
141
144
7/32 in binary is 0.00111:
145
+
142
146
- Mantissa: 1.11
143
147
- Exponent: -11
144
148
@@ -149,10 +153,12 @@ This format has the advantage of being very flexible in accomodating both very l
149
153
First, we convert the numbers to their floating-point representations:
150
154
151
155
0.1 in binary is 0.00011001100...:
156
+
152
157
- Mantissa: 1.1001100...
153
158
- Exponent: -100
154
159
155
-
0.2 in binary is 0.0011001100...:
160
+
0.2 in binary is 0.0011001100...:
161
+
156
162
- Mantissa: 1.1001100...
157
163
- Exponent: -11
158
164
@@ -161,6 +167,7 @@ You might already see a problem, that our numeric representations have become an
161
167
Then to complete our computation, we multiply the mantissas together and combine the exponents, which leaves us with:
0 commit comments