Column widths are broken for non-latin characters in console - mysql-cli

I have this rather inconvenient problem with mysql console client, the column widths in display are broken for non-latin characters, i.e. mysql makes the column 1.5 times wider than it needs to be for Chinese characters, Cyrillic is even worse, the column is twice as wide as it needs to be, i.e. for a string 100 characters wide, the column width will be 200 characters which makes the output absolute mess really. Is there a way to fix this? I tried to use -r -s and \P but I could not get anything suitable.
See the example below, note how abc column is exactly as wide as the string RRRRRRR plus two margin characters, and how zh and cyr are incorrectly padded as if the input contained invisible spaces.
select '你好你好' as zh, 'RRRRRRR' as abc, 'ЯЯЯЯЯЯЯ' as cyr;
+--------------+---------+----------------+
| zh | abc | cyr |
+--------------+---------+----------------+
| 你好你好 | RRRRRRR | ЯЯЯЯЯЯЯ |
+--------------+---------+----------------+

Related

Mysql - Select all rows with special characters (but ignore space)

I'm trying to write a query to identify what rows have special characters in them, but I want it to ignore spaces
So far I've got
SELECT word FROM `games_hangman_words` WHERE word REGEXP '[^[:alnum:]]'
Currently this matches those that use all special characters, what I want is to ignore if the special character is space
So if I have these rows
Alice
4 Kings
Another Story
Ene-tan
Go-Busters Logo
Lea's Request
I want it to match
Ene-tan, Go-Busters Logo and Lea's Request
Simply extend your class.
... WHERE word REGEXP '[^[:alnum:] ]' ...
for only a "regular" space (ASCII 32) or
... WHERE word REGEXP '[^[:alnum:][:space:]]' ...
for all kind of white space characters.

can't insert tables within dd tags in markdown syntax

setting up documentation for a plugin.
Can you add tables within a dd tag?
I tried the code below but it wont output as a table I tried with the double space line break technique but nothing either
This doesnt parse the table and just leaves the table syntax as is
Term
: definition
: | Table cell | Table cel | Table cell |
This wont render (note there are two spaces after definition)
Term
: definition
| Table cell | Table cel | Table cell |
my goal is this:
<dl>
<dt>Term</dt>
<dd>
definition
<table>
<!-- table rows and cells here -->
</table>
</dd>
</dl>
Depending on the Markdown implementation you are using either you can't or you need to do three things:
(1) Wrap your table with blank lines
A table is a block level element, just like a paragraph is. Therefore, it needs to be on a line by itself. To accomplish that, you need to include a blank line before the table. There is no need to add two spaces to the preceding line as the blank line already separates the elements and each block-level element will always be on its own line (barring some non-standard CSS which changes that behavior) .
(2) Indent your table
Of course, when you are nesting block level elements inside a list item and those elements do not start in the first line of the list item, you must indent those elements by one level to indicate they are nested. Therefore, the table must be indented by four spaces or one tab.
(3) Add a table header
Except for Kramdown, all implementations which support tables (that I am aware of) require the table to include a header. Otherwise, they do not recognize it as a table.
Example
Try this:
Term
: definition
| Header 1 | Header 2 | Header 3 |
| ---------- | --------- | ---------- |
| Table cell | Table cel | Table cell |
That said, both definition lists and tables are non-standard Markdown and their behavior varies among implementations which support them (not all do). Therefore, YMMV.
In fact, Babelmark demonstrates that the above works for Pandoc, RDiscount, PHP Markdown Extra, and MultiMarkdown (strangely version 5, but not version 6). Note that a few other implementations likely would work as well if they were properly configured. Babelmark only demonstrates default behavior for each implementation.

Why does a character trail after the hyperlink tag by one space when coded in a specific way?

The character used in this question examples is the period, it appears that all characters behave the same way. Why does the period trail after the hyperlink by one space character when coded like this:
You can become one of us
<a href="http://www.somedomain.com/oneOfUs/allYourBaseAreBelongToUs/">
here
</a>
.
I checked the ascii character array for the above and it looks to be a simple space:
104 101 114 101 32 46
vs no trailing space after the hyperlink when coded like this:
You can become one of us
here.
The ascii character array for the above contains no space in output, but providing the character array for output comparison: 104 101 114 101 46
This is because the newline in the first example is converted to a space. There is a more thorough explanation in this thread: Prevent browser converting '\n' between lines into space (for Chinese characters)

Designing table definition syntax for Markdown

I have made no secret of my disdain for BBCode and support for more readable text-to-HTML converters like Markdown, which is what SO uses. "Canonical" Markdown however doesn't have a syntax to define tables. So, I am trying to come up with an extension that does just that.
Above all, it should be easy to read and write. Of course it also shouldn't be conflict with existing Markdown syntax. PHP Markdown has syntax for tables that looks like:
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
For some reason, this strikes me as "not enough enough" (mainly because it looks a little too verbose). Does anyone know of a Markdown dialect with a nicer syntax? You are welcome to write your own as well.
Bonus points if it's not extraordinarily difficult to parse but still flexible enough to handle alignments (horizontal and vertical), table headers and possibly colspan and rowspan.
I like Textile's table syntax. It looks like:
|_. a header cell |_. another header |
|_. one more header |=. centered cell |
| regular cell |>. right-aligned cell |
The parser doesn't care about whitespace. This syntax is flexible and avoids the rigidity of syntaxes (like yours, Reddit's, etc.) requiring a "separator" line between a single header row and the rest of the table.

Give tab spacing after first word in text file

Consider I have a .txt file as of the format,
Name: Abc
Id: 123
Age: 12
Address: xyz
I want to convert this file of the form,
Name : Abc
Id : 123
Age : 12
Address : xyz
i.e the Colon after each tile should move 2 or 3 tab spaces. The title will be only a single word and wont have spaces. So the title wont be of the form(Your age:). So i can just read the first word and give tabs after that.
How can i do this? and will doing in perl be simpler or any other language.?
Find the length of the biggest word, add n spaces to it. That's the padding to use when formatting each word.
PHP, for example, has a sprintf() function that you can look at. Various other languages provide formatted output as well.
In PHP, the following format should work - "%-<max>s : %s", where <max> is the length of the biggest word + some padding.
sprintf("%-25s : %s", $key, $value);
- makes the string left aligned.