Skip to content

Commit

Permalink
March 2022 update
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsoderlund committed Mar 2, 2022
1 parent 02bf346 commit 5eb23ee
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 20 deletions.
16 changes: 11 additions & 5 deletions Development/Go.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ You define your `module my_app` in `go.mod`, then you can reference subfolders e

const earthsGravity = 9.80665

### Structs/Collections
### Structs/Collections/Interfaces

type album struct {
type Album struct {
ID string `json:"id"`
Title string `json:"title"`
Artist string `json:"artist"`
Expand All @@ -87,6 +87,13 @@ You define your `module my_app` in `go.mod`, then you can reference subfolders e
{ID: "3", Title: "Sarah Vaughan and Clifford Brown", Artist: "Sarah Vaughan", Price: 39.99},
}

type AlbumInterface interface {
ID string
Title string
Artist string
Price float64
}

### Private and public

privateFunction
Expand Down Expand Up @@ -132,7 +139,7 @@ https://gobyexample.com/command-line-flags

### HTTP server

package main
package main

import (
"fmt"
Expand All @@ -141,9 +148,8 @@ package main

func main() {
http.HandleFunc("/hello-world", func(w http.ResponseWriter, r *http.Request){
fmt.Fprintf(w, "Hello world")
fmt.Fprintf(w, "Hello world") // or: fmt.Fprint(w, myFunction())
})

http.ListenAndServe(":80", nil)
}

Expand Down
16 changes: 14 additions & 2 deletions Development/HTML/CSS.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ Code:
### Word wrap and whitespace

white-space: nowrap; /* never wrap */
white-space: pre-wrap; /* for 'code' */
white-space: break-spaces;
white-space: pre/pre-wrap; /* for 'code' */
word-wrap: break-word; /* break words that overflow their container */
word-break: break-all; /* breaks all words at the end of a line */
overflow-wrap: break-word;
Expand Down Expand Up @@ -970,10 +971,21 @@ Examples:
animation-delay: -2s;
}

## Children and Siblings

Children:

.parent > .child

Siblings on same level:

.first-sibling + .next-sibling

## Pseudo classes

input:not([type="radio"])
h1[data-testid="jest-test-product-name"]
button[data-testid]
button[data-testid="jest-test-product-name"]

:active
:any-link
Expand Down
2 changes: 2 additions & 0 deletions Development/HTML/HTML.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ input[type="radio"] {

## HTML5 Semantic Tags

https://www.w3schools.com/tags/

<main>
<nav>
<section>
Expand Down
13 changes: 8 additions & 5 deletions Development/JavaScript/JavaScript client.md
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,12 @@ http://www.w3schools.com/jsref/jsref_obj_array.asp
Use dayjs instead (smaller):

import dayjs from 'dayjs'
dayjs(myDate).format('YYYY-MM-DD')
dayjs().subtract(2, 'day').format('ddd, YYYY-MM-DD HH:mm:ss')

import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime)

dayjs(myDate).fromNow()
dayjs().subtract(2, 'day').format('ddd, YYYY-MM-DD HH:mm:ss')

Moment.js

Expand Down Expand Up @@ -1345,8 +1346,9 @@ sessionStorage vs localStorage: sessionStorage is cleared when the page session
item.replaceChild(newNode, container.childNodes[0])
container.removeChild(container.childNodes[0])

document.querySelectorAll('.my-class img').forEach(e => e.style.border = '1px solid red')
// Simple scraper:
document.querySelectorAll('h3').forEach(e => console.log(e.innerText))
document.querySelectorAll('.my-class img').forEach(e => e.style.border = '1px solid red')

function toggleClass (event, className) {
const { target } = event
Expand Down Expand Up @@ -1503,8 +1505,8 @@ Tip: event handlers on `document` for move/end:

const domain = await window.fetch(url).then(res => res.json()) // or res.text() for HTML

const userResponse = await window.fetch(`${API_URL}/api/users/${user}`)
const userJson = await userResponse.json() // or text(), arrayBuffer(), blob(), formData()
const userResponse = await window.fetch(userUrl)
const userJson = await userResponse.json() // or text(), blob(), arrayBuffer(), formData()

await window.fetch(`${config.appUrl}api/domains`, {
method: 'POST',
Expand Down Expand Up @@ -1870,6 +1872,7 @@ https://www.sitepoint.com/lodash-features-replace-es6/

// Optional chaining
const value = a?.[b]?.['myKey']?.c
(event) => handleInputChange?.(event)

// pick
const { a, c } = abcObject
Expand Down
6 changes: 5 additions & 1 deletion Development/JavaScript/React.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ https://reactjs.org/docs/hooks-overview.html

- `useMemo`: return value
- `useCallback`: return function
- `useEffect` + `useState`: if need async/await
- `useEffect` + `useState`: if need async/await:

const [stateValue, setStateValue] = useState()
const getStateValue = async () => setStateValue(await somethingAsync())
useEffect(() => getStateValue(), [])

#### useRef

Expand Down
33 changes: 28 additions & 5 deletions Development/JavaScript/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ Compile:
- tuple
- enum
- Array: `Array<string>` same as `string[]`. `let list: number[] = [1, 2, 3]`
- object: not number, string, boolean, bigint, symbol, null, or undefined.
- function: `() => void`
- object: see also `Record<string, string>`. Not number, string, boolean, bigint, symbol, null, or undefined.
- function: `(param: string) => void`
- symbol
- void
- any / unknown
- null / undefined
- never
- Date
- Combined: Human & Customer
- Or: string | null
- AND/Combined: Human & Customer
- OR: string | null

### enum

Expand Down Expand Up @@ -129,6 +129,26 @@ Function in interface:

## Patterns

### Combining types

interface RentalInputs extends ProductVariant, Customer, Rental {}
type RentalInputs = ProductVariant & Customer & Rental

interface RentalFieldsProps {
inputs: ProductVariant & Customer & Rental
}

### Partial/optional

export const AppContext = React.createContext<Partial<ContextProps>>({})

### Interface as Array

interface MyArrayInterface {
0: number,
1: (startValue: number) => void
}

### Cast with 'as'

const elementRef = useRef() as React.MutableRefObject<HTMLButtonElement>
Expand Down Expand Up @@ -186,7 +206,10 @@ With `type`-definition:
- component: React.FunctionComponent (alias React.FC)
- component return value: React.ReactElement
- element/children: React.ReactNode (not JSX.Element)
- event: React.SyntheticEvent, React.ChangeEvent: (event: React.SyntheticEvent) => void
- event:
- React.SyntheticEvent
- React.MouseEventHandler<HTMLImageElement>
- React.ChangeEvent: (event: React.SyntheticEvent) => void
- event.target: Element or HTMLInputElement

Custom HTMLElementEvent:
Expand Down
7 changes: 6 additions & 1 deletion Development/Regular Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ Domain from URL - https://regex101.com/r/MOIFTy/3

/^(?:https?:)?(?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/igm

Find all links EXCLUDING "screen:"
Find all links in an HTML file:

/(?:ht|f)tps?:\/\/[-a-zA-Z0-9.]+\.[a-zA-Z]{2,3}(\/[^"<]*)?/g

Find all HREF links – EXCLUDING "screen:"

/href="(.*?)"/g
/href="((?!screen:).+)"/g


Expand Down
19 changes: 18 additions & 1 deletion Operating Systems/Unix Linux Bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ List all except a pattern:

### Download a file

wget https://server.com/myfile
wget https://server.com/myfile.txt
curl -o myfile.txt https://server.com/myfile.txt

### Pretty file tree

Expand Down Expand Up @@ -612,3 +613,19 @@ Use `d *` to delete all.
#### launchd

https://www.launchd.info/

## Security

### SSH

Create:

ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh-keygen -t ed25519 -C "[email protected]"

NOTE: ssh-keygen will ask for a filename, so no risk of overwriting your old key.

Connect:

ssh -i keyfile target_machine
ssh -i ~/.ssh/filnamn
3 changes: 3 additions & 0 deletions Tools/Google Sheets and Excel.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ Random string

---------- DATE & TIME ----------

Format date as text:
=TEXT(D26+1, "YYYY-MM-DD")

=ROUND((NOW()-DATE(1970,1,1))*86400)
=ROUND((NOW()-DATE(1970,1,1))*86400000-7205600)

Expand Down

0 comments on commit 5eb23ee

Please sign in to comment.