This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
timeout = 40 # Set timeout to 40 seconds | |
with open('items.txt', 'r') as file: | |
items = file.read().strip().split('\n') | |
for item in items: | |
item = item.strip() # Clean up any extra whitespace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def extract_json_from_text(text): | |
# Find the first '{' character | |
start = text.find('{') | |
if start == -1: | |
print("No JSON block found in the text.") | |
return None | |
# Use a stack to track nested braces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install python-dotenv | |
import os | |
from dotenv import find_dotenv, load_dotenv | |
# load variables from .env | |
load_dotenv(find_dotenv(usecwd=True)) | |
MY_VAR = os.getenv("MY_VAR") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A function allows to generate json key file used by google api from environment variables. Example of `.env` file: | |
``` | |
TYPE="my_service_account" | |
PROJECT_ID="my_project_id" | |
PRIVATE_KEY_ID="my_private_key_id" | |
PRIVATE_KEY="-----BEGIN PRIVATE KEY----- | |
my_private_key_content | |
-----END PRIVATE KEY----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from typing import Any, Dict, List | |
import spacy | |
from spacy.training.iob_utils import biluo_to_iob, doc_to_biluo_tags | |
from tqdm import tqdm | |
def spans_to_conll( | |
samples: List[Dict[str, Any]], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fix_span(text: str, span: dict): | |
# let us check that spans are correctly extracted | |
fixed_span = span.copy() | |
# span starts with a space or a punctuation | |
while text[fixed_span["start"]] in [" ", ".", ",", ";", ":", "!", "?"]: | |
fixed_span["start"] += 1 | |
# span is cut in the begging: e.g. "ashington DC" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p ~/.ssh | |
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts | |
ssh-keygen -t rsa -C <email> | |
cat ~/.ssh/id_rsa.pub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import statsmodels.api as sm | |
X = np.array([[1, 85, 5], | |
[1, 177, 6], | |
[1, 100, 9], | |
[1, 110, 8], | |
[1, 90, 7.5], | |
[1, 144, 5.5]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 | |
!sudo update-alternatives --config python3 | |
!sudo apt install python3-pip | |
!python3 --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df = pd.DataFrame({'name': ['Store A', 'Store B', 'Store C', 'Store D'] | |
'district': ['I', "II", "I", "III"], | |
"category": [X, X, Y, Z] | |
} | |
) | |
district_category_pivot_table = df.pivot_table('name', 'district', 'category', aggfunc='count') |
NewerOlder