30 March 2023
29 March 2023
28 March 2023
How to Use ChatGPT 4 For Free
23 March 2023
How to install Python, pip, and venv on Ubuntu 22.04?
Method 1. Simpler Method
$ sudo apt update
19 March 2023
How to sort a 2 dimensional list by 2 or more keys in different orders in Python?
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 itemgetter, attrgetter, 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.
18 March 2023
17 March 2023
15 March 2023
"+y, "+p do not work in vim
14 March 2023
How to install Chinese input on Ubuntu?
- Open Settings, go to
Region & Language
->Manage Installed Languages
->Install / Remove languages
. - Select
Chinese (Simplified)
. Make sureKeyboard Input method system
hasIbus
selected. Apply. - Reboot
- Log back in, reopen Settings, go to
Keyboard
. - Click on the "+" sign under
Input sources
. - Select
Chinese (China)
and thenChinese (Intelligent Pinyin)
.
In newer version of Ubuntu, I seem to have to install ibus-pinyin
$ sudo apt-get install ibus-pinyin
$ ibus restart
11 March 2023
How to generate the RealTimeSync command line?
2. Then, next to the selected folder on the left side, there is a "green plus."
3. Click the "green plus" and it will add another line for an additional folder pair to sync in addition to the first one you selected.
4. Continue hitting the "green plus" until you've listed all the folders you want to sync between the two locations.
5. Run the FFS Compare and Synchronize buttons.
6. After completed, click on the File menu. Select "Save as batch job...".
7. Save the batch job file (you can rename it, but in the below example, I'm just going to use the automatic name FFS provides) to a convenient location - it doesn't matter where - Desktop or Root C:\ are good recommendations. I suggest using the normal batch job file name (BatchRun.ffs_batch). Then close FFS.
8. Open RealTimeSync (RTS).
9. In the command line in RTS, first enter the folder path to the FFS .EXE file in quotes. E.g., "C:\Program Files\FreeFileSync\FreeFileSync.exe"
10. After entering the FFS .EXE location in quotes, enter a Space.
11. After the Space in the command line field, in quotes, enter the direct path to the batch job that was saved from FFS. E.g., "C:\BatchRun.ffs_batch"
12. In my example, the full RTS command line would look like this: "C:\Program Files\FreeFileSync\FreeFileSync.exe" "C:\BatchRun.ffs_batch"
13. Then run RTS, and it should start automatically monitoring all of the folder pairs initially selected in FFS (one or more) that created the batch job file. You can always go back to FFS to add/remove any folders selected, then repeat Steps 6 & 7 above. If you never changed the name of the FFS batch job file, then no command line updates will be required in RTS. RTS will automatically start using the same/updated batch file with any FFS sync changes made to it.
14. Profit!
Note 1: Once you create a batch job file from FFS, it's strongly suggested that the file name is never changed, and that it is continuously updated (overwritten) from FFS. I.e., if you have RTS set up now, don't change the name of the batch job file, or move it to a different computer location.
Note 2: This should go without saying, but also make sure all of the folders being monitored for changes in RTS have been listed. In RTS, under the "Folders to watch:" section, make sure all the same folders being monitored match the same ones selected in FFS when the batch job file was created and/or latest overwritten.
Note 3: You can't enter multiple batch job files in the RTS command line. So, creating the singular batch job file and making updates to it, then overwriting the same old batch job file each time a change to the folders in FFS is made, is (probably) the best way to continuously auto-sync multiple folders with RTS.
All of this is working for me (as of when I'm posting this) - I monitored RTS multiple times and for a while, and it does work, following the above steps! I really hope this helps! Good luck!
K
08 March 2023
How to install .deb files on Ubuntu?
https://linuxconfig.org/install-deb-file-on-ubuntu-22-04-jammy-jellyfish-linux
$ sudo dpkg -i example.deb
If the package requires dependencies that aren’t already on your system, you will see
this error in the terminal:
dpkg: error processing package
Don’t fret, because we can install the required dependencies with a single command,
assuming that they are available in Ubuntu’s package repository. Just run this command
to install the dependencies:
$ sudo apt install -f