Category Archives: Software

How to: split PDFs into pages with pyPDF2 (writing your own PDF splitter)

The function below uses pyPDF2 to split pages in a pdf file into separate PDFs by given a path to the master PDF file.

import os
from PyPDF2 import PdfFileReader, PdfFileWriter

def pdf_splitter(path):
    fname = os.path.splitext(os.path.basename(path))[0]
 
    pdf = PdfFileReader(path)
    for page in range(pdf.getNumPages()):
        pdf_writer = PdfFileWriter()
        pdf_writer.addPage(pdf.getPage(page))
 
        output_filename = '{}_page_{}.pdf'.format(
            fname, page+1)
 
        with open(output_filename, 'wb') as out:
            pdf_writer.write(out)
 
        print('Created: {}'.format(output_filename))

How to fix orphan files in Google Drive?

Missing Files and Folder on Google Drive!

If you stumble into this post, it means you are also having an orphan files problem with Gdrive.

I had exactly the same issue. When I was trying to remove a big folder from Google Drive to free space, only the top layer of the folder is removed. All the sub-folders inside are not trashed, but appearing in my “Recent” and “Storage” Tab.

Those missing and disappearing files become what are known as orphan files (or invisible ghost files). They are folders / files with an empty path.

Here are the solutions to fix those, you just need to find them and restore / trash them.

Solution 1: Searching “is:unorganized owner:me”

Some of the ghost files can be found by searching “is:unorganized owner:me” on the search bar. This will list out the unorganized files and folder. You can then drag them back to a new location / trash them again to free space.

However, this does not work for files in an orphan folder! See solution 2 to find ghost files in orphan folder.

Solution 2: Finding files in orphan directory

Step 1: List storage by clicking on “XXX GB of XXX GB used” below “Storage” on the left, this will list all of your files

Step 2: Sort the files by size / by names to find 1 orphan file

Step 3: Single Click on the orphan file

Step 4: Open the Detail Tab on the right side, you will see the orphan directory, click onto that to drill into the directory

Step 5: If the orphan directory is also a sub-folder, navigate to the parent folder through the buttons below the search bar

Step 6: Now, you are at the parent orphan directory. Single click on the folder button below the search bar and choose “search within [Folder Name]” from the dropdown menu.

Step 7: Great, now you have a list of all the orphan files in that parent orphan folder. You can then drag them to a new location or proceed to remove them to free space.

Step 8: Repeat to target other parent orphan folder (hope you do not have too many parents folders to deal with!)

How to cancel Microsoft Office 365 subscription and get a refund when the cancellation button is not showing?

If you happened to receive a free Microsoft office 365 subscription (for a limited number of months) or tried the trial version, but forgot to cancel your subscription, Microsoft will renew the subscription for you automatically and charge your credit card.

According to Microsoft, you can request a refund if:

  • You bought an annual subscription to Office 365 within the last 30 days.
  • You have a monthly subscription and cancel within 30 days of your last renewal.

Normally, you can do it online through the website: https://account.microsoft.com/account

You can login and manage your subscription. If the above condition is satisfied, you will see a button to cancel your subscription and get a refund.

However, sometimes the button is not showing up. Perhaps in their system, auto-renewal of the subscription is not detected automatically to be eligible for the refund.

However, no worry, you can contact Microsoft customer service arrange for the refund. I tried contacting Microsoft through their Help Service (https://partner.support.services.microsoft.com/en-us/contactus/) and the process went quite smoothly.

 

How to free up space in windows 10

1. Using the windows Disk Cleanup tool
Windows comes with a disk cleanup tool that lists out most of the temporary files locations. You can remove those files without changing the functionality of your PC. These locations includes:

  • a) Delivery Optimization Files
    Delivery Optimization files are files that were previously downloaded to your computer and can be deleted if currently unused by the Delivery Optimization service.
  • b) Downloads Folder
  • c) Recycle Bin
  • d) Temporary Files
    Apps can store tempporary information in specific folders. These can be cleaned up manually if you app does not do it automatically.
  • e) Thumbnails
    Windows keeps a copy of all of your picture, video, and document thumbnails so they can be displayed quickly when you open a folder. If you delete these thumbnails, they will be automatically created as needed.

 

2. Remove Windows.old folder (up to 40GB)
If you update to windows 10 from a previous windows version, windows would keep a copy of the previous OS in your disk, which is stored in C:\Windows.old folder. This folder can take up to 40GB. As windows 10 is getting stable, this previous windows copy may not be useful anymore and we may choose to remove it to save disk space. This site shows the steps of how to remove windows.old folder.

How To Build Your Own Software: Keyboard Chattering / Double Stroking Suppressing Python Script

Previously, I wrote a post regarding keyboard chattering / double tapping software solution (link). This solution requires downloading a software from Softpedia.

When it comes to downloading software that records your keyboard strokes, caution must be taken, to make sure the source is free from malware. Or, why not build your own script to fix the keyboard chattering.

It is actually quite simple to write such script (similar to keylogger) in python with the keyboard library. A simple algorithm to prevent double tapping is to write a callback function for each key press event. Usually the double taps occur within a very short interval, and we can block the key for ~20ms to filter out the second strokes

Script:

import keyboard
import time
import os
import threading

class myThread (threading.Thread):
    def __init__(self, key, keyboard):
        threading.Thread.__init__(self)
        self.key = key
        self.keyboard = keyboard
    def run(self):
        keyboard = self.keyboard
        key = self.key
        hook = keyboard.block_key(key)
        time.sleep(0.02) # block key for 0.02 after pressing (adjustable)
        keyboard.unhook(hook) # unblock key after 0.02 sec

def callback(e):
    key = e.name
    if not key in ["ctrl", "shift", "alt"]: # Don't block function keys
        if e.event_type == "up":
            thread = myThread(key, keyboard)
            thread.run()

if __name__ == "__main__":
    keyboard.hook(callback)

The advantage of writing your own script is the flexibility. Depending on how your keyboard chatter, you can adjust the parameters to make it work. In the script below, I also added an exception list, as I don’t want to block the function keys (ctrl, shift, alt) and double strokes really do not have effects on these keys. Please let me know if you find the script useful.

How To Fix: Keyboard doublestrokes / multistrokes / double tapping / key chattering (Software Solution)

Issue: Keyboard doublestrokes / multistrokes / double tapping / key chattering

Fix 1: Install “Free Keyboard Chattering Fix Software” from Softpedia:
https://www.softpedia.com/get/System/System-Miscellaneous/Keyboard-Chattering-Fix.shtml

Is it safe?
Softpedia is a popular website for software downloads. If you see “100% Free” or “100% Safe” on the top right side of their website, it means the software has been tested by the Softpedia team to ensure it does not contain any form of malware, including but not limited to: spyware, viruses, trojans and backdoors.

Fix 2: Build your own script to filter out the double strokes
See my other post (url).

How to reset ubuntu password in virtual machine

1. Enter the Recovery Mode
– To do this, hold SHIFT key during boot-up
– Select *Advanced options for Ubuntu in the GNU GRUB Menu
– Select (recovery mode)

2. In the recovery mode, choose root – Drop to root shell prompt

3. Remount system with write access, type the following command:

mount -o remount,rw /

4. Reset password, type the following command:

passwd USERNAME

Where USERNAME is your account’s id. If you forgot your username, you can type “ls /home” to list out all usernames.

Source: https://wiki.ubuntu.com/RecoveryMode

How To Fix: “The ordinal 242 could not be located in the dynamic link library mkl_intel_thread.dll”

One day after updating spyder in anaconda, I got the following error message when opening Spyder:
“The ordinal 242 could not be located in the dynamic link library mkl_intel_thread.dll”

Cause:
Another software installed MKL or Intel OpenMP (libiomp5md.dll) files into the C:\Windows\System32 folder (which is a bad practice) and the libiomp5md.dll installed is not compatible with numpy.

Temporary Fix:
Enter the following command in anaconda prompt before starting spyder

set CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
spyder

Permanent Fix:
Remove libiomp5md.dll in C:\Windows\System32 or rename it to libiomp5md.dll.bak.

Source: https://conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#numpy-mkl-library-load-failed

How to roll back conda updates

Few days ago I updated my conda packages and I am getting the following errors:

Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.

The ordinal could not be located in the dynamic link library C:\Users\username\Anaconda3\Library\bin\mkl_intel_thread.dll.

(detail of the issue: https://github.com/ContinuumIO/anaconda-issues/issues/10213)

Apparently if the “conda-forge” channel is above the “defaults” channel on the .condarc list (located in home directory), this problem may occur.

 

Then I learnt some useful commands in anaconda:

  • conda list –revisions
  • conda install –revision REVNUM

The first command lists out the revision history of the conda environment, each with a revision number.

The second command will restore your conda environment to the revision you specify.

 

Reference:

https://support.anaconda.com/hc/en-us/articles/360023863914-Restoring-environment-to-a-previous-revision

Opensees Awesome List

Hanlin-Dong (董翰林) created an awesome list for opensees (https://github.com/Hanlin-Dong/awesome-opensees).

Some of the tools on the list are really great, and I recommend the followings:

  1. OpenSees Navigator: a very easy to use mat-lab built-in GUI tool to create opensees models. Perfect for mat-lab users and new opensees users.
  2. OpenSeesAPI: Python API to write .tcl script.
  3. OpenSees Model View: Python script to visualize model built in .tcl (doesn’t support .tcl with comments yet, but the project has great potential)

I am so glad to find this list when I started learning opensees. These tools provide a board coverage on what opensees can do and I am totally impressed.