Skip to content

Instantly share code, notes, and snippets.

@krisbolton
krisbolton / icann-verification-suspension-page-remains.md
Created January 6, 2023 14:13
ICANN verification suspension page remains after verification
View icann-verification-suspension-page-remains.md

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
View count-unique-days-in-datetime-dataframe-column.md

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
View extract-time-from-datetime-dataframe.md

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 ..."
View r-cannot-allocate-vector-of-size-solution.md

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 February 3, 2021 16:02
How to iterate and update pandas dataframe row by row
View iterate-pandas-dataframe-row-by-row.md

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.

Solution

for i, row in df.iterrows():
    user_input = input('Enter value: ')
 df.at[i, 'user_input'] = user_input
@krisbolton
krisbolton / fix-USB-showing-up-as-two-partitions.md
Last active June 3, 2023 19:36
How to fix a USB drive showing up as two drives (fragmented into multiple partitions) on Windows
View fix-USB-showing-up-as-two-partitions.md

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.