Add to the last commit without changing its message (only if not pushed)
git rebase -i HEAD~3
Reorder, squash or reword the last three commits
git stash push -m "wip"
Put work aside with a name
git log --oneline --graph --decorate
Compact history as a graph
git restore --staged <file>
Remove a file from the staging area
git reflog
Find commits you thought were lost
git bisect start
Binary search for the commit that broke something
C# and LINQ
items.Where(x => x.Active)
Filter
items.Select(x => x.Name)
Project to something else
items.OrderBy(x => x.Date).ThenBy(x => x.Id)
Sort by several keys
items.GroupBy(x => x.Type)
Group into buckets
items.Any(x => x.Late)
Is there at least one match?
items.FirstOrDefault(x => x.Id == id)
First match or null
items.Chunk(100)
Split into batches of 100
a.Zip(b)
Pair two sequences item by item
$"{price:N2} {date:yyyy-MM-dd}"
Format numbers and dates in a string
EF Core
db.Items.AsNoTracking()
Faster reads when you will not save changes
query.Include(x => x.Lines)
Load related rows in the same query
query.AsSplitQuery()
Avoid huge joins with several collections
query.ExecuteUpdateAsync(s => s.SetProperty(x => x.Count, x => x.Count + 1))
Update in the database in one statement, safely under load
query.ExecuteDeleteAsync()
Delete rows in one statement without loading them
dotnet ef migrations add Name
Create a migration from model changes
dotnet ef database update
Apply pending migrations
SQL
SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY …
The order a query is written in
WITH x AS (SELECT …) SELECT … FROM x
Name a sub-query so the main one reads clearly
ROW_NUMBER() OVER (PARTITION BY a ORDER BY b)
Number rows within each group
WHERE EXISTS (SELECT 1 FROM t WHERE …)
Test for related rows, often faster than IN
COALESCE(a, b, 0)
First value that is not null
CASE WHEN a > 0 THEN 'y' ELSE 'n' END
If-then-else inside a query
Shell and tools
grep -rn "text" .
Search text in files, recursively, with line numbers
find . -name "*.log" -mtime +7
Find log files older than seven days
tar -czf out.tar.gz folder/
Pack a folder into a compressed archive
curl -i -X POST -d @body.json url
Send a POST with a JSON body and show the headers
Get-ChildItem -Recurse -Filter *.cs
PowerShell: list C# files recursively
netstat -ano | findstr :5000
Windows: which process uses port 5000
SQL joins
Join
Returns
INNER JOIN
Only rows with a match on both sides
LEFT JOIN
All rows from the left, matches from the right (or null)
RIGHT JOIN
All rows from the right, matches from the left (or null)
FULL JOIN
All rows from both, matched where possible
CROSS JOIN
Every row paired with every row
HTTP methods
Method
Safe
Idempotent
Typical use
GET
✓
✓
Read a resource
HEAD
✓
✓
Read only the headers
OPTIONS
✓
✓
Ask what is allowed
POST
✗
✗
Create something or start an action
PUT
✗
✓
Replace a resource completely
PATCH
✗
✗
Change part of a resource
DELETE
✗
✓
Remove a resource
Check the documentation for your version before relying on a flag or an API. Rebase and amend rewrite history, so only use them on commits you have not shared.