Sunday, 13 March 2022

Video & Screenshot

Screenshot:

use scrot -s
 

Video screen record:
 * simplescreenrecorder

Trim / Compress video:

ffmpeg 

trim video: ffmpeg -i film.mkv  -to 01:46:58 -c:v copy -c:a copy output.mp4
compress video: ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.m

 

Tuesday, 9 November 2021

Thursday, 21 October 2021

Adding markers to google maps

Adding stuff to google maps

Demo code:

const coordinates = // array of lat, lng
const flightPath = new google.maps.Polyline({
path: coordinates,
geodesic: true,
strokeColor: '#73B9FF',
strokeOpacity: 1.0,
strokeWeight: 4,
icons: [{
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
},
offset: '100%'
}],
map: this.theMap,

Useful links

Google maps doc on custom symbols


Post on custom google maps markers


Doing lots of things on google maps

Flexbox & centering stuff



Flexbox 

  • Css to use:
    • display: flex;

  • Vertical align bottom:
    • align-items: flex-end;

  • Horizontal align middle:  
    •   justify-content: center;



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.

Oops:

  • 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]

REACT:

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

Flow

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:
 https://pgtune.leopard.in.ua/#/

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:
https://www.postgresql.org/docs/9.5/runtime-config-logging.html


log_lock_waits

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

log_statement(ddl)

* Logs statements changing the DB

log_min_duration_statement

* 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/fabfile.py | grep '\[' | tail -1 | cut -f 2 -d  "'")
      echo "ssh: "$a       
      ssh $a".corp.hanson.as"
}

Sunday, 5 August 2018

*nix Directories

Root *nix Directories:

 Core:

/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.
/tmp
/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.

Other:

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

/usr/:

/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 s.id = er.student_id and s.name='andy'; 
This is what you wanted to do:
update Exam_Result set score = 99 FROM Student s WHERE s.id = Exam_Result.student_id and s.name='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;

Monday, 6 June 2016

javascript regex oddities.


Get a JS console and try this


/./.exec('a')
>["a"]

^ This regex '.' will match the single character 'a'.

Now try with a complex unicode char like an emoji:

/./.exec('😂')
> ["�"]

The JS regex matches half of the unicode character. 

What is interesting is if you specify a 2 letter match JS finds the character:


/../.exec('😂')
>["😂"]

'😂'.length
>2

In other unrelated regex bugs: \w can not understand accents:

/\w/.exec('Ä')
> Null


Reading more about crazy Unicode in Javascript. Note that some accents can be displayed as letter followed by accent (2 characters) and that the same character can be letter_with_accent (1 character). Ofcourse if this happens the string length is different and they don't match.

People are upset about Python's handling of unicode too.

Saturday, 12 March 2016

Sunday, 5 August 2012

Web Server config notes

Apache & Keepalive
 - short version keepalive ON for static content CDN stuff. keepalive OFF for dynamic eg: python

Wednesday, 7 December 2011

Design

Interesting design talk

Font:
Use Verdana on websites.
At least 14pt size (12 for Verdana)

Paragraphs should not be wider than 60 characters.
line height 1.5 for paragraphs
line height 1.1 for headings

Concept: Try and keep everything to a multiple of 6.

Shadows must be soft. (and a little bluish)

Text color: Use a darker color of your background color.
If text is on a colored box make text the same color as the original background.

Thursday, 22 September 2011

Handy Sites for building Websites

Name availability & Launching:
List of sites to submit to
Name Check

User Feedback:
User Voice
Snap engage
#User Tracking
Olark
Refining your Design

Crowd Sourced User Feedback:
FiveSecondTest
Feedback Army
Concept Feedback
PickFu - Ask is A better than B ?

Is my Server up?
Pingdom  - pings you over HTTP
Blame Stella - good for server side computation time
Monitor us - pings you over HTTP

Page Speed:
Y Slow - The Classic!
Simulate huge concurrent load on your server

Metrics:
Kiss Metrics
Live Metrics - GoSquared
datadog - (server status too)

Stress Test:
Gatling
Siege

AB Testing:
Visual Website Optimizer

Building Mobile sites:
Sencha

Mocking:
Mocking Bird
Balsamiq

Launch Pages:
Launcheffectapp
My Beta List
UnBounce

Accounts:
Quickbooksonline
Xero

Payments:
braintreepayments


Cools JS widgits:
Fast JS test & dev
Slidedown notifications
Example of CSS3 rollovers
Twitter Bootstrap - HTML, CSS & JS components
Twitter Bootstrap Extensions
Better Twitter Bootstrap notifications
Pretty Selects and menus
Form Validation made easy
Data Visualizatino D3js 
wrapbootstrap - take bootstrap make prettier

Social Plugins
The widget with all social sites

Design Resources:
Crowd Spring
99 Designs

Graphics & Icons:
Fam Fam Fam - Free icons
Paid Icons and More Icons
Completely Free clipart
Social Buttons (FB & twitter)
More Icons
Font Awesome

CRM / Marketing :
Office Autopilot
Infusion Soft
Intercom/
Custora

Marketting Emails:
Mailchimp vs Campaign Monitor

Transactional Emails
MailGun - Email only
AWS email
Postmark
Sendgrid
Mandrill (from Mailchimp)

Deals:
http://www.startuppack.org/

And finally the best site for getting random small things done
Fiverr

Friday, 16 September 2011

Pre launch site

A simple WordPress "coming soon" theme to collect emails:

Launch Page

Friday, 22 July 2011

Git

A summary of things I need to do with Git and can never quite remember how:

Checkout a URL from Github:
git clone https://github.com/mattiaslinnap/citymapper-web
 
To pull a branch from someone else's github repo in to your local one:
 git pull [copy link from github] [branch name]
 git pull  git@github.com:adamcstephens/dust.git  their-branch-name

I made changes locally now I want to push them into a separate branch and then on to github

git checkout -b many_changes
git push origin many_changes


Everything has gone wrong. REVERT!

git reset --hard HEAD

Revert to remote head:

git reset --hard origin/master


Oops! - I commited to wrong branch - undo commits but keep the changes on my local area. more info

git reset --soft HEAD^

Master has gone to hell. My current branch should be master instead

git merge --strategy=ours master
git checkout master
git merge GOOD_BRANCH

Everything has gone wrong. AND I have a local commit to revert

git reset --hard ORIG_HEAD

Revert to last committed state:

git reset --hard


Revert to last committed state from TIME ago:

git reset --hard master@{"10 minutes ago"}   

Review unpushed commits and squash:

git rebase -i

Reverting local changes:

git checkout -- file

Go back in Time:

git log -3
git checkout TAG

OR:
git checkout master^ (go back 1 commit from master)
git checkout HEAD^^ (go back 2 commits from where i am now)
git checkout HEAD~3 (go back 3 commits from where i am now)


Search:

Search thru git logs on my commits only:

git log --all-match --grep=search_string --author=andy

Git logs with follow:

git log --follow

Search for component:

git log -p -S SEARCH_FOR optional_limit_by_dir


Complex multi revert pattern:
 git checkout -b temp
 git rebase -i

  # If we get a merge error then you need to remove more commits as some more modern ones depend on the ones removed
  git checkout master
  git checkout temp -- .   #checkout  branch into the directory '.'
  git commit -a


Some commit has introduced a bug somewhere - lets go find it:

Bisect

Pull code then review before release

git fetch
summary:
  git log HEAD..origin
giant diff:
  git log -p HEAD...origin
git merge origin


Standard GIT workflow:(create a myfeaturebranch from the master branch)

git checkout -b myfeature master

while(I have code):
    (code)
    
git pull --rebase origin master

final merge:

git checkout master
git merge myfeature  OR git merge --no-ff myfeature OR git merge --squash myfeature
git branch -d myfeature
git push origin master


NOTES: 
--no-ff = No Fast forward = Keep the fact I worked on a separate branch.
(default) = Fast Forward = Fast forward all changes in to the master. 
General Rule: Use --no-ff if you worked on something big and want the branch history.
--squash = Squash this local branch's commits into 1. Makes git logs easier to read
git pull --rebase origin master = remove local changes. Pull master. Re-apply your changes


REBASE ADVICE:
If you can rebase OFTEN do it. If there are many differences between master and your branch do a merge instead. Rebase is only for LOCAL branches not pushed ones.

REBASE WARN:
Do not rebase a public 'pushed' branch that someone else is using. EG: If you fork a github project your fork is publicly available so do not rebase this fork with the original master. Instead use git fetch, git merge


Delete remote branch
git push origin --delete 

Merging:
git mergetool

Funky review & merge tool:
gitk

Using my file or there file on conflict:

git checkout --ours filename.c
git checkout --theirs filename.c
git add filename.c
git commit -m "using theirs"


Oops! I commited to the wrong branch

How to rebase - This is like merging but better. It updates the origin (head) then applies each of your commits so you have no 'merges'.


More Git Help

I'm in git Merge Hell!

Great Git learning web game

Tool to simplify your git branching Git Flow