Skip to content

Instantly share code, notes, and snippets.

View krisbolton's full-sized avatar

Kris krisbolton

View GitHub Profile
@krisbolton
krisbolton / vscode-import-could-not-be-resolved-by-pylance.md
Last active June 16, 2024 08:07
VSCode import could not be resolved by Pylance (reportMissingImports)

Problem

Visual Studio Code (VSCode) reports an error (yellow squiggly lines) saying "Import [nameOfModule] could not be resolved by Pylance (reportMissingImports)". You may be using a virtual environment (e.g., venv).

Solution

You need to tell Pylance where pip has installed the module you are trying to import. This is called an "additional path".

  1. Find the location of the module. In the VSCode terminal within your project enter the python interpreter by typing python.
  2. Once the interpreter is active (shown by >>> instead of $ or %) type import [nameOfModule] and press enter.
@krisbolton
krisbolton / fix-vmware-workstation-error-unable-to-open-kernel-device-vmcidev-vmx.md
Last active February 23, 2024 18:09
Fix VMware Workstation Error unable to open kernel device "VMCIDev VMX"

Problem

VMware Workstation Player returns an error when trying to run a new virutal machine. The error reads "Unable to open kernel device '\.\VMCIDev\VMX': The operation completed successfully. Did you reboot after installing VMware Player? Module 'DevicePowerOn' power on failed. Failed to start the virtual machine."

Solution

  1. Navigate to the virtual machine's working directory.
  2. To find your VM's working directory by right-clicking the VM, selecting 'settings', selecting the 'Options' tab, and noting the 'Working directory' path. Navigate to the working directory in Window's Explorer.
  3. Find the VMX file, with type 'VMware virtual machine configuration'.
  4. Open the VMX file in notepad.
@krisbolton
krisbolton / icann-verification-suspension-page-remains.md
Created January 6, 2023 14:13
ICANN verification suspension page remains after verification

Problem

I missed an email from my domain provider requesting I verify my contact details in accordance with ICANN's policies, this resulted in a landing page being placed on my domain root. The page said after verification the site would return after 24 to 48 hours. The landing page remained in place for approx. 6 days, until I made DNS changes.

Solution

"Reset" your website's DNS. i.e., change the IP addresses the A records point to. In my case this was GitHub Pages IP addesses. After just a few minutes the website returned. I'm not sure if the IP addresses were changed in the first place, but this worked for me.

@krisbolton
krisbolton / count-unique-days-in-datetime-dataframe-column.md
Last active February 20, 2023 17:02
Count the number of unique days in a datetime dataframe column

Problem

I want to count the number of unqiue days within a pandas dataframe column contianing datatime dtypes. The use-case is Twitter data from TWINT, "How many days has a user tweeted within the collected time period?". The code below assumes the datetime column is called date.

Solution

You must first convert the datetime column using pd.to_datetime and use pandas dt to access the date portion of the date time. This can then be used by the unique() and len() function to count unique occurances.

df['date_only'] = pd.to_datetime(df['date'])
@krisbolton
krisbolton / extract-time-from-datetime-dataframe.md
Last active March 17, 2021 21:17
Extract time from datetime in pandas dataframe for TWINT

Problem

I want to extract the time part of a datetime column (2021-02-17 00:14:53). For example, from Twitter data stored in a dataframe. In this example the datetime dtype is stored in a column named date.

Solution

You must convert the column to a datetime using pd.to_datetime and use Pandas dt function to access the time portion of the datetime field.

df['time_only'] = pd.to_datetime(df['date'])
@krisbolton
krisbolton / r-cannot-allocate-vector-of-size-solution.md
Last active February 3, 2021 16:01
Solution to R error "cannot allocate vector of size ..."

Problem

You recieve an error in R Studio "cannot allocate vector of size ...". Below is the full error:

Error: package or namespace load failed for ‘raster’ in .doLoadActions(where, attach): error in load action .A.1 for package raster: loadModule(module = "spmod", what = TRUE, env = ns, loadNow = TRUE): Unable to load module "spmod": cannot allocate vector of size 14274.2 Gb

N.B. the data was not actually 14,000 Gb.. issues surrounding data that large would be clear.

Solution

@krisbolton
krisbolton / iterate-pandas-dataframe-row-by-row.md
Last active March 9, 2024 19:26
How to iterate and update pandas dataframe row by row

Problem

I want to iterate over a single column in a pandas dataframe and update cells in that column one by one. In my use-case I want user input to provide the update input.

New solution accesses cells directly reducing performance hit and avoiding potential side effects of iterrows().

New Solution

for index, row in df['Col'].items():
@krisbolton
krisbolton / fix-USB-showing-up-as-two-partitions.md
Last active June 18, 2024 23:56
How to fix a USB drive showing up as two drives (fragmented into multiple partitions) on Windows

How to fix a USB drive showing up as two drives (fragmented into multiple partitions) on Windows:

  1. Hold the Windows key and press X, select PowerShell (Admin), select Yes to the pop-up. You can also use Command Prompt.
  2. In the Powershell interface type diskpart to enter the disk partition tool.
  3. Type list disk to see all disks listed.
  4. Select the USB drive by typing select disk [NUMBER]. Be careful to select the correct drive.
  5. Type clean. An error will occur if you have the drive folder open, close the window and repeat the command if this happens.
  6. Type create partition primary.
  7. Type format fs=ntfs quick to format the drive (you can also choose to set fs=fat32).
  8. Type active.