Amo Chen

R File Manipulation

This post is one of the R language learning notes, focusing on file manipulation.

Posted on  May 30, 2017  in  R  by  Amo Chen  ‐ 1 min read

Connecting Windows to Virtual Machines in VirtualBox

Since Windows uses virtual network adapters to achieve VirtualBox’s network functionality, connecting from Windows to a virtual machine in VirtualBox requires some simple setup. This setup is known as “Port forwarding.”

Posted on  Dec 6, 2016  in  VirtualBox  by  Amo Chen  ‐ 2 min read

Recording Test Duration with Python pytest

Recently, I read an article titled Timing Tests in Python for Fun and Profit, which is well worth a read. The article discusses how to find test cases that need speed improvement by recording their execution time (and in the process, you might also discover code with poor performance).

However, I often use pytest, so I spent some extra time finding out how to achieve the same in pytest.

Posted on  Nov 20, 2016  in  Python Module Recommendations  by  Amo Chen  ‐ 2 min read

Python Tips - Saving Time and Effort with CSVDictWriter and defaultdict

Python’s CSVDictWriter is a handy module that allows you to write dictionary data directly into a CSV file. Here’s how you can use it:

import csv

with open('my.csv', 'w') as csvf:
    writer = csv.DictWriter(csvf, fieldnames=[
        'field_1',
        'field_2',
        'field_3'
    ])

    writer.writeheader()
    writer.writerow({'field_1': '', 'field_2': 'b', 'field_3': ''})
    writer.writerow({'field_1': '', 'field_2': 'b', 'field_3': ''})

While CSVDictWriter is convenient, it stops if any fields in a row are missing. This can be a hassle if you have many fields, and not all of them have values. Do you really need to manually fill in every single field?

Actually, you can solve this problem by using defaultdict.

Posted on  Sep 2, 2016  in  Python Programming - Intermediate Level  by  Amo Chen  ‐ 1 min read

Efficient MySQL Pagination

When I first started learning programming, I followed examples in textbooks using LIMIT offset, row_count for pagination. However, as the volume of data increased, this pagination method caused longer query times for later pages. In MySQL, when an offset is specified, it does not directly start retrieving data from that offset. Instead, it fetches all data based on the ‘where’ conditions first, and then retrieves the required number of rows beginning from the offset.

Posted on  May 29, 2016  in  MySQL  by  Amo Chen  ‐ 3 min read

Know Your VIM - Basic Cursor Movement

Up, Down, Left, and Right

Remembering how to move up, down, left, and right in VIM doesn’t require any secret tricks. The reason h, j, k, l are used for left, down, up, and right is because on the developer’s keyboard at the time, hjkl also represented those directions.

Left, Down, Up, Right h j k l

Historical Note: ADM-3A Keyboard

Last updated on  Sep 29, 2024  in  Vim  by  Amo Chen  ‐ 2 min read