Saturday, 24 August 2019

Sat diary, cut lawn, laundry, recycling, . . .


Maeve heading out with friends
Daire in heading golfing later
No sign yet of Kate

Breakfast

No Saturday paper?

Cut very long grass(first day it has been dry for ages)
Hang clothes
Put on white wash
Empty dishwasher

Green bin was not collected :-( Panda :-( second fortnight in row not collected so emptied it, separated waste. Paper paper card paper paper card tins tetra plastic(next to paper in bulk), there was a puddle at the bottom.


Exercises, neck, shoulder, weights, push ips, stretches, . . Todo: plank! Yoga.

Catching up on family/scout messages. Counting scouts moving to vents/going to eurojam/registering.

Todo:
Lunch. Spuds
Test systems in work, several failed :-P
Recycling visit

Count scouts, scout money, send messages, new leaders training, . .  Scout county prep, . .

Bike chain?

Fix boots?

Orienteering or mountain bike or . . .





Friday, 23 August 2019

grepping for non-ascii chars . . grep from 0x80->0xFF doesn't find > 2 byte encoded chars unless set locale e.g. with LC_ALL=C


A cow-orker asked this old chestnut again.

Actually that problem ended up being a CR in between {} in a big .json file, not funny characters.

But along the way we found something confusing and learned that grep for chars from 0x80 to 0xff does show extended chars encoded in 2 bytes BUT weirdly NON intuitively it doesn't seem to match with extended chars encoded in 3 and 4 bytes.

 * © copyright c2a9 or   underscore c2a0 chars would match

 * ๐Ÿ’˜ Heart With Arrow Emoji - Emojipedia == UTF8? f09f9298  did not match

 * ใ‚ a in japanese hiragana  e38182 did not match

If you give the magical pre-invocation LC_ALL=C to the grep . . then it DOES match 2/3/4 byte extended characters.


This ANSWER updated goes into full explanation:


https://stackoverflow.com/questions/3001177/how-do-i-grep-for-all-non-ascii-characters/46343900#46343900

I agree with Harvey above buried in the comments, it is often more useful to search for non-printable characters OR it is easy to think non-ASCII when you really should be thinking non-printable. Harvey suggests "use this: "[^\n -~]". Add \r for DOS text files. That translates to "[^\x0A\x020-\x07E]" and add \x0D for CR"

Also, adding -c (show count of patterns matched) to grep is useful when searching for non-printable chars as the strings matched can mess up terminal.

I found adding range 0-8 and 0x0e-0x1f (to the 0x80-0xff range) is a useful pattern. This excludes the TAB, CR and LF and one or two more uncommon printable chars. So IMHO a quite a useful (albeit crude) grep pattern is THIS one:

grep -c -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" *

ACTUALLY, generally you will need to do this:

LC_ALL=C grep -c -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" *

breakdown:

LC_ALL=C - set locale to C, otherwise many extended chars will not match (even though they look like they are encoded > 0x80)
\x00-\x08 - non-printable control chars 0 - 7 decimal
\x0E-\x1F - more non-printable control chars 14 - 31 decimal
\x80-1xFF - non-printable chars > 128 decimal
-c - print count of matching lines instead of lines
-P - perl style regexps 
Instead of -c you may prefer to use -n (and optionally -b) or -l
-n, --line-number
-b, --byte-offset
-l, --files-with-matches

E.g. practical example of use find to grep all files under current directory:

LC_ALL=C find . -type f -exec grep -c -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" {} +

You may wish to adjust the grep at times. e.g. BS(0x08 - backspace) char used in some printable files or to exclude VT(0x0B - vertical tab). The BEL(0x07) and ESC(0x1B) chars can also be deemed printable in some cases.

Non-Printable ASCII Chars
** marks PRINTABLE but CONTROL chars that is useful to exclude sometimes

Dec   Hex Ctrl Char description           Dec Hex Ctrl Char description
0     00  ^@  NULL                        16  10  ^P  DATA LINK ESCAPE (DLE)
1     01  ^A  START OF HEADING (SOH)      17  11  ^Q  DEVICE CONTROL 1 (DC1)
2     02  ^B  START OF TEXT (STX)         18  12  ^R  DEVICE CONTROL 2 (DC2)
3     03  ^C  END OF TEXT (ETX)           19  13  ^S  DEVICE CONTROL 3 (DC3)
4     04  ^D  END OF TRANSMISSION (EOT)   20  14  ^T  DEVICE CONTROL 4 (DC4)
5     05  ^E  END OF QUERY (ENQ)          21  15  ^U  NEGATIVE ACKNOWLEDGEMENT (NAK)
6     06  ^F  ACKNOWLEDGE (ACK)           22  16  ^V  SYNCHRONIZE (SYN)
7     07  ^G  BEEP (BEL)                  23  17  ^W  END OF TRANSMISSION BLOCK (ETB)
8     08  ^H  BACKSPACE (BS)**            24  18  ^X  CANCEL (CAN)
9     09  ^I  HORIZONTAL TAB (HT)**       25  19  ^Y  END OF MEDIUM (EM)
10    0A  ^J  LINE FEED (LF)**            26  1A  ^Z  SUBSTITUTE (SUB)
11    0B  ^K  VERTICAL TAB (VT)**         27  1B  ^[  ESCAPE (ESC)
12    0C  ^L  FF (FORM FEED)**            28  1C  ^\  FILE SEPARATOR (FS) RIGHT ARROW
13    0D  ^M  CR (CARRIAGE RETURN)**      29  1D  ^]  GROUP SEPARATOR (GS) LEFT ARROW
14    0E  ^N  SO (SHIFT OUT)              30  1E  ^^  RECORD SEPARATOR (RS) UP ARROW
15    0F  ^O  SI (SHIFT IN)               31  1F  ^_  UNIT SEPARATOR (US) DOWN ARROW


UPDATE: I had to revisit this recently. And, YYMV depending on terminal settings/solar weather forecast BUT . . I noticed that grep was not finding many unicode or extended characters. Even though intuitively they should match the range 0x80 to 0xff, 3 and 4 byte unicode characters were not matched. ??? Can anyone explain this? YES. @frabjous asked and @calandoa explained that LC_ALL=C should be used to set locale for the command to make grep match.

e.g. my locale LC_ALL= empty

$ locale
LANG=en_IE.UTF-8
LC_CTYPE="en_IE.UTF-8"
.
.
LC_ALL=
grep with LC_ALL= empty matches 2 byte encoded chars but not 3 and 4 byte encoded:

$ grep -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" notes_unicode_emoji_test
5:© copyright c2a9
7:call  underscore c2a0
9:CTRL
31:5 © copyright
32:7 call  underscore
grep with LC_ALL=C does seem to match all extended characters that you would want:

$ LC_ALL=C grep --color='auto' -P -n "[\x80-\xFF]" notes_unicode_emoji_test
1:���� unicode dashes e28090
3:��� Heart With Arrow Emoji - Emojipedia == UTF8? f09f9298
5:� copyright c2a9
7:call� underscore c2a0
11:LIVE��E! ���������� ���� ���������� ���� �� �� ���� ����  YEOW, mix of japanese and chars from other e38182 e38184 . . e0a487
29:1 ���� unicode dashes
30:3 ��� Heart With Arrow Emoji - Emojipedia == UTF8 e28090
31:5 � copyright
32:7 call� underscore
33:11 LIVE��E! ���������� ���� ���������� ���� �� �� ���� ����  YEOW, mix of japanese and chars from other
34:52 LIVE��E! ���������� ���� ���������� ���� �� �� ���� ����  YEOW, mix of japanese and chars from other
81:LIVE��E! ���������� ���� ���������� ���� �� �� ���� ����  YEOW, mix of japanese and chars from other
THIS perl match (partially found elsewhere on stackoverflow) OR the inverse grep on the top answer DO seem to find ALL the ~weird~ and ~wonderful~ "non-ascii" characters without setting locale:

$ grep --color='auto' -P -n "[^\x00-\x7F]" notes_unicode_emoji_test
$ perl -ne 'print "$. $_" if m/[\x00-\x08\x0E-\x1F\x80-\xFF]/' notes_unicode_emoji_test
1 ‐‐ unicode dashes e28090
3 ๐Ÿ’˜ Heart With Arrow Emoji - Emojipedia == UTF8? f09f9298
5 © copyright c2a9
7 call  underscore c2a0
9 CTRL-H CHARS URK URK URK
11 LIVE‐E! ใ‚ใ„ใ†ใˆใŠ ใ‹ใŒ ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช ใ‚ซใ‚ฌ แšŠ แš‹ เธ‹เธŒ เค†เค‡  YEOW, mix of japanese and chars from other e38182 e38184 . . e0a487
29 1 ‐‐ unicode dashes
30 3 ๐Ÿ’˜ Heart With Arrow Emoji - Emojipedia == UTF8 e28090
31 5 © copyright
32 7 call  underscore
33 11 LIVE‐E! ใ‚ใ„ใ†ใˆใŠ ใ‹ใŒ ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช ใ‚ซใ‚ฌ แšŠ แš‹ เธ‹เธŒ เค†เค‡  YEOW, mix of japanese and chars from other
34 52 LIVE‐E! ใ‚ใ„ใ†ใˆใŠ ใ‹ใŒ ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช ใ‚ซใ‚ฌ แšŠ แš‹ เธ‹เธŒ เค†เค‡  YEOW, mix of japanese and chars from other
73 LIVE‐E! ใ‚ใ„ใ†ใˆใŠ ใ‹ใŒ ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช ใ‚ซใ‚ฌ แšŠ แš‹ เธ‹เธŒ เค†เค‡  YEOW, mix of japanese and chars from other
SO the preferred non-ascii char finders:

$ perl -ne 'print "$. $_" if m/[\x00-\x08\x0E-\x1F\x80-\xFF]/' notes_unicode_emoji_test

as in top answer, the inverse grep:

$ grep --color='auto' -P -n "[^\x00-\x7F]" notes_unicode_emoji_test

as in top answer but WITH LC_ALL=C:

$ LC_ALL=C grep --color='auto' -P -n "[\x80-\xFF]" notes_unicode_emoji_test

Wednesday, 14 August 2019

Shimano brake pads required adjusting with file !? and How to change hydraulic disc brake pads on bike

Shimano brake pads required adjusting with file !?
OOPS. Sorry Shimano. I put the pad sprint on the outside!
Lesson learnt: DIAGRAMS are good, even if you know have done the same procedure a few times before and think you know what you are doing!

My regular commuting bike rear brake felt a bit rough so brake pads probably worn. Need replacing.

I quite like replacing disc brake pads, it has sometimes been easy.

However the simple step of fitting the brake pads into the little brake pad holder did not work. The hole in the holder and pads could not line up. The hole for the pin in the pads was too far down OR the poinky bit of the pad too long. I guess tolerance in the brake pad manufacturing factory was exceeded.  SOLUTION: file down the top of the poinky bit of the brake pads until they fit in the holder.

I haven't had to do that before.

OOPS. DOH! Ehhhmm. The little pad spacer spring goes INSIDE the two brake pads!
Somewhat surprisingly the brake pads work fine with the spring on the outside.
Probably would wear weirdly though.


See also:
https://si.shimano.com/pdfs/dm/DM-BR0005-12-ENG.pdf


 A quick search online, . . I don't see other people with same problem.


Old school bike site . . is a little bit dated about disc brakes (cable levers, not hydraulic) and doesn't go into detail: https://www.sheldonbrown.com/disc-brakes.html


Good disc brake pad replacement instructions:

https://www.parktool.com/blog/repair-help/disc-brake-pad-removal-installation

https://www.bikeradar.com/advice/workshop/how-to-change-the-disc-brake-pads-on-your-bike/

https://www.merlincycles.com/blog/buyers-guide-to-disc-brake-pads/


My comprehensive general disc brake pad replacement instructions:

https://bicycles.stackexchange.com/questions/249/how-do-i-change-my-disc-brake-pads/63644#63644

The exact procedure varies a bit depending on the model of brake caliper/pads. Most disc brakes are now hydraulic. I have found that I have never had to so far let fluid out of or top up fluid in the hydraulic brakes! The procedure usually goes a bit like this:

TOOLS/INGREDIENTS:
latex gloves, cloth, old toothbrush, white spirits,
tyre remover tool, screwdriver, pliers(preferably needle nosed),
allen key/wrench as appropriate depending on wheel removal/caliper

0. Always allow a bit of time for complications. ESPECIALLY if you have not done that particular bike/part before.

1. Collect tools/parts. Gloves on. Remove wheel (OR some calipers you remove one bolt and the caliper rotates away from the rotor like a motorbike brake).

2. Clean brake caliper outside. Using toothbrush + white spirits + cloth. WARNING:  do not get dirty/oily fluid on rotor or braking surfaces!

3. OPTIONALLY: Use screwdriver to push brake pads apart as far as you can to each side (to push pistons back)

4. Pop out pin or whatever holds the brake pads in place.
   Remove pads from caliper.
   Inspect pads.
 
5. Clean inside of caliper.

6. Use plastic tool to push pistons back on each side.

7. Put new pads together with the pad spring in between them. Slide them into caliper. Push in pin or whatever holds them in place and lock.

8. Put wheel back on, gently . . make sure rotor goes in between the brake pads in the caliper.

9. Pull the brake a few times. The first few times it will be soft and go all the way but it should stiffen up as the piston is pushed out and starts pushing the pads against the rotor.

10. At this stage you are almost done, the rotor could have got something dripped or splashed on it so clean the rotor with a completely fresh cloth/kitchen towell. If the rotor has any contamination on it brakes might be noisy and not as effective as they should be.

11. Test cycle. Hopefully job is done brake working fine. If not . . then . . CONTINGENCY/debugging TIME . .

12. Tidy up.

12. Careful first few cycles out just in case . . .

Usually with disc brakes it is easy enough.
I think they are easier to change than rim brake pads.
But . . sometimes things get a bit tricky.
Extra notes in case of complications:

1. Yes, you do need to remove the wheel. This gives access to put in and out pads and to push the pistons back. Some types of pads could be replaced without removing the wheel, but only if you can also clean and get pistons back.

2. Yes, gloves and cleaning are good to use/do. Cleaning helps keeps you and tools/bike clean and in long term helps prevent parts getting seized and wearing.

3. Before removing the pads you can use them to push the pistons back. Insert a screwdriver or different tool between the brake pads and push them to the side. This ensures the piston is not damaged by directly pushing with screwdriver.

I did once encounter a piston which was stuck:
https://bicycles.stackexchange.com/questions/57661/hayes-sole-disk-brakes-adjusters-stiff-seized

In this case, remove the brake pads. Clean inside and outside with white spirits. Avoid getting dirty fluid on brake rotor or other braking surfaces. Do not clean/lubricate with oil or WD40 as it could damage any rubber/plastic parts of pistons. dot4 brake fluid could be used to lubricate (check is your hydraulic fluid mineral oil or dot4). After a while (in bad cases leave overnight for cleaning to soak in) gently (with plastic tool) but firmly push piston back.

I guess if that doesn't work then there might be air or excess of fluid in hydraulic system and some needs to be drained BUT I would really try and avoid draining any fluid!

4. For shimano there is a sort of cotter-pin. Bend or unbend the end to secure in place. For other pads there are different pins and small bolts or the caliper needs to be disconnected partly and angled away from rotor.

4. Inspect pads, I find usually pads go just a little bit too far worn in one place! When brake feels rougher or noisy I know I need to replace or inspect properly. Inspecting pads . . it is very hard to see how much pad is left without removing them. My shimano pads come off and the part closer to inside of the wheel is more worn, usually one end of a pad is almost completely down to the metal behind pad.

6. plastic tool = tyre remover or perhaps your old toothbrush :)

7. This step caused me trouble this morning! Shimano brake pads did not fit into the supplied pad holder they came with! They sort of fitted but hole for pin did not line up. I actually had to file the tops of the pads down to get them to fit into holder.  Fun and interesting!? And educational.  YES, and AFTER doing all this I find the clue is in the name "pad spacer" or "pad spring" should go in between the disc pads gently pushing them apart.  However you can put them on the outside and . . it doesn't really seem to matter. :-o

12. First few cycles out, just watching out for anything funny. "bedding-in" brake pads? I dunno. Usually they just work immediately.

A different thing, more of a problem with rim brakes, in case where your old brakes were quite bad and now you have good brakes be careful as you might grab and squeeze brakes suddenly and actually stop!! Do a bit of MTB training and learn to feather brakes.