Skip to content

Instantly share code, notes, and snippets.

View ranabhat's full-sized avatar
🎯
Focusing

Paribesh Ranabhat ranabhat

🎯
Focusing
View GitHub Profile
@ranabhat
ranabhat / Dockerfile
Created January 20, 2023 07:36 — forked from BretFisher/Dockerfile
Multi-stage Dockerfile example of installing dependencies with COPY --from
# any images you use later, add them here first to create aliases
# I like keeping all my versions at the top
FROM node:14.3-slim as node
FROM php:7.2.1-fpm-slim as php
FROM nginx:1.17 as nginx
# The real base image to start from
FROM ubuntu:focal-20210827 as base
# install apt stuff
import asyncio
loop = asyncio.get_event_loop()
async def hello():
await asyncio.sleep(3)
print('Hello!')
if __name__ == '__main__':
loop.run_until_complete(hello())
@ranabhat
ranabhat / list_comprehension.md
Created November 6, 2020 10:27
List Comprehension Formula

Simple list comprehensions

  • Problem
y = [0,1,2,3,4,5,6,7,8,9]
squares = []
for i in  y:
    squares.append(i**2)
print squares
  • Formula: [ expression-involving-loop-variableforloop-variableinsequence]
@ranabhat
ranabhat / pyenv_installation.md
Created November 6, 2020 10:26
Quick Guide to install Pyenv **tool for managing multiple Python versions**

Pyenv Installation

Ubuntu Installation

  1. Install build dependencies sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \ libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
  2. Install pyenv curl https://pyenv.run | bash
  3. Add following lines to ~/.bashrc
export PYENV_ROOT="$HOME/.pyenv"
@ranabhat
ranabhat / pipenv_python_packaging_tool.md
Created November 6, 2020 10:24
Allow for deterministic builds for your Python project without gaining the responsibility of updating versions of sub-dependencies.

Basic Usage

  1. Install pipenv pip install pipenv
  2. Create a directory say hello where you are going to create your python project.
  3. Go inside the directory cd hello
  4. Create a virtual env using command pipenv --python 3.7 (Specify which version of python you need)
  5. Alternative to 4 enter command pipenv shell. This case pipenv will use whatever default virtualenv finds.

This will create Pipfile and Pipfile.lock

  1. Install packages you need, say numpy pipenv install numpy
@ranabhat
ranabhat / do_get_git_public_repo_name.py
Last active March 29, 2024 06:08
Simple example on how to use web APIs in Python3.
import requests # importing libraries for working with HTTP requests
import json
api_url_base = 'https://api.github.com/' # string that starts off every URL in the GitHub API
#response = requests.get(api_url_base)
#print(response.headers)
headers = {'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3+json'
}