Showing posts with label List. Show all posts
Showing posts with label List. Show all posts

25 January 2026

The list of all the format options of the gq command in vim?

In Vim, the
'formatoptions' setting controls how automatic text formatting is performed. It accepts a string of single-character flags, each enabling a specific behavior. You can view the current value in your Vim session with the command :set fo? or get a detailed explanation of all flags using the Vim help documentation via :help fo-table. 
The common and widely recognized formatoptions flags are:
  • t: Auto-wrap text at the width specified by the 'textwidth' option.
  • c: Auto-wrap comments at 'textwidth', automatically inserting the current comment leader character(s) (defined by 'comments' or 'commentstring').
  • q: Allow formatting with the gq operator.
  • r: Automatically insert the current comment leader after pressing <Enter> in Insert mode.
  • o: Automatically insert the current comment leader after pressing o or O in Normal mode.
  • n: Recognize numbered lists when formatting, using the pattern defined in 'formatlistpat'. This helps avoid joining list items into a single paragraph.
  • b: Auto-wrap text (backwards) when a line grows longer than 'textwidth'. The line is broken at the last white space before 'textwidth'.
  • v: Vi-compatible auto-wrapping (wraps at 'textwidth' in Insert mode).
  • j: Delete comment characters when joining lines using the J command.
  • l: Leave long lines as they are when entering Insert mode; only format if a line explicitly exceeds 'textwidth' due to typing.
  • m: Join with a space between the joined lines if there isn't one already.
  • p: Do not auto-wrap paste. When pasting text in Insert mode, do not apply auto-wrapping based on 'textwidth'.
  • u: Undo separate; make an undo command revert one line at a time instead of the entire paragraph formatting operation.
  • 2: Keep the indent of the second line when a paragraph is formatted (useful for some programming styles).
  • 1: Do not break a line after a single character (e.g., prevent single-letter words from being alone on the next line). 
  • a: Automatic formatting of paragraphs (changes are immediately reformatted). 
The default value is typically tcq. To add an option, you can use :set formatoptions+=<char>, and to remove one, use :set formatoptions-=<char>. 

04 April 2023

Can not connect sftp - "Warning: Permanently added to the list of known hosts"

https://stackoverflow.com/questions/9299651/git-says-warning-permanently-added-to-the-list-of-known-hosts

Create a ~/.ssh/config file and insert the line:

UserKnownHostsFile ~/.ssh/known_hosts

You will then see the message the next time you access Github (or any other sftp server), but after that you'll not see it anymore because the host is added to the known_hosts file. This fixes the issue, rather than just hiding the log message.

19 March 2023

How to sort a 2 dimensional list by 2 or more keys in different orders in Python?

https://wiki.python.org/moin/HowTo/Sorting/#Key_Functions

If with Pandas, it is easy - 

dist_list = [            
    [Ada Taylor, 4.00],
    [Iris White,26.02],
    [Octavia Smith, 7.29],
    [Tracy Jones, 4.00],
]

# Convert the list into a Python dataframe.
dist_df = pd.DataFrame(dist_list, columns=['Name', 'Distance'])

# Sort it by Distance in descending order. If some people 
# run the same distance, then sort those people's distances 
# by Name in ascending order.
dist_df.sort_values(by=['Distance', 'Name'], ascending=(False, True), inplace=True)

print(dist_df)

            Name  Distance
0     Iris White     26.02
1  Octavia Smith      7.29
2     Ada Taylor      4.00
3    Tracy Jones      4.00

But if without Pandas, we can manage to do that by sorting it twice. Firstly sort it by the secondary key (Name) in one order (ascending), then sort it by the main key (Distance) in another order (descending).

# Convert the list into a dictionary, while grouping
# and aggregating the distances by person.
dist_dict = {}
for person, distance in dist_list:
    if person not in dist_dict:
        dist_dict[person] = distance
    else:
        dist_dict[person] += distance

# Convert the dictionary back into a list, in order to sort it.
dist_list = [[person, distance] for person, distance in dist_dict.items()]

# Firstly, sort it by secondary key - person, in ascending order.
dist_list = sorted(dist_list, key=lambda x: x[0], reverse=False)

# Then, sort it by primary key - distance, in descending order.
dist_list = sorted(dist_list, key=lambda x: x[1], reverse=True)

print(dist_list)

[['Iris White', 26.02], ['Octavia Smith', 7.29], ['Ada Taylor', 4], ['Tracy Jones', 4]]


We can also manage to do that using the 'itemgetter()' function from the 'operator' Python standard module.


from operator import itemgetter
dist_list = sorted(dist_list, itemgetter(0), reverse=False)
dist_list = sorted(dist_list, itemgetter(1), reverse=True)

print(dist_list)

[['Iris White', 26.02], ['Octavia Smith', 7.29], ['Ada Taylor', 4], ['Tracy Jones', 4]]


Please look at 


I copied the section here as follows.

Operator Module Functions

The key-function patterns shown above are very common, so Python provides convenience functions to make accessor functions easier and faster. The operator module has itemgetterattrgetter, and starting in Python 2.6 a methodcaller function.

Using those functions, the above examples become simpler and faster.

>>> from operator import itemgetter, attrgetter, methodcaller

>>> sorted(student_tuples, key=itemgetter(2))
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

>>> sorted(student_objects, key=attrgetter('age'))
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

The operator module functions allow multiple levels of sorting. For example, to sort by grade then by age:

>>> sorted(student_tuples, key=itemgetter(1,2))
[('john', 'A', 15), ('dave', 'B', 10), ('jane', 'B', 12)]

>>> sorted(student_objects, key=attrgetter('grade', 'age'))
[('john', 'A', 15), ('dave', 'B', 10), ('jane', 'B', 12)]

The third function from the operator module, methodcaller is used in the following example in which the weighted grade of each student is shown before sorting on it:

>>> [(student.name, student.weighted_grade()) for student in student_objects]
[('john', 0.13333333333333333), ('jane', 0.08333333333333333), ('dave', 0.1)]
>>> sorted(student_objects, key=methodcaller('weighted_grade'))
[('jane', 'B', 12), ('dave', 'B', 10), ('john', 'A', 15)]

Ascending and Descending

Both list.sort() and sorted() accept a reverse parameter with a boolean value. This is using to flag descending sorts. For example, to get the student data in reverse age order:

>>> sorted(student_tuples, key=itemgetter(2), reverse=True)
[('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]

>>> sorted(student_objects, key=attrgetter('age'), reverse=True)
[('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]

Sort Stability and Complex Sorts

Starting with Python 2.2, sorts are guaranteed to be stable. That means that when multiple records have the same key, their original order is preserved.

>>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)]
>>> sorted(data, key=itemgetter(0))
[('blue', 1), ('blue', 2), ('red', 1), ('red', 2)]

Notice how the two records for 'blue' retain their original order so that ('blue', 1) is guaranteed to precede ('blue', 2).

This wonderful property lets you build complex sorts in a series of sorting steps. For example, to sort the student data by descending grade and then ascending age, do the age sort first and then sort again using grade:

>>> s = sorted(student_objects, key=attrgetter('age'))     # sort on secondary key
>>> sorted(s, key=attrgetter('grade'), reverse=True)       # now sort on primary key, descending
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

The Timsort algorithm used in Python does multiple sorts efficiently because it can take advantage of any ordering already present in a dataset.

14 May 2022

How to get a list of the members of an email distribution list, and a list of the members of an office 365 team?


(1) Email distribution list

Go to office.com > 9 dots > admin > show all > exchange > dashboard_recipients_groups.

Click to select a group, e.g. cics.staff. Click 'Edit' > membership. Ctrl-a Ctrl-c

Ctrl-v in a text editor.

(2) Team

Go to the team, e.g. team_staff. Wait for quite a while, and need repeat scrolling up and down, until all the members are displayed, before mouse-dragging all the members, and Ctrl-c

Ctrl-v in a text editor.

13 May 2022

How to export a list of members of an email group from Office 365?

https://answers.microsoft.com/en-us/msoffice/forum/all/how-do-i-really-export-distribution-list-members/efe355ff-cc64-4235-8615-364bbff75382

Based on my tests and researches, it is not feasible to export distribution list members using UI interface. We can only export the members via Windows PowerShell. To do that, the steps are as follows:

1. Open Windows PowerShell and connect to Exchange Online PowerShell. Here are the commands:

Install-Module ExchangeOnlineManagement (Enter Y to install the module)

Connect-ExchangeOnline (Sign in using admin account and password)

2. Then run the following script to get a csv file about Distribution list.

$Groups = Get-DistributionGroup

$Groups | ForEach-Object {

$group = $_.Name

$members = ''

Get-DistributionGroupMember $group | ForEach-Object {

$members=$_.Name

New-Object -TypeName PSObject -Property @{

GroupName = $group

Members = $members

EmailAddress = $_.PrimarySMTPAddress

}}

} | Export-CSV "C:\DistributionGroupMember.csv" -NoTypeInformation -Encoding UTF8

Here is a screenshot about the result I got:

Image


10 August 2021

How to read a file, which only contains a string, into Python, and then convert the string into a list?

 How to read a file, which only contains a string, into Python, and then convert the string into a list?


from pathlib import Path

txt = Path('filename.txt').read_text()

list_ = list(txt.split('; '))

08 August 2021

How to convert a pandas dataframe into a python list, and a python list into a pandas dataframe?

 How to convert a pandas dataframe into a python list, and a python list into a pandas dataframe?


1. To convert a pandas dataframe into a python list

email_list = df['Email'].to_list()

or

email_list = df[['Name', 'Email']].to_list()


2. To convert a python list into a pandas dataframe

Examples

>>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
...           {'a': 100, 'b': 200, 'c': 300, 'd': 400},
...           {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
>>> df = pd.DataFrame(mydict)
>>> df
      a     b     c     d
0     1     2     3     4
1   100   200   300   400
2  1000  2000  3000  4000


20 June 2021

How to list all html files in a directory recursively sorted by file size?

 How to list all html files in a directory recursively sorted by file size?

$du -a -h | sort -nr | grep 'html' | less

Note:

1. '-a' means all files and directories, not just directories.

2. '-h' means human readable.

3. '-n' means numeric sort.

4. '-r' means recursive.

11 April 2016

Incident list would not appear

Incident list would not appear

After upgrading SysAid versions, incident list would not appear.

Instead, you see an error message -

'The list can not be loaded, because it was defined with a bad query. Click "Customize View" to review the view settings and try again.'

Go to your database, run this query - select version from version. You may see the same version number (of the tables) as the version of the new SysAid Server software.

Run this query - delete version from version. You may see different old version numbers (of tables), while the newest version number has disappeared. That is correct.

Go see the incident list. It appears now. Congratulations!

23 June 2015

SysAid - In RDS list, can not see the machine I have installed RDS software on

Problem: SysAid - In RDS list, can not see the machine I have installed RDS software on

Solution: On the machine I have installed RDS on, go to the folder -

C:\Program Files\SysAidRemoteDiscovery\root\WEF_INF\root, open the text file -

Discovery Services.properties

There are two lines containing the IP address of the SysAid server. The first one is with the port 8080, the second one without.

What we need to do is to just add ':8080' at the end of the second line of IP address.

Save it. Restart the RDS service.

Done.