Skip to content

Instantly share code, notes, and snippets.

View ruslanmv's full-sized avatar
😃

Ruslan Magana Vsevolodovna ruslanmv

😃
View GitHub Profile
@ruslanmv
ruslanmv / Python-Compre-Iter.py
Created December 25, 2021 10:31
Tricks with Comprehensive and Iteration in Python
## Comprehensive -----
strings = ['a', 'as', 'bat', 'car', 'dove', 'python']
[x.upper() for x in strings if len(x) > 2] ## list comprehensive
{x.upper() for x in strings if len(x) > 2} ## set comprehensive
{key: val.upper() for key,val in enumerate(strings)} ## dict comprehensive
## Nested Comprehensive ----
all_data = [['John', 'Emily', 'Michael', 'Mary', 'Steven'],
['Maria', 'Juan', 'Javier', 'Natalia', 'Pilar', 'Eerin']]
## full
@ruslanmv
ruslanmv / Python-googleapi-vision-face.py
Created December 25, 2021 10:33
Call googleapi vision, use the FACE_DETECTION, output the likelihood of happy/unhappy
## Install this in terminal: !pip install --upgrade google-api-python-client
## This func to call googleapi, apply the face_detection on img, and output the happy/unhappy likelihood
def detect_joy(IMG):
from googleapiclient.discovery import build
vservice = build('vision', 'v1', developerKey=APIKEY)
## CHECK THIS: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate
## The have the interactive tool to create the body of request
request = vservice.images().annotate(body={
"requests": [
@ruslanmv
ruslanmv / Python-read-data.py
Created December 25, 2021 10:35
Read csv, html, xml, hdf5, api Data to Python
## Import modules
import pandas as pd
import numpy as np
import scipy as sp
import pandas_datareader.data as web
from datetime import datetime as dt ## datetime
import json ## json
import requests ## API
from lxml import objectify
import os
@ruslanmv
ruslanmv / Google-Cloud-Shell-commands.txt
Created February 14, 2022 16:09
Google Cloud Shell via gsutil in Command Line - Commands
pwd
ls
gcloud config list
gsutil ls
gsutil ls gs://storage-lab-console/
gsutil ls gs://storage-lab-console/**
gsutil mb --help
@ruslanmv
ruslanmv / Google_Compute_Engine_commands.txt
Created February 17, 2022 11:39
Google Compute Engine commands
gcloud config get-value project
gcloud compute instances list
gcloud services list
gcloud services list -h
gcloud services list --enabled
gcloud services list --available
gcloud services list --available | grep compute
@ruslanmv
ruslanmv / python-offline.txt
Created March 8, 2022 23:02
How to install packages offline
On the system that has access to internet
The pip download command lets you download packages without installing them:
pip download -r requirements.txt
(In previous versions of pip, this was spelled pip install --download -r requirements.txt.)
On the system that has no access to internet
Then you can use
@ruslanmv
ruslanmv / install_docker.sh
Last active August 31, 2022 19:23
AWS EC2 Instance Docker on Ubuntu Installation
sudo apt-get -y update
sudo apt-get -y install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
@ruslanmv
ruslanmv / Dockerfile
Last active September 1, 2022 08:35
AWS Pyspark Docker Container
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/scipy-notebook
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"
# Fix DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
@ruslanmv
ruslanmv / environment_variables.py
Created September 6, 2022 22:13
Environment variables in python
import os
print(os.environ['HOME'])
#To see a list of all environment variables:
print(os.environ)
# Returns `None` if key doesn't exist
print(os.environ.get('KEY_THAT_MIGHT_EXIST'))
# Returns `default_value` if key doesn't exist
@ruslanmv
ruslanmv / install_git-lfs.sh
Last active September 11, 2022 22:47
Install git-lfs on Sagemaker / EC2 Instances with Linux AMI 2
#!/bin/bash
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
sudo yum install git-lfs -y
git lfs install