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.