Sunday, July 26, 2015

Copying and pasting table contents into comments in social networks and discussion forums

There isn't much sense in posting whole contents of tables into a comment under a post in most social networks, because directly copied-and-pasted content becomes plaintext, data is misplaced and garbled, because the comment and display area are not wide enough, and the intended overview becomes non-sensical anyway.

One can also choose to copy and paste only the first two columns, by holding down the Ctrl key in Firefox and dragging the mouse cursor across the cells with actual data starting from the ranking.

The data should first and foremost be pasted into a text editor, all the unnecessary data removed, and then copied and pasted here:
Top 10 countries by PEV market share of total new car sales in 2014 and 2013
^ Copied and pasted separately
# Country 2013 2014
1 Norway 13.84% 6.10%
2 Netherlands 3.87% 5.55%
3 Iceland 2.71% 0.94%
4 Estonia 1.57% 0.73%
5 Sweden 1.53% 0.71%
6 Japan 1.06% 0.91%
7 Denmark 0.88% 0.29%
8 Switzerland 0.75% 0.44%
9 United States 0.72% 0.60%
Source:
https://en.wikipedia.org/wiki/Electric_car_use_by_country#Top_10_countries

The result looks much nicer, but is still relatively unwieldy, because of variable-width fonts used by most social networking sites.

Section anchors and other anchors in MediaWiki code

It's possible to link to specific article sections or other in-article items in Wikipedia and other projects that use MediaWiki software.
Hereonafter I'm going to use 'MediaWiki', because this is the software that Wikipedia and similar projects rely on, and functionality is not limited to just Wikipedia. Other projects that use MediaWiki code are at Wikia, such as Memory Alpha, a comprehensive Star Trek canon encyclopedia.
The simplest way to find the jump link is by clicking on a section name in the article table of contents — the browser then jumps to the section — and then copying the URL from the browser address bar, where the address is appended with anchor text when an anchor is jumped to.

An anchor in HTML and newer web page standards is an in-page point one can jump to if a link exists, or if the anchor is used in a web address (URL).

Each section title is also made into an anchor, and sections are the most prominent jumping points in MediaWiki-based projects, because the anchor is always there whenever there's a section.

In a web address, the anchor is known as part of the URL that starts with a hash # sign:

https://en.wikipedia.org/wiki/Electric_car_use_by_country#Global_outlook

This link takes to the Wikipedia article "Electric car use by country", but jumps the browser view into the "Global outlook" section, which may have more relevant information than the whole article.

One can thus link to an in-article position either by targeting a section via pre-existing section anchors, or by creating a separate anchor using the {{Anchor}} template (exists in Wikipedia and its sister projects), or by creating and adding in article code a specific easily-readable ID to almost any tag or object present in an article, such as a table, a <DIV> or <SPAN>:
{| class="wikitable" id="Top_10_countries"
|-
|Table in wikicode
|-
|}


<!-- or somewhere else: -->

<div id="Other_countries">Some content inside a block</div>
That way, the anchor is created to a table, and after saving, one can jump to it by using this link instead:

https://en.wikipedia.org/wiki/Electric_car_use_by_country#Top_10_countries

Article sections in MediaWiki-based projects may contain all UTF-8-encoded characters, and the characters are then transformed into UTF-8-encoded text parts acceptable in web addresses:

The highlighted anchor part of the below URL was converted from the Russian word 'Возможности' (Features) from the Russian-language article about Mozilla Firefox, wherein the Russian-language capital 'В' (V) was converted into .D0.92. in an anchor. This, of course, makes links in non-Latin scripts very long:

https://ru.wikipedia.org/wiki/Mozilla_Firefox#.D0.92.D0.BE.D0.B7.D0.BC.D0.BE.D0.B6.D0.BD.D0.BE.D1.81.D1.82.D0.B8

Friday, July 17, 2015

Vim tips on searching and replacing

This is not exhaustive or anything, just a memo.
's' means substitute. While it may also mean "search", the search command is usually a slash /, as in
/searchabletext
The simple of it:

:s/whatimlookingfor/whatshouldreplaceit

The slash separates the command, the searchable item, the replaceable item, and additional parameters.

To replace stuff throughout the whole file (or document), use the percent % sign before s:

:%s/whatimlookingfor/whatshouldreplaceit

:s/\&,/^M/g

This replaces commas across one (long or large) line with a newline (carriage return). Breakdown:

s/ — starts the substitute command
after slash, enter search string
\& — all occurrences of desired search string within a line
, — comma is what one is looking for
/ — the next slash separates the search string from the replacement
^M — newline (carriage return). in gVIM (for Windows), it's highlighted, as it's actually entered as <Ctrl+V> <enter>
/g — replace till the end of line. Useful for if there's a huge amount of text in one line.

If one wants carriage returns after a comma, use this:

:s/\&,/&^M/g
— where the usually coloured (and special) carriage return symbol ^M follows the ampersand &. The ampersand is used to to add text: stuff before it is added before the searchable string; stuff added after the ampersand means that instead of deleting, stuff is added after the searchable string.

Convenient.

:s/\&&quot\;/"/g

Here it replaces all &quot; with normal quote characters "
\& — all occurrences of search string within a line;
&quot\; note that the semicolon is escaped.

:s/\&description="/&\t

\& — search in a line all instances of
    description="
/
&\t — As stated above, the ampersand & is used to add stuff; in this instance, a tab \t is added after the searchable string.

Turn highlight off
Like this:nohlsearch
^ Given that all searchable strings found are highlighted. But then it becomes somewhat annoying when proceeding to edit text after things are done. Instructions from the Vim wikia.

Or:

:noh

16.04.2018:
Search for strings not containing a character (search with exclusions)

Search for a line not containing dots (periods):

/^[^\.]*$

Breakdown:

/ — starts a search
^ — start of a line
[^stuff_to_be_excluded] — exclusion [^inside square brackets, starting with caron]
[^\.] — the dot is escaped with a backslash \
* — wildcard for everything
$ — end of a line

Pressing enter/return will get you to the nearest match (if any), and highlight other matches. Move to the next match with the n key.