Skip to content

Instantly share code, notes, and snippets.

@egordm
Last active April 15, 2021 16:03
Show Gist options
  • Save egordm/17d6531711476e533407002206534d2a to your computer and use it in GitHub Desktop.
Save egordm/17d6531711476e533407002206534d2a to your computer and use it in GitHub Desktop.
Google Collab Snippets
#@title Load cached dataset from google drive
drive_project_root = "MyDrive/Colab" #@param {type:"string"}
dataset_name = "stanford40_augmented.tar.gz" #@param {type:"string"}
import os
from google.colab import drive
drive.mount('/content/drive')
drive_dataset_path = os.path.join('/content/drive', drive_project_root, dataset_name)
!test -e $drive_dataset_path \
&& echo 'Extracting the cached dataset' \
&& cp $drive_dataset_path $dataset_name \
&& tar -xzf $dataset_name
#@title Cache the processed dataset { display-mode: "form" }
dataset_dir = "datasets/Stanford40/baked" #@param {type:"string"}
!test ! -e $drive_dataset_path \
&& echo 'Compressing the dataset' \
&& GZIP=-9 tar --totals=USR1 -czf $dataset_name $dataset_dir \
&& echo 'Copying cache to drive' \
&& cp $dataset_name $drive_dataset_path
#@title Clone Private Repo Snippet { display-mode: "form" }
#@markdown ```
#@markdown # Generate a key with, adn add pub key to your git repo
#@markdown ssh-keygen -t rsa -b 2048 -C "[email protected]" -m pem -f ./collab_pk
#@markdown # Then paste the output of the following command "private_key" field
#@markdown python -c 'print("\""+open("collab_pk", "r").read().replace("\n", "\\n")+"\"")'
#@markdown ```
repository = "[email protected]:user/repo.git" #@param {type:"string"}
private_key = "paste your private key here"#@param {type:"raw"}
# ================= SKIP IF YOU DONT USE GOOGLE COLLAB =============================
try:
import google.colab
key = private_key
!mkdir -p /root/.ssh
with open(r'/root/.ssh/id_rsa', 'w', encoding='utf8') as fh:
fh.write(key)
!chmod 600 /root/.ssh/id_rsa
!ssh-keyscan github.com >> /root/.ssh/known_hosts
!git clone $repository
except:
print('>:|')
# ================= SKIP IF YOU DONT USE GOOGLE COLLAB =============================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment