Skip to content

Instantly share code, notes, and snippets.

View paulera's full-sized avatar

Paulo Amaral paulera

View GitHub Profile
@paulera
paulera / recreate_tree_from_filelist.py
Created December 29, 2023 02:25
Automatically recreates a directory tree from a filelist, using divider characters to define folder paths.
#!/usr/bin/env python3
# Written by OpenAI (GPT 4): https://chat.openai.com/share/b7a9d856-7509-460d-85b3-3e5f07161e55
import argparse
import os
import shutil
def process_files(output_folder, divider, file_names):
if not os.path.exists(output_folder):
@paulera
paulera / create_fresh_wsl_image.md
Last active June 20, 2023 09:49
Create a WSL instance from a fresh linux image file. You can have many instances running in parallel.

Create a fresh WSL instance

  • Download ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz from https://cloud-images.ubuntu.com/releases/focal/release
  • Install the .tar.gz image in a folder of your choice: wsl --import <Instance Name> <Folder> <.tar.gz file>
    • example (run in Windows command line):
      mkdir %userprofile%\wsl-developer
      wsl --import Development %userprofile%\wsl-developer ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz
  • Boot up the instance: wsl -d <Instance Name>

Tips from the book Pragmatic Programmer (20th Anniversary edition)

https://pragprog.com/titles/tpp20/the-pragmatic-programmer-20th-anniversary-edition/

https://www.goodreads.com/book/show/60633459-the-pragmatic-programmer-20th-anniversary-edition-your-journey-to-maste

Tip #1, pg. xxi: Care About Your Craft - Why spend your life developing software unless you care about doing it well?

Tip #2, pg. xxi: Think! About Your Work - Turn off the autopilot and take control. Constantly critique and appraise your work.

@paulera
paulera / _rsync_backup_restore.md
Last active March 1, 2023 19:09
rsync for backups and restore, preserving folders structure

Backup tricks with rsync

Creating backups

The commands below use a folder ~/backup/ as storage. Files are copied with the following features:

  • rsync --relative: Tree structure relative to / is preserved (subdirectories created if needed).
    • realpath --no-symlinks: Symlinks not resolved, so in case you use the backup to restore files, they will end up where they were found.
  • --recursive: Subfolders too
  • --perms: Permissions preserved
  • --copy-links: Don't backup links, but the files they are pointing to
@paulera
paulera / stopwords.md
Created January 30, 2023 13:20
Clean up text data for creating wordclouds

Cleaning up text data for wordcloud

Regular expression replacements to be done in the order presented, for cleaning up words that might interfere in the resulting cloud.

Step Replace... For...
Remove punctuation [;\.\(\)!/"] space
Add space to lines start and end [^|$] space
Remove stopwords [^a-z](share|and|at|by|the|is|that|it|or|to|it's|of|a|an|btw|be|in|if|be|amd|the|just|get|'ll's)[^a-z] space
Break in lines [ \r\n\t]+ \n
@paulera
paulera / run1.bat
Created March 9, 2022 01:47
Batch file to open a program if not yet running, or bring up to focus if it is already.
@if (@X)==(@Y) @end /* JScript comment
@echo off
REM This script runs a command if it is not yet running. Otherwise, it brings
REM the current stance into focus.
REM Usage: run1 [/nostart] <command> <params>
REM /nostart - doesn't use the command "start" to run, causing the prompt to hang
REM
REM Example: run1.bat c:\Windows\notepad.exe c:\User\paulo\Documents\todo.txt
/**
* Mural downloader
*
* Run this script in Google Chrome's console to display buttons for PDF download and a switch for automatic mode.
*
* This requires the extension Ignore X-Frame headers
* https://chrome.google.com/webstore/detail/ignore-x-frame-headers/gleekbfjekiniecknbkamfmkohkpodhe
*
**/
@paulera
paulera / _cleanup-dontkinhooot.tw-wordpress-malware.md
Last active June 15, 2021 19:52
Finding the dontkinhooot.tw malware from WordPress sites and cleaning it manually

Cleaning dontkinhooot.tw malware from WordPress

See here how to disable dontkinhooot.tw malware from a WordPress site manually. Use the instructions below to fix your site temporarily. Then proceed to rebuild your site in an updated WordPress instance. This guide won't guarantee there won't be reinfection.

This malware didn't damage the site or stole data. It redirects the visitor to another site, probably to make money from affiliation programs.

@paulera
paulera / _work-from-home-bingo.md
Last active April 18, 2021 19:13
🏠💻 Working From Home Bingo with 163 possible words and expressions

Yet another WFH bingo 🏠💻

Click to generate a card: http://bit.ly/wfhbingo

Things you can do:

  • Share this link directly and people will generate their own cards.
  • Open the link, click "Generate Card" and share the generated link instead.
  • You can save the link for a specific card to use for multiple days.

This link will generate a card with 24 random words/expressions (out of a total of 163).