2019-10-31

Sublime Text - Copy columns of text on MacOS

1. Press the option key and at the same time left click where you want to start copying.
2. Drag until your selection is done.
3. Copy
4. Paste somewhere else

2019-09-10

GIT - How to remove history for already deleted files

# Mirror the repository and get inside its directory
cd ~/Documents/mirrored_repository_name_here.git

# Display the biggest files, which might help figure out what to remove
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4 | tail -n 10

# Get outside of the folder
cd ..

# Run BFG (in the desktop in this example) to delta files of a certain extension 
java -jar ~/Desktop/bfg.jar --delete-files *.zip  --no-blob-protection mirrored_repository_name_here.git

# Run BFG to delete folders
java -jar ~/Desktop/bfg.jar --delete-folders data  --no-blob-protection mirrored_repository_name_here.git

# Remove those files
git reflog expire --expire=now --all && git gc --prune=now --aggressive

# Check on the size of the repository
git count-objects -v

# Push it

git push --force



2019-09-08

Python - Get string in between two other sub-strings

import re
s = 'STRING_PART_1This is the text you will getSTRING_PART_2'
result = re.search('STRING_PART_1(.*)STRING_PART_2', s)
print result.group(1)

MongoDB - Shutdown from the command line

mongo --eval "db.getSiblingDB('admin').shutdownServer()"

2019-08-28

Python - List of lists to CSV

import csv

# Data
headers = ['Header1', 'Header2', 'Header3']
rows = [[1,2,3], [5,6,7]]

# Open a file to append to
with open('/path/target_file.txt', 'a') as f:

    # CSV writer instantiation
    writer = csv.writer(
    f
    # Settings
    , quoting=csv.QUOTE_NONE
    , delimiter='\t'
    )

    # Headers
    writer.writerow(headers)

    # All rows
    writer.writerows(rows)

2019-08-05

MongoDB - Retrieve only matching sub-documents

db.collection.find(

    // Match
    {
        "subdocument_to_search_within":  {
        "$elemMatch": {
                "field_within_the_subdocument": 100
            }
    }
    , "other_filter": 1
    }

    // Projection
, {
        "subdocument_to_search_within.$": 1
    }
);

2019-07-27