Skip to content

Commit 49a0ea8

Browse files
committed
main
1 parent da5ed0c commit 49a0ea8

File tree

9 files changed

+114
-18
lines changed

9 files changed

+114
-18
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Make Nix Derivation
2+
3+
Making a nix derivation typically includes following steps.
4+
5+
1. **Choose a derivation function**: `pkgs` has some wrapper functions of `mkDerivation` for different frameworks. See:[Languages and Frameworks](https://nixos.org/manual/nixpkgs/stable/#chap-language-support)
6+
- `mkDerivation` is a wrapper of `derivation` function.
7+
2. **Find a source**: where the source code come from? github repo or tarball or any other available from url.
8+
- If the source is precompiled, should set a appropriate value for `meta.sourceProvenance`. See: [Source provenance](https://ryantm.github.io/nixpkgs/stdenv/meta/#sec-meta-sourceProvenance)
9+
3. **Choose a fetcher**: use a appropriate fetcher to download the source. See [Fetchers](https://nixos.org/manual/nixpkgs/unstable/#chap-pkgs-fetchers)
10+
4. **Generate lock file**: if you'd build from source, this might require a lock file so nix can download dependencies during build.
11+
- If the source is precompiled, this is probably not necessary.
12+
- Lock file is typically required when using a wrapper function of `mkDerivation` for certain framework.
13+
5.

docs/document/PowerShell/docs/Language/Array.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ Keyword operators has special functionalities on collections.
221221
> [!NOTE]
222222
> If current item for `-match` or `-notmatch` is not a string, Powershell evaluates it to string by certain strategy.
223223
224+
> [!TIP]
225+
> Match and replace is case-insensitive by default. Use `-cmatch`, `-cnotmatch`, `-creplace`, `-csplit` for **case-sensitive** scenarios.
226+
227+
## Deconstruction
228+
229+
```ps1
230+
$a, $b, $c = 1,2,3 # $a = 1, $b = 2, $c = 3
231+
$a, $b = 1,2,3 # $a = 1, $b = 3 This might not be expected # [!code warning]
232+
```
233+
234+
> [!WARNING]
235+
> You should only use deconstruction when **you need the first and the last item returned** or **you're pretty sure there's only two element will be returned**.
236+
224237
## Multi-Dim Array
225238

226239
You'll have to create Multi-Dim array from .NET type constructor only.

docs/document/PowerShell/docs/Language/Control Flow.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ cd ..; gci -rec -file; echo hello
7575

7676
In PowerShell 7, `&&` and `||` were introduced to do the same command chaining as bash does.
7777

78+
## Null-Conditional Operator <Badge type="info" text="PowerShell 7+" />
79+
80+
This feature is basically the same as in `C#` except a bracing `{}` is required around variable because `?` is valid as part of variable name.
81+
82+
```ps1
83+
$null.Bar() # exception raised # [!code error]
84+
${null}?.Bar() # ok
85+
86+
$null[0] # exception raised here # [!code error]
87+
${null}?[0] # ok
88+
89+
$null ?? 'I am not null'
90+
91+
$baz ??= 'I am new value'
92+
```
93+
94+
## Ternary Operator <Badge type="info" text="PowerShell 7+" />
95+
96+
No need to explain, same as in `C#`.
7897

7998
## Pattern Matching
8099

docs/document/PowerShell/docs/Language/String.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Use `$` to interpolate:
2121
```
2222

2323
> [!NOTE]
24-
> `$()` is being called **SubExpression Operator** in Powershell.
24+
> `$()` is being called **SubExpression Operator** in PowerShell.
2525
2626
## Verbatim String
2727

@@ -36,12 +36,12 @@ Can contains new lines and
3636
```
3737

3838
> [!NOTE]
39-
> Verbatim string does not allow interpolation in Powershell which differs from `C#`.
39+
> Verbatim string does not allow interpolation in PowerShell which differs from `C#`.
4040
4141
## Raw String
4242

4343
> [!NOTE]
44-
> Raw string is being called **Here String** in Powershell.
44+
> Raw string is being called **Here String** in PowerShell.
4545
4646
**Here String** typically allows string contents starting at the second line and truncates the last newline.
4747

@@ -93,7 +93,7 @@ Use double `'` to escape `'` in a verbatim string.
9393
9494
## Arithmetic with Numerics
9595

96-
Powershell will try to convert the string on the right operand to the same type as left operand.
96+
PowerShell will try to convert the string on the right operand to the same type as left operand.
9797
Exception will be raised if conversion failed.
9898

9999
```ps1
@@ -111,6 +111,15 @@ Exception will be raised if conversion failed.
111111

112112
## Match & Replace
113113

114+
PowerShell has two kinds of matching strategy for strings.
115+
- `-match` for regex matching.
116+
- `-like` for wildcard matching.
117+
118+
While `-replace` only supports regex.
119+
120+
> [!TIP]
121+
> Match and replace is case-insensitive by default. Use `-cmatch`, `-cnotmatch`, `-creplace`, `-csplit` for **case-sensitive** scenarios.
122+
114123
```ps1
115124
'Janet is a girl' -match 'Jane' # True
116125
'Janet is a girl' -replace '^Janet', 'Jane'

docs/document/PowerShell/docs/Object Manipulation/ForEach.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ If you do want a `$null` return, use `Out-Null` to swallow the value.
2525

2626
```ps1
2727
# doesn't make much sense though
28-
(gci | foreach { $_.Name | Out-Null }) -eq $null # True
28+
$null -eq (gci | foreach { $_.Name | Out-Null }) # True
2929
```
3030

31-
31+
> [!NOTE]
32+
> One exception is `ForEach-Object` can execute method by name.
33+
> You might expect delegate objects to be returned, but no, values of the method being executed will be returned.
34+
>```ps1
35+
>(1,2,3 | % GetType | select -first 1) -is [System.Type] # True
36+
>```
3237

docs/document/PowerShell/docs/Object Manipulation/Select.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Select
22

3-
## Overview
3+
`Select-Object` serves for multiple purposes for object transformation and picking from collection.
4+
5+
The following is a overview:
46

57
- Picking composed object by one or more properties with `-Property`.
68
- select properties reversely by `-ExcludeProperty`.

docs/document/PowerShell/docs/Object Manipulation/Where.md

Whitespace-only changes.

docs/document/PowerShell/docs/Terminology.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Powershell has its own terminologies besides other shells like bash.
44
It's a shell integrated with .NET, it's not a independent platform.
55

6-
- `cmdlet`: builtin utils inside powershell, implemented using other languages like `C#`.
6+
- `cmdlet`: precompiled .NET assemblies work for PowerShell, implemented using other languages typically in `C#`.
77
- `function`: a command implemented using powershell language itself.
88
- `application`: external executable.
99

docs/document/PowerShell/docs/Type System/Extended Type System.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
11
# Extended Type System
22

3-
Extended Type System(ETS) is for consistent experience with **some** `.NET` types when working with Powershell.
3+
Extended Type System(ETS) is for consistent experience with **some** `.NET` types when working with PowerShell.
44

5-
For this purpose, Powershell wraps the traget object as `PSObject` with two approaches:
5+
There's two approaches that PowerShell did for implementing the ETS.
66

7-
- Set the object to be wrapped as a meta object(similar to lua metatable)
8-
- Add extra members to the containing `PSObject` itself.
7+
- Intrinsic members for all objects.
8+
- Dynamic manipulation to members of an object.
9+
- Potentially wrap an object as `PSObject`.
10+
11+
## Intrinsic Members
12+
13+
There's two kinds of intrinsic members in PowerShell
14+
- Object views: the mapping of a certain object.
15+
- Property and methods: intrinsic properties and methods.
16+
17+
All objects in PowerShell have five **object views** members:
18+
19+
- `psobject`: a `MemberSet` containing reflection source of members.
20+
```ps1
21+
$foo = 'I am foo'
22+
[object]::ReferenceEquals($foo, $foo.psobject.BaseObject) # True
23+
```
24+
- `psbase`: a `MemberSet` containing members of the object being wrapped.
25+
```ps1
26+
$foo = 'I am foo'
27+
[object]::ReferenceEquals($foo.ToString, $foo.psbase.ToString) # True
28+
```
29+
- `psadapted`: a `MemberSet` containing adapted members added by ETS.
30+
- `psextended`: a `MemberSet` containing extended members **added at runtime**.
31+
- `pstypenames`: a `CodeProperty` equivalent to `psobject.TypeNames`. Returns a collection containing the type names of inheritance chain.
32+
```ps1
33+
$foo = 'I am foo'
34+
[object]::ReferenceEquals($foo.psobject.TypeNames, $foo.pstypenames) # True
35+
```
36+
37+
Intrinsic methods and properties are to mimic singular object and collection in a same form.
38+
- `Where`: a method for filtering or slicing by condition. See [Where](../Object Manipulation/Where.md)
39+
- `ForEach`: a method to perform iteration with certain logic or perform casting all items to target type. See [ForEach](../Object Manipulation/ForEach.md)
40+
- `Count`
41+
- `Length`
42+
43+
44+
> [!NOTE]
45+
>**Intrinsic members are not described as part of certain type definition, they're isolated from the object-oriented type system.**
46+
> Object views are visible to `Get-Member -Force` while intrinsic methods aren't.
947
1048
A common example would be `Process` type.
1149

@@ -16,18 +54,16 @@ A common example would be `Process` type.
1654
(gps | select -First 1) -is [System.Diagnostics.Process] # True
1755
```
1856

19-
The functionality of ETS achieved benifits:
57+
The functionality of ETS achieved benefits:
2058

21-
- Allow custom behaviours like formatting, sorting for your custom type or object.
59+
- Allow custom behaviors like formatting, sorting for your custom type or object.
2260
- Dynamic interpreting a `HashTable` to any `PSObject`
2361
- Accessibility to the underlying object.
2462
- Manipulation on extended members.
2563

26-
## What's `PSObject`
27-
2864
## ETS Members
2965

30-
To represent meta of ETS members, Powershell has an abstract class called `PSMemberInfo`, each concrete member info type is derived from it.
66+
To represent meta of ETS members, PowerShell has an abstract class called `PSMemberInfo`, each concrete member info type is derived from it.
3167

3268
```cs
3369
public abstract class PSMemberInfo { }
@@ -37,4 +73,3 @@ public abstract class PSMemberInfo { }
3773
The facts of ETS members:
3874
- each member has a type inherited from `PSMemberInfo`.
3975

40-
## PSObject

0 commit comments

Comments
 (0)