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
@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']
{% extends 'base.html' %}
{% block content %}
<h1 class="text-center mb-3">{% block title %} Welcome to Shorty {% endblock %}</h1>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<form method="post" action="{{url_for('index')}}">
<div class="form-floating mb-3">
<input type="text" name="url" id="url"
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">