Skip to content

Instantly share code, notes, and snippets.

View ashutoshkrris's full-sized avatar
🏠
Learning from home

Ashutosh Krishna ashutoshkrris

🏠
Learning from home
View GitHub Profile
post_data = [1, 'Getting started with Rich', 'Ashutosh Krishna']
post_id = post_data[0]
post_title = post_data[1]
post_author = post_data[2]
print(post_id, post_title, post_author)
@ashutoshkrris
ashutoshkrris / main.py
Created March 23, 2022 03:06
Code file for *args and **kwargs
"""Sum of Two Numbers
def add(x, y):
return x+y
print(add(2, 3))
"""
"""Sum of Three Numbers
def add(x, y, z):
@ashutoshkrris
ashutoshkrris / main.py
Created March 11, 2022 08:33
Sentence Rearrangement Game using Python
from typing import List
from random import shuffle, choice
from rich.console import Console
console = Console()
def get_sentences(filename: str) -> List:
with open(filename) as f:
sentences = list(set(f.read().splitlines()))
@ashutoshkrris
ashutoshkrris / dict-methods.md
Created January 12, 2022 06:53
Dictionary Built-in Methods
Method Description
clear() Removes all items from the dictionary.
copy() Returns a shallow copy of the dictionary.
fromkeys(seq[, v]) Returns a new dictionary with keys from seq and value equal to v (defaults to None).
get(key[,d]) Returns the value of the key. If the key does not exist, returns d (defaults to None).
@ashutoshkrris
ashutoshkrris / Table3.md
Created December 24, 2021 05:21
API Endpoints
HTTP METHOD API ENDPOINT DESCRIPTION
GET /products Get a list of products.
GET /products?limit=x Get only x products.
GET /products/<product_id> Get a single product.
POST /products Create a new product.
PUT /products/<product_id> Update a product.
PATCH /products/<product_id> Partially update a product.
DELETE /products/ Delete a product.
@ashutoshkrris
ashutoshkrris / Table2.md
Created December 24, 2021 05:16
Code Range and Category
CODE RANGE CATEGORY
1XX Informational response
2XX Successful operation
3XX Redirection
4XX Client error
5XX Server error
@ashutoshkrris
ashutoshkrris / Table1.md
Created December 24, 2021 05:13
HTTP Methods and Description
HTTP METHOD DESCRIPTION
GET Retrieve existing data
POST Add new data
PUT Update existing data
PATCH Partially update existing data
DELETE Delete data
@ashutoshkrris
ashutoshkrris / main.py
Last active August 21, 2023 23:37
Know your horoscope using Python
import requests
from bs4 import BeautifulSoup
def get_horoscope(zodiac_sign: int, day: str):
if not "-" in day:
res = requests.get(
f"https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{day}.aspx?sign={zodiac_sign}")
else:
day = day.replace("-", "")
@ashutoshkrris
ashutoshkrris / routes.py
Created August 14, 2021 10:02
Redirect to original URL
@app.route('/<short_id>')
def redirect_url(short_id):
link = ShortUrls.query.filter_by(short_id=short_id).first()
if link:
return redirect(link.original_url)
else:
flash('Invalid URL')
return redirect(url_for('index'))
from datetime import datetime
from app.models import ShortUrls
from app import app, db
from flask import render_template, request, flash, redirect, url_for
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
url = request.form['url']
short_id = request.form['custom_id']