Monday, 23 March 2020

A load of React Notes from my time dabbling with React

Overview of core:

this.state = stuff you can change
this.props = constants that come from the hierarchy.

Build / Flow locally:

  • yarn flow src

Lost / Where is that function from:

look for: conectRedux at the bottom of the file. - go to the class mentioned there.
Generally go to the bottom of the react file.


  • Dont use alert use window.sendError
  • Link tag: use 'to' not 'a'
  • Every list li ul element needs a key property key={uuid} NOT key="{uuid}"
  • Use button not a if it is a button.
  • Don't use Maps just use raw Objects instead:
  • If no state in a react component just use an arrow function.
  • Make react handle the loading case instead of blindly defaulting to empty list:
    • if (!teamsFetch || teamsFetch.pending) return <Loading />
    • if (teamsFetch.rejected) return <Error />
    • const rawTeams = (teamsFetch && teamsFetch.fulfilled && teamsFetch.value) || []
  • Use useMemo:
    • const memoisedValue = React.useMemo(() => doHeavyComputation(a, b), [a, b])
    • Must go before any returns. 
  • Don't modify this.props - instead call onChange and have the parent update it.  [...this.props.mylist, new_element]


Tests yarn add --dev jest
  • yarn jest
  • Jest test design: We don't tend to test the API is hit. Normally test the modals are called.

JS yarn prettify

yarn prettier --write find src | egrep jsx\\\\?$ --exclude passfort-types | grep -v passfort-types


Ignore JS Flow check add this on line before:

  • // $FlowFixMe
  • {/* $FlowFixMe */}

Friday, 7 December 2018

Recovering disk space

If these aren't good enough:
  •  df -kh
  •  du -d 1 -h 
  •  ncdu
  •  dust

Look for deleted nodes that haven't been reclaimed yet (restart to recover space):

  •  lsof | grep '(deleted)'

Monday, 29 October 2018

Tuning PG

Our upgrade to Postgresql 10 went badly due to parallel queries. If Postgres 10 performance sucks then try turning off parallel queries.

This site generates a tuned pg config for you based on your system:

Attempt to configure your Wall-E database backs so they back up on a a time frequency not size frequency by tuning:  max_wal_size

PG Logging:

Things you really should turn on for your PG logs:


* This is useful in determining if lock waits are causing poor performance.


* Logs statements changing the DB


* Causes the duration of each completed statement to be logged if the statement ran for at least the specified number of milliseconds.  

Monday, 20 August 2018

Neat shell script functions

Greps through a file to find a single line of data containing a server name and then ssh's to it
function goto() {             
      a=$(grep -B 20 "$1" /home/andy/dev/hanson/crane/ | grep '\[' | tail -1 | cut -f 2 -d  "'")
      echo "ssh: "$a       
      ssh $a""

Sunday, 5 August 2018

*nix Directories

Root *nix Directories:


/bin - compiled ready to run programs
/dev - Devices files (disks)
/etc - System configuration files
/home - Personal directories
/lib -  Library - hold library files used by executables. (note: /usr/lib also exists)
/proc - System stats, information about running processes.
/sys - Similar to proc (TODO: Update)
/sbin - System executables. Users should NOT have /sbin in their PATH.
/usr - Not user files! File layout is similar to '/'. Historic, meant to minimise space for root user.
/var - 'Variables' Programs record runtime info. System logging, caches, user tracking etc.


/boot - kernal boot loader
/media - Removable drives
/opt - Third party software, often not used.


/usr/ - The same as above
/usr/include - Header files for C compiler
/usr/info - GNU manuals
/usr/local - For admins to install stuff here
/usr/man - man pages
/usr/share - historical from the days of low disk space

Basic Command Notes

 Refresher on Shell IO:

' > ' Is write stdout and clobber
' >> ' Is append stdout
' | ' Is stdout -> stdin
'2> ' Is write stderr
'ls badtext > out 2>&1' Redirecting stderr to the same file as stdout.

Wednesday, 28 June 2017

SQL trouble

Some SQL trouble.

This SQL doesn't do what you might think. It will update all entries in Exam_Result not just andy's exams
update Exam_Result set score = 99 FROM Student s, Exam_Result er WHERE = er.student_id and'andy'; 
This is what you wanted to do:
update Exam_Result set score = 99 FROM Student s WHERE = Exam_Result.student_id and'andy';

And this is how to fix it from a DB backup via CSV after it has gone wrong:

\copy Exam_Result (exam_id, student_id, score) to out.csv CSV;
create table fix(exam_id int, student_id int, score int);
\copy fix from out.csv CSV;
update Exam_Result set score = f.score FROM fix f where f.exam_id=Exam_Result.exam_id and f.student_id=Exam_Result.student_id;