├── .gitignore ├── Introduction_To_Computer_Science ├── README.md ├── Week01_C │ ├── credit.c │ ├── mario-more.c │ └── population.c ├── Week02_Arrays │ ├── caesar.c │ ├── readability.c │ └── scrabble.c ├── Week03_Algorithms │ ├── plurality.c │ └── runoff.c ├── Week04_Memory │ ├── filter-more │ │ ├── Makefile │ │ ├── bmp.h │ │ ├── filter │ │ ├── filter.c │ │ ├── helpers.c │ │ ├── helpers.h │ │ ├── images │ │ │ ├── courtyard.bmp │ │ │ ├── stadium.bmp │ │ │ ├── tower.bmp │ │ │ └── yard.bmp │ │ └── out.bmp │ ├── recover │ │ ├── card.raw │ │ ├── recover │ │ └── recover.c │ └── smiley │ │ ├── Makefile │ │ ├── bmp.h │ │ ├── colorize │ │ ├── colorize.c │ │ ├── helpers.c │ │ ├── helpers.h │ │ ├── output.bmp │ │ └── smiley.bmp ├── Week05_DataStructures │ ├── inheritance.c │ └── speller │ │ ├── Makefile │ │ ├── dictionaries │ │ ├── large │ │ └── small │ │ ├── dictionary.c │ │ ├── dictionary.h │ │ ├── dictionary.o │ │ ├── inheritance.zip │ │ ├── keys │ │ ├── aca.txt │ │ ├── austen.txt │ │ ├── birdman.txt │ │ ├── burnett.txt │ │ ├── carroll.txt │ │ ├── cat.txt │ │ ├── constitution.txt │ │ ├── federalist.txt │ │ ├── frankenstein.txt │ │ ├── grimm.txt │ │ ├── her.txt │ │ ├── holmes.txt │ │ ├── homer.txt │ │ ├── lalaland.txt │ │ ├── mansfield.txt │ │ ├── pneumonoultramicroscopicsilicovolcanoconiosis.txt │ │ ├── revenant.txt │ │ ├── rinehart.txt │ │ ├── shakespeare.txt │ │ ├── stein.txt │ │ ├── stoker.txt │ │ ├── surgery.txt │ │ ├── tolstoy.txt │ │ ├── wells.txt │ │ ├── whittier.txt │ │ ├── wordsworth.txt │ │ ├── xueqin1.txt │ │ └── xueqin2.txt │ │ ├── speller │ │ ├── speller.c │ │ ├── speller.o │ │ ├── speller50 │ │ └── texts │ │ ├── aca.txt │ │ ├── austen.txt │ │ ├── birdman.txt │ │ ├── burnett.txt │ │ ├── carroll.txt │ │ ├── cat.txt │ │ ├── constitution.txt │ │ ├── federalist.txt │ │ ├── frankenstein.txt │ │ ├── grimm.txt │ │ ├── her.txt │ │ ├── holmes.txt │ │ ├── homer.txt │ │ ├── lalaland.txt │ │ ├── mansfield.txt │ │ ├── pneumonoultramicroscopicsilicovolcanoconiosis.txt │ │ ├── revenant.txt │ │ ├── rinehart.txt │ │ ├── shakespeare.txt │ │ ├── stein.txt │ │ ├── stoker.txt │ │ ├── surgery.txt │ │ ├── tolstoy.txt │ │ ├── wells.txt │ │ ├── whittier.txt │ │ ├── wordsworth.txt │ │ ├── xueqin1.txt │ │ └── xueqin2.txt ├── Week06_Python │ ├── credit.py │ ├── mario.py │ └── readability.py ├── Week07_SQL │ └── songs │ │ ├── 1.sql │ │ ├── 2.sql │ │ ├── 3.sql │ │ ├── 4.sql │ │ ├── 5.sql │ │ ├── 6.sql │ │ ├── 7.sql │ │ ├── 8.sql │ │ ├── answers.txt │ │ └── songs.db ├── Week08_Html_CSS_JS │ ├── homepage │ │ ├── index.html │ │ └── styles.css │ └── trivia │ │ ├── index.html │ │ ├── script.js │ │ └── styles.css └── Week09_Flask │ ├── birthdays │ ├── app.py │ ├── birthdays.db │ ├── static │ │ └── styles.css │ └── templates │ │ └── index.html │ └── finance │ ├── app.py │ ├── finance.db │ ├── helpers.py │ ├── requirements.txt │ ├── static │ ├── favicon.ico │ └── styles.css │ └── templates │ ├── apology.html │ ├── buy.html │ ├── history.html │ ├── index.html │ ├── layout.html │ ├── login.html │ ├── quote.html │ ├── quoted.html │ ├── register.html │ └── sell.html ├── Introduction_To_Programming_with_Python ├── .gitignore ├── ProblemSet_00 │ ├── einstein │ │ └── einstein.py │ ├── faces │ │ └── faces.py │ ├── indoor │ │ └── indoor.py │ ├── playback │ │ └── playback.py │ └── tip │ │ └── tip.py ├── ProblemSet_01 │ ├── bank │ │ └── bank.py │ ├── deep │ │ └── deep.py │ ├── extensions │ │ └── extensions.py │ ├── interpreter │ │ └── interpreter.py │ └── meal │ │ └── meal.py ├── ProblemSet_02 │ ├── camel │ │ └── camel.py │ ├── coke │ │ └── coke.py │ ├── foo │ ├── nutrition │ │ └── nutrition.py │ ├── plates │ │ └── plates.py │ └── twttr │ │ └── twttr.py ├── ProblemSet_03 │ ├── fuel │ │ └── fuel.py │ ├── grocery │ │ └── grocery.py │ ├── outdated │ │ └── outdated.py │ └── taqueria │ │ └── taqueria.py ├── ProblemSet_04 │ ├── adieu │ │ └── adieu.py │ ├── bitcoin │ │ └── bitcoin.py │ ├── emojize │ │ └── emojize.py │ ├── figlet │ │ └── figlet.py │ ├── game │ │ └── game.py │ └── professor │ │ └── professor.py ├── ProblemSet_05 │ ├── .gitignore │ ├── test_bank │ │ ├── bank.py │ │ └── test_bank.py │ ├── test_fuel │ │ ├── fuel.py │ │ └── test_fuel.py │ ├── test_plates │ │ ├── plates.py │ │ └── test_plates.py │ └── test_twttr │ │ ├── test_twttr.py │ │ └── twttr.py ├── ProblemSet_06 │ ├── lines │ │ └── lines.py │ ├── pizza │ │ ├── pizza.py │ │ └── sicilian.csv │ ├── scourgify │ │ ├── after.csv │ │ ├── before.csv │ │ └── scourgify.py │ └── shirt │ │ ├── shirt.png │ │ └── shirt.py ├── ProblemSet_07 │ ├── numb3rs │ │ ├── __pycache__ │ │ │ ├── numb3rs.cpython-310.pyc │ │ │ └── test_numb3rs.cpython-310-pytest-7.4.4.pyc │ │ ├── numb3rs.py │ │ └── test_numb3rs.py │ ├── response │ │ ├── response.py │ │ └── test_response.py │ ├── um │ │ ├── test_um.py │ │ └── um.py │ ├── watch │ │ └── watch.py │ └── working │ │ ├── __pycache__ │ │ ├── test_working.cpython-310-pytest-7.4.4.pyc │ │ └── working.cpython-310.pyc │ │ ├── test_working.py │ │ └── working.py ├── ProblemSet_08 │ ├── jar │ │ ├── jar.py │ │ └── test_jar.py │ ├── seasons │ │ ├── seasons.py │ │ └── test_seasons.py │ └── shirtificate │ │ ├── shirtificate.pdf │ │ ├── shirtificate.png │ │ └── shirtificate.py ├── README.md └── final_project │ ├── README.md │ ├── __init__.py │ ├── project.py │ ├── requirements.txt │ └── test_project.py ├── LICENSE ├── README.md └── Web_Programming_With_Python_And_JavaScript ├── .gitignore ├── Project00_Search ├── advanced_search.html ├── imghp.html ├── index.html └── style.css ├── Project01_Wiki ├── encyclopedia │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── static │ │ └── encyclopedia │ │ │ └── styles.css │ ├── templates │ │ └── encyclopedia │ │ │ ├── edit_entry.html │ │ │ ├── entry.html │ │ │ ├── error.html │ │ │ ├── index.html │ │ │ ├── layout.html │ │ │ └── new_entry.html │ ├── tests.py │ ├── urls.py │ ├── util.py │ └── views.py ├── entries │ ├── CSS.md │ ├── Django.md │ ├── Git.md │ ├── HTML.md │ └── Python.md ├── manage.py └── wiki │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── Project02_Commerce ├── auctions │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_auction_bid_comment.py │ │ ├── 0003_comment_auction.py │ │ ├── 0004_auction_cover_image.py │ │ ├── 0005_alter_auction_cover_image.py │ │ ├── 0006_alter_auction_cover_image.py │ │ ├── 0007_alter_auction_cover_image.py │ │ ├── 0008_alter_auction_cover_image.py │ │ ├── 0009_remove_auction_cover_image_auction_category_and_more.py │ │ ├── 0010_auction_status.py │ │ └── __init__.py │ ├── models.py │ ├── static │ │ └── auctions │ │ │ └── styles.css │ ├── templates │ │ └── auctions │ │ │ ├── create_listing.html │ │ │ ├── index.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ ├── register.html │ │ │ └── view_listing.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── commerce │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── images │ ├── 91PeFpf5NNL._AC_UF10001000_QL80_.jpg │ └── Untitled.jpeg └── manage.py ├── Project03_Mail ├── mail │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ ├── models.py │ ├── static │ │ └── mail │ │ │ ├── inbox.js │ │ │ └── styles.css │ ├── templates │ │ └── mail │ │ │ ├── inbox.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ └── register.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── manage.py └── project3 │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── Project04_Network ├── manage.py ├── network │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_follow_post_like.py │ │ └── __init__.py │ ├── models.py │ ├── static │ │ └── network │ │ │ └── styles.css │ ├── templates │ │ └── network │ │ │ ├── following.html │ │ │ ├── index.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ ├── post_list.html │ │ │ ├── profile.html │ │ │ └── register.html │ ├── tests.py │ ├── urls.py │ └── views.py └── project4 │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | secret.txt -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/README.md: -------------------------------------------------------------------------------- 1 | ## CS50's Introduction to Computer Science 2 | 3 | Started: Dec 10 2023 4 | Ended: Dec 14 2023 5 | 6 | | Submissions | Lecture(s) | 7 | |-----------------------------------------------------------------|-------------------------------| 8 | | [Simple Pong Game](https://scratch.mit.edu/projects/937971609/) | Week 0: Scratch | 9 | | [Credit, Mario (more), Population](./Week01_C) | Week 1: C | 10 | | [Caesar, Readability, Scrabble](./Week02_Arrays) | Week 2: Arrays | 11 | | [Plularity, Runoff](./Week03_Algorithms) | Week 3: Algorithms | 12 | | [Volume, Filter (More), Recover](./Week04_Memory) | Week 4: Memory | 13 | | [Inheritence, Speller](./Week05_DataStructures) | Week 5: Data Structures | 14 | | [Credit, Mario, Readability](./Week06_Python) | Week 6: Python | 15 | | [Songs](./Week07_SQL) | Week 7: SQL | 16 | | [Homepage, Trivia](./Week08_Html_CSS_JS) | Week 8: HTML, CSS, JavaScript | 17 | | [Birthdays, Finance](./Week09_Flask) | Week 9: Flask | 18 | 19 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week01_C/credit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | string card_number; 8 | do 9 | { 10 | card_number = get_string("Number: "); 11 | } 12 | while (card_number == NULL || strlen(card_number) == 0); 13 | 14 | int sum = 0; 15 | int digit_count = 0; 16 | 17 | for (int i = strlen(card_number) - 1; i >= 0; i--) 18 | { 19 | int digit = card_number[i] - '0'; 20 | 21 | if (digit_count % 2 == 1) 22 | { 23 | digit *= 2; 24 | 25 | if (digit > 9) 26 | { 27 | digit = digit % 10 + 1; 28 | } 29 | } 30 | 31 | sum += digit; 32 | digit_count++; 33 | } 34 | 35 | if (sum % 10 == 0) 36 | { 37 | if ((strlen(card_number) == 15) && 38 | (strncmp(card_number, "34", 2) == 0 || strncmp(card_number, "37", 2) == 0)) 39 | { 40 | printf("amex\n"); 41 | } 42 | else if ((strlen(card_number) == 16) && 43 | (strncmp(card_number, "51", 2) == 0 || strncmp(card_number, "52", 2) == 0 || 44 | strncmp(card_number, "53", 2) == 0 || strncmp(card_number, "54", 2) == 0 || 45 | strncmp(card_number, "55", 2) == 0)) 46 | { 47 | printf("mastercard\n"); 48 | } 49 | else if ((strlen(card_number) == 13 || strlen(card_number) == 16) && 50 | strncmp(card_number, "4", 1) == 0) 51 | { 52 | printf("visa\n"); 53 | } 54 | else 55 | { 56 | printf("invalid\n"); 57 | } 58 | } 59 | else 60 | { 61 | printf("invalid\n"); 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week01_C/mario-more.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void print_p(int i, int height) 5 | { 6 | int hc = i + 1; 7 | int sc = height - (i + 1); 8 | 9 | for (int j = 0; j < sc; j++) 10 | { 11 | putc(' ', stdout); 12 | } 13 | 14 | for (int j = 0; j < hc; j++) 15 | { 16 | putc('#', stdout); 17 | } 18 | 19 | putc(' ', stdout); 20 | putc(' ', stdout); 21 | 22 | for (int j = 0; j < hc; j++) 23 | { 24 | putc('#', stdout); 25 | } 26 | } 27 | 28 | int main(void) 29 | { 30 | int height; 31 | 32 | do 33 | { 34 | height = get_int("Height: "); 35 | } while (height < 1 || height > 8); 36 | 37 | for (int i = 0; i < height; i++) 38 | { 39 | print_p(i, height); 40 | printf("\n"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week01_C/population.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define DEATH_RATE 4 5 | #define BORN_RATE 3 6 | 7 | int main(void) 8 | { 9 | int start_size; 10 | do 11 | { 12 | start_size = get_int("start size: "); 13 | } 14 | while (start_size < 9); 15 | 16 | int end_size; 17 | do 18 | { 19 | end_size = get_int("end size: "); 20 | } 21 | while (end_size < start_size); 22 | 23 | int years = 0; 24 | while (start_size < end_size) 25 | { 26 | int llama_born = start_size / BORN_RATE; 27 | int llama_passed = start_size / DEATH_RATE; 28 | start_size = start_size + llama_born - llama_passed; 29 | years++; 30 | } 31 | 32 | printf("Years: %d\n", years); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week02_Arrays/caesar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | bool only_digits(string s); 8 | char rotate(char c, int key); 9 | 10 | int main(int argc, string argv[]) 11 | { 12 | if (argc != 2) 13 | { 14 | printf("Usage: ./caesar key\n"); 15 | return 1; 16 | } 17 | 18 | if (!only_digits(argv[1])) 19 | { 20 | printf("Usage: ./caesar key\n"); 21 | return 1; 22 | } 23 | 24 | int offset = atoi(argv[1]); 25 | string input = get_string("plaintext: "); 26 | 27 | const string lower = "abcdefghijklmnopqrstuvwxyz"; 28 | const string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 29 | const int max = 26; 30 | 31 | printf("ciphertext: "); 32 | for (int i = 0; i < strlen(input); i++) 33 | { 34 | char current = input[i]; 35 | if (isalpha(current)) 36 | { 37 | char base = isupper(current) ? 'A' : 'a'; 38 | int idx = (current - base + offset) % max; 39 | printf("%c", isupper(current) ? upper[idx] : lower[idx]); 40 | } 41 | else 42 | { 43 | printf("%c", current); 44 | } 45 | } 46 | 47 | printf("\n"); 48 | return 0; 49 | } 50 | 51 | bool only_digits(string s) 52 | { 53 | for (int i = 0; s[i] != '\0'; i++) 54 | { 55 | if (!isdigit(s[i])) 56 | { 57 | return false; 58 | } 59 | } 60 | return true; 61 | } 62 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week02_Arrays/readability.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int count_letters(string text); 7 | int count_words(string text); 8 | int count_sentences(string text); 9 | int getGradeLevel(int letters, int words, int sentences); 10 | 11 | int main(void) 12 | { 13 | string text = get_string("Text: "); 14 | 15 | int cl = count_letters(text), 16 | cw = count_words(text), 17 | cs = count_sentences(text); 18 | 19 | int grade_level = getGradeLevel(cl, cw, cs); 20 | 21 | if (grade_level < 1) 22 | { 23 | printf("Before Grade 1\n"); 24 | } 25 | else if (grade_level >= 16) 26 | { 27 | printf("Grade 16+\n"); 28 | } 29 | else 30 | { 31 | printf("Grade %d\n", grade_level); 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | int count_letters(string text) 38 | { 39 | int count = 0; 40 | 41 | for (int i = 0, n = strlen(text); i < n; i++) 42 | { 43 | if (isalpha(text[i])) 44 | { 45 | count++; 46 | } 47 | } 48 | 49 | return count; 50 | } 51 | 52 | int count_words(string text) 53 | { 54 | int count = 1; 55 | 56 | for (int i = 0, n = strlen(text); i < n; i++) 57 | { 58 | if (isspace(text[i])) 59 | { 60 | count++; 61 | } 62 | } 63 | 64 | return count; 65 | } 66 | 67 | int count_sentences(string text) 68 | { 69 | int count = 0; 70 | 71 | for (int i = 0, n = strlen(text); i < n; i++) 72 | { 73 | if (text[i] == '.' || text[i] == '!' || text[i] == '?') 74 | { 75 | count++; 76 | } 77 | } 78 | 79 | return count; 80 | } 81 | 82 | int getGradeLevel(int letters, int words, int sentences) 83 | { 84 | float L = (float) letters / words * 100; 85 | float S = (float) sentences / words * 100; 86 | 87 | return round(0.0588 * L - 0.296 * S - 15.8); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week02_Arrays/scrabble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10}; 6 | 7 | int compute_score(string s); 8 | 9 | int main(void) 10 | { 11 | string word1 = get_string("Player 1: "); 12 | string word2 = get_string("Player 2: "); 13 | 14 | int score1 = compute_score(word1); 15 | int score2 = compute_score(word2); 16 | 17 | if (score1 == score2) 18 | { 19 | printf("Tie!\n"); 20 | } 21 | else if (score1 > score2) 22 | { 23 | printf("Player 1 wins!\n"); 24 | } 25 | else 26 | { 27 | printf("Player 2 wins!\n"); 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | int compute_score(string s) 34 | { 35 | int score = 0; 36 | 37 | for (int i = 0; s[i] != '\0'; i++) 38 | { 39 | if (isalpha(s[i])) 40 | { 41 | score += POINTS[tolower(s[i]) - 'a']; 42 | } 43 | } 44 | 45 | return score; 46 | } 47 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week03_Algorithms/plurality.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Max number of candidates 6 | #define MAX 9 7 | 8 | // Candidates have name and vote count 9 | typedef struct 10 | { 11 | string name; 12 | int votes; 13 | } candidate; 14 | 15 | // Array of candidates 16 | candidate candidates[MAX]; 17 | 18 | // Number of candidates 19 | int candidate_count; 20 | 21 | // Function prototypes 22 | bool vote(string name); 23 | void print_winner(void); 24 | 25 | int main(int argc, string argv[]) 26 | { 27 | // Check for invalid usage 28 | if (argc < 2) 29 | { 30 | printf("Usage: plurality [candidate ...]\n"); 31 | return 1; 32 | } 33 | 34 | // Populate array of candidates 35 | candidate_count = argc - 1; 36 | if (candidate_count > MAX) 37 | { 38 | printf("Maximum number of candidates is %i\n", MAX); 39 | return 2; 40 | } 41 | for (int i = 0; i < candidate_count; i++) 42 | { 43 | candidates[i].name = argv[i + 1]; 44 | candidates[i].votes = 0; 45 | } 46 | 47 | int voter_count = get_int("Number of voters: "); 48 | 49 | // Loop over all voters 50 | for (int i = 0; i < voter_count; i++) 51 | { 52 | string name = get_string("Vote: "); 53 | 54 | // Check for invalid vote 55 | if (!vote(name)) 56 | { 57 | printf("Invalid vote.\n"); 58 | } 59 | } 60 | 61 | // Display winner of election 62 | print_winner(); 63 | } 64 | 65 | // Update vote totals given a new vote 66 | bool vote(string name) 67 | { 68 | for (int i = 0; i < candidate_count; i++) 69 | { 70 | if (strcmp(candidates[i].name, name) == 0) 71 | { 72 | candidates[i].votes++; 73 | return true; 74 | } 75 | } 76 | return false; 77 | } 78 | 79 | // Print the winner (or winners) of the election 80 | void print_winner(void) 81 | { 82 | int max_votes = 0; 83 | for (int i = 0; i < candidate_count; i++) 84 | { 85 | if (candidates[i].votes > max_votes) 86 | { 87 | max_votes = candidates[i].votes; 88 | } 89 | } 90 | 91 | for (int i = 0; i < candidate_count; i++) 92 | { 93 | if (candidates[i].votes == max_votes) 94 | { 95 | printf("%s\n", candidates[i].name); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/Makefile: -------------------------------------------------------------------------------- 1 | filter: 2 | clang -ggdb3 -gdwarf-4 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-gnu-folding-constant -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -lm -o filter filter.c helpers.c 3 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/bmp.h: -------------------------------------------------------------------------------- 1 | // BMP-related data types based on Microsoft's own 2 | 3 | #include 4 | 5 | /** 6 | * Common Data Types 7 | * 8 | * The data types in this section are essentially aliases for C/C++ 9 | * primitive data types. 10 | * 11 | * Adapted from http://msdn.microsoft.com/en-us/library/cc230309.aspx. 12 | * See http://en.wikipedia.org/wiki/Stdint.h for more on stdint.h. 13 | */ 14 | typedef uint8_t BYTE; 15 | typedef uint32_t DWORD; 16 | typedef int32_t LONG; 17 | typedef uint16_t WORD; 18 | 19 | /** 20 | * BITMAPFILEHEADER 21 | * 22 | * The BITMAPFILEHEADER structure contains information about the type, size, 23 | * and layout of a file that contains a DIB [device-independent bitmap]. 24 | * 25 | * Adapted from http://msdn.microsoft.com/en-us/library/dd183374(VS.85).aspx. 26 | */ 27 | typedef struct 28 | { 29 | WORD bfType; 30 | DWORD bfSize; 31 | WORD bfReserved1; 32 | WORD bfReserved2; 33 | DWORD bfOffBits; 34 | } __attribute__((__packed__)) 35 | BITMAPFILEHEADER; 36 | 37 | /** 38 | * BITMAPINFOHEADER 39 | * 40 | * The BITMAPINFOHEADER structure contains information about the 41 | * dimensions and color format of a DIB [device-independent bitmap]. 42 | * 43 | * Adapted from http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx. 44 | */ 45 | typedef struct 46 | { 47 | DWORD biSize; 48 | LONG biWidth; 49 | LONG biHeight; 50 | WORD biPlanes; 51 | WORD biBitCount; 52 | DWORD biCompression; 53 | DWORD biSizeImage; 54 | LONG biXPelsPerMeter; 55 | LONG biYPelsPerMeter; 56 | DWORD biClrUsed; 57 | DWORD biClrImportant; 58 | } __attribute__((__packed__)) 59 | BITMAPINFOHEADER; 60 | 61 | /** 62 | * RGBTRIPLE 63 | * 64 | * This structure describes a color consisting of relative intensities of 65 | * red, green, and blue. 66 | * 67 | * Adapted from http://msdn.microsoft.com/en-us/library/aa922590.aspx. 68 | */ 69 | typedef struct 70 | { 71 | BYTE rgbtBlue; 72 | BYTE rgbtGreen; 73 | BYTE rgbtRed; 74 | } __attribute__((__packed__)) 75 | RGBTRIPLE; 76 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/filter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/filter-more/filter -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/helpers.h: -------------------------------------------------------------------------------- 1 | #include "bmp.h" 2 | 3 | // Convert image to grayscale 4 | void grayscale(int height, int width, RGBTRIPLE image[height][width]); 5 | 6 | // Reflect image horizontally 7 | void reflect(int height, int width, RGBTRIPLE image[height][width]); 8 | 9 | // Detect edges 10 | void edges(int height, int width, RGBTRIPLE image[height][width]); 11 | 12 | // Blur image 13 | void blur(int height, int width, RGBTRIPLE image[height][width]); 14 | 15 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/images/courtyard.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/filter-more/images/courtyard.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/images/stadium.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/filter-more/images/stadium.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/images/tower.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/filter-more/images/tower.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/images/yard.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/filter-more/images/yard.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/filter-more/out.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/filter-more/out.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/recover/card.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/recover/card.raw -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/recover/recover: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/recover/recover -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/recover/recover.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef uint8_t BYTE; 6 | 7 | #define BLOCK_SIZE 512 8 | #define JPEG_SIGNATURE_1 0xff 9 | #define JPEG_SIGNATURE_2 0xd8 10 | #define JPEG_SIGNATURE_3 0xff 11 | #define JPEG_SIGNATURE_MASK 0xf0 12 | #define JPEG_SIGNATURE_PREFIX 0xe0 13 | #define FILENAME_LENGTH 8 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | if (argc != 2) 18 | { 19 | fprintf(stderr, "Usage: %s IMAGE\n", argv[0]); 20 | return 1; 21 | } 22 | 23 | FILE *file = fopen(argv[1], "r"); 24 | if (file == NULL) 25 | { 26 | fprintf(stderr, "Unable to open the file.\n"); 27 | return 1; 28 | } 29 | 30 | BYTE buffer[BLOCK_SIZE]; 31 | int jpgCount = 0; 32 | FILE *currentJpg = NULL; 33 | 34 | while (fread(buffer, 1, BLOCK_SIZE, file) == BLOCK_SIZE) 35 | { 36 | if (buffer[0] == JPEG_SIGNATURE_1 && 37 | buffer[1] == JPEG_SIGNATURE_2 && 38 | buffer[2] == JPEG_SIGNATURE_3 && 39 | (buffer[3] & JPEG_SIGNATURE_MASK) == JPEG_SIGNATURE_PREFIX) 40 | { 41 | if (currentJpg != NULL) 42 | { 43 | fclose(currentJpg); 44 | } 45 | 46 | char filename[FILENAME_LENGTH]; 47 | sprintf(filename, "%03d.jpg", jpgCount); 48 | currentJpg = fopen(filename, "w"); 49 | jpgCount++; 50 | } 51 | 52 | if (currentJpg != NULL) 53 | { 54 | fwrite(buffer, 1, BLOCK_SIZE, currentJpg); 55 | } 56 | } 57 | 58 | if (currentJpg != NULL) 59 | { 60 | fclose(currentJpg); 61 | } 62 | 63 | fclose(file); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/Makefile: -------------------------------------------------------------------------------- 1 | colorize: 2 | clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o colorize colorize.c helpers.c 3 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/bmp.h: -------------------------------------------------------------------------------- 1 | // BMP-related data types based on Microsoft's own 2 | 3 | #include 4 | 5 | /** 6 | * Common Data Types 7 | * 8 | * The data types in this section are essentially aliases for C/C++ 9 | * primitive data types. 10 | * 11 | * Adapted from http://msdn.microsoft.com/en-us/library/cc230309.aspx. 12 | * See http://en.wikipedia.org/wiki/Stdint.h for more on stdint.h. 13 | */ 14 | typedef uint8_t BYTE; 15 | typedef uint32_t DWORD; 16 | typedef int32_t LONG; 17 | typedef uint16_t WORD; 18 | 19 | /** 20 | * BITMAPFILEHEADER 21 | * 22 | * The BITMAPFILEHEADER structure contains information about the type, size, 23 | * and layout of a file that contains a DIB [device-independent bitmap]. 24 | * 25 | * Adapted from http://msdn.microsoft.com/en-us/library/dd183374(VS.85).aspx. 26 | */ 27 | typedef struct 28 | { 29 | WORD bfType; 30 | DWORD bfSize; 31 | WORD bfReserved1; 32 | WORD bfReserved2; 33 | DWORD bfOffBits; 34 | } __attribute__((__packed__)) 35 | BITMAPFILEHEADER; 36 | 37 | /** 38 | * BITMAPINFOHEADER 39 | * 40 | * The BITMAPINFOHEADER structure contains information about the 41 | * dimensions and color format of a DIB [device-independent bitmap]. 42 | * 43 | * Adapted from http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx. 44 | */ 45 | typedef struct 46 | { 47 | DWORD biSize; 48 | LONG biWidth; 49 | LONG biHeight; 50 | WORD biPlanes; 51 | WORD biBitCount; 52 | DWORD biCompression; 53 | DWORD biSizeImage; 54 | LONG biXPelsPerMeter; 55 | LONG biYPelsPerMeter; 56 | DWORD biClrUsed; 57 | DWORD biClrImportant; 58 | } __attribute__((__packed__)) 59 | BITMAPINFOHEADER; 60 | 61 | /** 62 | * RGBTRIPLE 63 | * 64 | * This structure describes a color consisting of relative intensities of 65 | * red, green, and blue. 66 | * 67 | * Adapted from http://msdn.microsoft.com/en-us/library/aa922590.aspx. 68 | */ 69 | typedef struct 70 | { 71 | BYTE rgbtBlue; 72 | BYTE rgbtGreen; 73 | BYTE rgbtRed; 74 | } __attribute__((__packed__)) 75 | RGBTRIPLE; -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/colorize: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/smiley/colorize -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/colorize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "helpers.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | // ensure proper usage 9 | if (argc != 3) 10 | { 11 | printf("Usage: colorize infile outfile\n"); 12 | return 1; 13 | } 14 | 15 | // remember filenames 16 | char *infile = argv[1]; 17 | char *outfile = argv[2]; 18 | 19 | // open input file 20 | FILE *inptr = fopen(infile, "r"); 21 | if (inptr == NULL) 22 | { 23 | printf("Could not open %s.\n", infile); 24 | return 4; 25 | } 26 | 27 | // open output file 28 | FILE *outptr = fopen(outfile, "w"); 29 | if (outptr == NULL) 30 | { 31 | fclose(inptr); 32 | printf("Could not create %s.\n", outfile); 33 | return 5; 34 | } 35 | 36 | // read infile's BITMAPFILEHEADER 37 | BITMAPFILEHEADER bf; 38 | fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr); 39 | 40 | // read infile's BITMAPINFOHEADER 41 | BITMAPINFOHEADER bi; 42 | fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr); 43 | 44 | // ensure infile is (likely) a 24-bit uncompressed BMP 4.0 45 | if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || 46 | bi.biBitCount != 24 || bi.biCompression != 0) 47 | { 48 | fclose(outptr); 49 | fclose(inptr); 50 | printf("Unsupported file format.\n"); 51 | return 6; 52 | } 53 | 54 | int height = abs(bi.biHeight); 55 | int width = bi.biWidth; 56 | 57 | // allocate memory for image 58 | RGBTRIPLE (*image)[width] = calloc(height, width * sizeof(RGBTRIPLE)); 59 | if (image == NULL) 60 | { 61 | printf("Not enough memory to store image.\n"); 62 | fclose(outptr); 63 | fclose(inptr); 64 | return 7; 65 | } 66 | 67 | // determine padding for scanlines 68 | int padding = (4 - (width * sizeof(RGBTRIPLE)) % 4) % 4; 69 | 70 | // iterate over infile's scanlines 71 | for (int i = 0; i < height; i++) 72 | { 73 | // read row into pixel array 74 | fread(image[i], sizeof(RGBTRIPLE), width, inptr); 75 | 76 | // skip over padding 77 | fseek(inptr, padding, SEEK_CUR); 78 | } 79 | 80 | colorize(height, width, image); 81 | 82 | // write outfile's BITMAPFILEHEADER 83 | fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr); 84 | 85 | // write outfile's BITMAPINFOHEADER 86 | fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr); 87 | 88 | // write new pixels to outfile 89 | for (int i = 0; i < height; i++) 90 | { 91 | // write row to outfile 92 | fwrite(image[i], sizeof(RGBTRIPLE), width, outptr); 93 | 94 | // write padding at end of row 95 | for (int k = 0; k < padding; k++) 96 | { 97 | fputc(0x00, outptr); 98 | } 99 | } 100 | 101 | // free memory for image 102 | free(image); 103 | 104 | // close infile 105 | fclose(inptr); 106 | 107 | // close outfile 108 | fclose(outptr); 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/helpers.c: -------------------------------------------------------------------------------- 1 | #include "helpers.h" 2 | 3 | void colorize(int height, int width, RGBTRIPLE image[height][width]) 4 | { 5 | RGBTRIPLE newColor; 6 | newColor.rgbtRed = 255; 7 | newColor.rgbtGreen = 0; 8 | newColor.rgbtBlue = 0; 9 | 10 | for (int i = 0; i < height; i++) 11 | { 12 | for (int j = 0; j < width; j++) 13 | { 14 | if (image[i][j].rgbtRed == 0 && image[i][j].rgbtGreen == 0 && image[i][j].rgbtBlue == 0) 15 | { 16 | image[i][j] = newColor; 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/helpers.h: -------------------------------------------------------------------------------- 1 | #include "bmp.h" 2 | 3 | // colorize image 4 | void colorize(int height, int width, RGBTRIPLE image[height][width]); 5 | 6 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/output.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/smiley/output.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week04_Memory/smiley/smiley.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week04_Memory/smiley/smiley.bmp -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/inheritance.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct person 6 | { 7 | struct person *parents[2]; 8 | char alleles[2]; 9 | } person; 10 | 11 | const int GENERATIONS = 3; 12 | const int INDENT_LENGTH = 4; 13 | 14 | person *create_family(int generations); 15 | void print_family(person *p, int generation); 16 | void free_family(person *p); 17 | char random_allele(); 18 | 19 | int main(void) 20 | { 21 | srand(time(0)); 22 | person *p = create_family(GENERATIONS); 23 | print_family(p, 0); 24 | free_family(p); 25 | } 26 | 27 | person *create_family(int generations) 28 | { 29 | person *newPerson = malloc(sizeof(person)); 30 | if (generations > 1) 31 | { 32 | person *parent0 = create_family(generations - 1); 33 | person *parent1 = create_family(generations - 1); 34 | newPerson->parents[0] = parent0; 35 | newPerson->parents[1] = parent1; 36 | newPerson->alleles[0] = parent0->alleles[rand() % 2]; 37 | newPerson->alleles[1] = parent1->alleles[rand() % 2]; 38 | } 39 | else 40 | { 41 | newPerson->parents[0] = NULL; 42 | newPerson->parents[1] = NULL; 43 | newPerson->alleles[0] = random_allele(); 44 | newPerson->alleles[1] = random_allele(); 45 | } 46 | return newPerson; 47 | } 48 | 49 | void free_family(person *p) 50 | { 51 | if (p == NULL) 52 | { 53 | return; 54 | } 55 | free_family(p->parents[0]); 56 | free_family(p->parents[1]); 57 | free(p); 58 | } 59 | 60 | void print_family(person *p, int generation) 61 | { 62 | if (p == NULL) 63 | { 64 | return; 65 | } 66 | for (int i = 0; i < generation * INDENT_LENGTH; i++) 67 | { 68 | printf(" "); 69 | } 70 | if (generation == 0) 71 | { 72 | printf("Child (Generation %i): blood type %c%c\n", generation, p->alleles[0], p->alleles[1]); 73 | } 74 | else if (generation == 1) 75 | { 76 | printf("Parent (Generation %i): blood type %c%c\n", generation, p->alleles[0], p->alleles[1]); 77 | } 78 | else 79 | { 80 | for (int i = 0; i < generation - 2; i++) 81 | { 82 | printf("Great-"); 83 | } 84 | printf("Grandparent (Generation %i): blood type %c%c\n", generation, p->alleles[0], p->alleles[1]); 85 | } 86 | print_family(p->parents[0], generation + 1); 87 | print_family(p->parents[1], generation + 1); 88 | } 89 | 90 | char random_allele() 91 | { 92 | int r = rand() % 3; 93 | if (r == 0) 94 | { 95 | return 'A'; 96 | } 97 | else if (r == 1) 98 | { 99 | return 'B'; 100 | } 101 | else 102 | { 103 | return 'O'; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/Makefile: -------------------------------------------------------------------------------- 1 | speller: 2 | clang -ggdb3 -gdwarf-4 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-gnu-folding-constant -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c 3 | clang -ggdb3 -gdwarf-4 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-gnu-folding-constant -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c 4 | clang -ggdb3 -gdwarf-4 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-gnu-folding-constant -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o speller speller.o dictionary.o -lm 5 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/dictionaries/small: -------------------------------------------------------------------------------- 1 | cat 2 | caterpillar 3 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/dictionary.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "dictionary.h" 9 | 10 | // Represents a node in a hash table 11 | typedef struct node 12 | { 13 | char word[LENGTH + 1]; 14 | struct node *next; 15 | } node; 16 | 17 | // Choose number of buckets in hash table 18 | const unsigned int N = 26; 19 | 20 | // Hash table 21 | node *table[N]; 22 | 23 | // Returns true if word is in dictionary, else false 24 | bool check(const char *word) 25 | { 26 | int index = hash(word); 27 | for (node *tmp = table[index]; tmp != NULL; tmp = tmp->next) 28 | { 29 | if (strcasecmp(tmp->word, word) == 0) 30 | { 31 | return true; 32 | } 33 | } 34 | 35 | return false; 36 | } 37 | 38 | 39 | 40 | // https://stackoverflow.com/questions/7666509/hash-function-for-string 41 | unsigned int hash(const char *word) 42 | { 43 | unsigned int hash_value = 0; 44 | for (int i = 0; word[i] != '\0'; i++) 45 | { 46 | hash_value = (hash_value << 2) ^ toupper(word[i]); 47 | } 48 | return hash_value % N; 49 | } 50 | 51 | 52 | // Loads dictionary into memory, returning true if successful, else false 53 | bool load(const char *dictionary) 54 | { 55 | FILE *file = fopen(dictionary, "r"); 56 | if (file == NULL) 57 | { 58 | fprintf(stderr, "Could not open dictionary.\n"); 59 | return false; 60 | } 61 | 62 | for (int i = 0; i < N; i++) 63 | { 64 | table[i] = NULL; 65 | } 66 | 67 | char word[LENGTH + 1]; 68 | while (fscanf(file, "%s", word) != EOF) 69 | { 70 | node *new_node = malloc(sizeof(node)); 71 | if (new_node == NULL) 72 | { 73 | fclose(file); 74 | fprintf(stderr, "Out of memory.\n"); 75 | return false; 76 | } 77 | 78 | strcpy(new_node->word, word); 79 | int index = hash(word); 80 | 81 | new_node->next = table[index]; 82 | table[index] = new_node; 83 | } 84 | 85 | fclose(file); 86 | return true; 87 | } 88 | 89 | // Returns number of words in dictionary if loaded, else 0 if not yet loaded 90 | unsigned int size(void) 91 | { 92 | int count = 0; 93 | 94 | // Traverse each linked list in the hash table 95 | for (int i = 0; i < N; i++) 96 | { 97 | for (node *tmp = table[i]; tmp != NULL; tmp = tmp->next) 98 | { 99 | count++; 100 | } 101 | } 102 | 103 | return count; 104 | } 105 | 106 | // Unloads dictionary from memory, returning true if successful, else false 107 | bool unload(void) 108 | { 109 | // Traverse each linked list in the hash table 110 | for (int i = 0; i < N; i++) 111 | { 112 | // Free nodes in the linked list 113 | while (table[i] != NULL) 114 | { 115 | node *tmp = table[i]->next; 116 | free(table[i]); 117 | table[i] = tmp; 118 | } 119 | } 120 | 121 | return true; 122 | } 123 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/dictionary.h: -------------------------------------------------------------------------------- 1 | // Declares a dictionary's functionality 2 | 3 | #ifndef DICTIONARY_H 4 | #define DICTIONARY_H 5 | 6 | #include 7 | 8 | // Maximum length for a word 9 | // (e.g., pneumonoultramicroscopicsilicovolcanoconiosis) 10 | #define LENGTH 45 11 | 12 | // Prototypes 13 | bool check(const char *word); 14 | unsigned int hash(const char *word); 15 | bool load(const char *dictionary); 16 | unsigned int size(void); 17 | bool unload(void); 18 | 19 | #endif // DICTIONARY_H 20 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/dictionary.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/dictionary.o -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/inheritance.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/inheritance.zip -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/keys/carroll.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | Gutenberg's 5 | Alice's 6 | eBook 7 | eBook 8 | org 9 | Alice's 10 | EBook 11 | EBOOK 12 | ALICE'S 13 | ALICE'S 14 | MARMALADE' 15 | Antipathies 16 | Dinah'll 17 | Alice's 18 | ME' 19 | not' 20 | ME' 21 | ALICE'S 22 | ESQ 23 | HEARTHRUG 24 | ALICE'S 25 | skurried 26 | O 27 | O 28 | O 29 | Ou 30 | chatte 31 | better' 32 | Morcar 33 | Morcar 34 | Stigand 35 | Atheling 36 | William's 37 | Normans 38 | thimble' 39 | C 40 | D 41 | Mouse's 42 | Dinah's 43 | naturedly 44 | W 45 | RABBIT' 46 | Dinah'll 47 | pleasanter 48 | Alice's 49 | won't' 50 | yer 51 | yer 52 | arrum 53 | yer 54 | yer 55 | Bill's 56 | Bill's 57 | Bill's 58 | Bill's 59 | barrowful 60 | barrowful 61 | V 62 | sir' 63 | yawned 64 | Footman's 65 | nose' 66 | Hatter's 67 | Alice's 68 | Lacie 69 | Sh 70 | sh 71 | were' 72 | M 73 | M 74 | M 75 | everything's 76 | beheaded 77 | King's 78 | processions 79 | rosetree 80 | beheaded 81 | croqueted 82 | croqueting 83 | executioner's 84 | King's 85 | beheaded 86 | Alice's 87 | Everything's 88 | Alice's 89 | Alice's 90 | game's 91 | Tis 92 | tis 93 | tis 94 | Alice's 95 | m 96 | Alice's 97 | ordered' 98 | Hjckrrh 99 | mayn't 100 | uglifying 101 | Seaography 102 | X 103 | never' 104 | dinn 105 | Dinn 106 | yawned 107 | TIS 108 | Tis 109 | Hm 110 | ootiful 111 | oop 112 | ootiful 113 | oop 114 | oop 115 | e 116 | e 117 | ootiful 118 | oop 119 | ootiful 120 | oop 121 | oop 122 | e 123 | e 124 | beauti 125 | FUL 126 | oop 127 | e 128 | e 129 | men' 130 | slates'll 131 | T 132 | Alice's 133 | jurymen 134 | jurymen 135 | jurymen 136 | jurymen 137 | teacups 138 | teacups 139 | Gutenberg's 140 | Alice's 141 | EBOOK 142 | ALICE'S 143 | txt 144 | http 145 | org 146 | tm 147 | tm 148 | eBooks 149 | eBook 150 | eBook 151 | eBooks 152 | tm 153 | tm 154 | http 155 | org 156 | tm 157 | tm 158 | tm 159 | tm 160 | E 161 | B 162 | tm 163 | C 164 | tm 165 | tm 166 | E 167 | C 168 | PGLAF 169 | tm 170 | tm 171 | tm 172 | tm 173 | tm 174 | D 175 | tm 176 | E 177 | E 178 | tm 179 | tm 180 | eBook 181 | eBook 182 | org 183 | E 184 | tm 185 | E 186 | E 187 | tm 188 | E 189 | E 190 | E 191 | tm 192 | E 193 | E 194 | tm 195 | E 196 | tm 197 | tm 198 | E 199 | E 200 | tm 201 | E 202 | nonproprietary 203 | tm 204 | tm 205 | org 206 | tm 207 | E 208 | E 209 | tm 210 | E 211 | E 212 | E 213 | tm 214 | tm 215 | tm 216 | e 217 | s 218 | tm 219 | tm 220 | F 221 | tm 222 | E 223 | tm 224 | tm 225 | F 226 | F 227 | tm 228 | tm 229 | F 230 | F 231 | tm 232 | tm 233 | F 234 | F 235 | F 236 | IS' 237 | MERCHANTIBILITY 238 | F 239 | unenforceability 240 | F 241 | tm 242 | tm 243 | tm 244 | b 245 | tm 246 | c 247 | tm 248 | tm 249 | tm's 250 | tm 251 | tm 252 | http 253 | pglaf 254 | org 255 | c 256 | c 257 | http 258 | pglaf 259 | org 260 | U 261 | S 262 | Melan 263 | S 264 | pglaf 265 | org 266 | http 267 | pglaf 268 | org 269 | B 270 | Newby 271 | gbnewby 272 | pglaf 273 | org 274 | tm 275 | http 276 | pglaf 277 | org 278 | U 279 | S 280 | http 281 | pglaf 282 | org 283 | tm 284 | S 285 | tm 286 | tm 287 | eBooks 288 | tm 289 | eBooks 290 | U 291 | S 292 | eBooks 293 | PG 294 | http 295 | org 296 | tm 297 | eBooks 298 | eBooks 299 | 300 | WORDS MISSPELLED: 295 301 | WORDS IN DICTIONARY: 143091 302 | WORDS IN TEXT: 29758 303 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/keys/cat.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | 5 | WORDS MISSPELLED: 0 6 | WORDS IN DICTIONARY: 143091 7 | WORDS IN TEXT: 6 8 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/keys/constitution.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | USConstitution 5 | http 6 | usconstitution 7 | const 8 | html 9 | tempore 10 | Impeachments 11 | Nays 12 | Nays 13 | repassed 14 | Piracies 15 | Felonies 16 | attainted 17 | Langdon 18 | Gilman 19 | Brearley 20 | Mifflin 21 | Clymer 22 | Fitzsimons 23 | Jared 24 | Gouvernour 25 | McHenry 26 | Jenifer 27 | Blount 28 | Spaight 29 | Cotesworth 30 | tempore 31 | tempore 32 | tempore 33 | tempore 34 | 35 | WORDS MISSPELLED: 30 36 | WORDS IN DICTIONARY: 143091 37 | WORDS IN TEXT: 7573 38 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/keys/pneumonoultramicroscopicsilicovolcanoconiosis.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | 5 | WORDS MISSPELLED: 0 6 | WORDS IN DICTIONARY: 143091 7 | WORDS IN TEXT: 20 8 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/keys/wordsworth.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | 5 | WORDS MISSPELLED: 0 6 | WORDS IN DICTIONARY: 143091 7 | WORDS IN TEXT: 158 8 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/speller: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/speller -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/speller.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/speller.o -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/speller50: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/speller50 -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/cat.txt: -------------------------------------------------------------------------------- 1 | A cat is not a caterpillar. 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/holmes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/holmes.txt -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/pneumonoultramicroscopicsilicovolcanoconiosis.txt: -------------------------------------------------------------------------------- 1 | According to Merriam-Webster's Medical Dictionary, 2 | pneumonoultramicroscopicsilicovolcanoconiosis is a 3 | pneumoconiosis caused by inhalation of very fine 4 | silicate or quartz dust. 5 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/wordsworth.txt: -------------------------------------------------------------------------------- 1 | Daffodils 2 | 3 | I wandered lonely as a cloud 4 | That floats on high o'er vales and hills, 5 | When all at once I saw a crowd, 6 | A host, of golden daffodils; 7 | Beside the lake, beneath the trees, 8 | Fluttering and dancing in the breeze. 9 | 10 | Continuous as the stars that shine 11 | And twinkle on the milky way, 12 | They stretched in never-ending line 13 | Along the margin of a bay: 14 | Ten thousand saw I at a glance, 15 | Tossing their heads in sprightly dance. 16 | 17 | The waves beside them danced; but they 18 | Out-did the sparkling waves in glee: 19 | A poet could not but be gay, 20 | In such a jocund company: 21 | I gazed--and gazed--but little thought 22 | What wealth the show to me had brought: 23 | 24 | For oft, when on my couch I lie 25 | In vacant or in pensive mood, 26 | They flash upon that inward eye 27 | Which is the bliss of solitude; 28 | And then my heart with pleasure fills, 29 | And dances with the daffodils. 30 | 31 | -- William Wordsworth 32 | 33 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/xueqin2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week05_DataStructures/speller/texts/xueqin2.txt -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week06_Python/credit.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | card_number = "" 3 | 4 | while not card_number or len(card_number) == 0: 5 | card_number = input("Number: ") 6 | 7 | sum = 0 8 | digit_count = 0 9 | 10 | for i in range(len(card_number) - 1, -1, -1): 11 | digit = int(card_number[i]) 12 | 13 | if digit_count % 2 == 1: 14 | digit *= 2 15 | 16 | if digit > 9: 17 | digit = digit % 10 + 1 18 | 19 | sum += digit 20 | digit_count += 1 21 | 22 | if sum % 10 == 0: 23 | if (len(card_number) == 15 and (card_number.startswith("34") or card_number.startswith("37"))): 24 | print("AMEX") 25 | elif (len(card_number) == 16 and card_number.startswith(("51", "52", "53", "54", "55"))): 26 | print("MASTERCARD") 27 | elif (len(card_number) == 13 or len(card_number) == 16) and card_number.startswith("4"): 28 | print("VISA") 29 | else: 30 | print("INVALID") 31 | else: 32 | print("INVALID") 33 | 34 | if __name__ == "__main__": 35 | main() 36 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week06_Python/mario.py: -------------------------------------------------------------------------------- 1 | def print_p(i, height): 2 | hc = i + 1 3 | sc = height - (i + 1) 4 | 5 | for j in range(sc): 6 | print(' ', end='') 7 | 8 | for j in range(hc): 9 | print('#', end='') 10 | 11 | print(' ', end='') 12 | 13 | for j in range(hc): 14 | print('#', end='') 15 | 16 | def main(): 17 | height = 0 18 | 19 | while height < 1 or height > 8: 20 | try: 21 | height = int(input("Height: ")) 22 | except ValueError: 23 | continue 24 | 25 | for i in range(height): 26 | print_p(i, height) 27 | print() 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week06_Python/readability.py: -------------------------------------------------------------------------------- 1 | from cs50 import get_string 2 | 3 | def main(): 4 | text = get_string("Text: ") 5 | letters, words, sentences = count_text(text) 6 | grade = calculate_grade(letters, words, sentences) 7 | print_grade(grade) 8 | 9 | def count_text(text): 10 | letters = sum(c.isalpha() for c in text) 11 | words = len(text.split()) 12 | sentences = text.count('.') + text.count('!') + text.count('?') 13 | return letters, words, sentences 14 | 15 | def calculate_grade(letters, words, sentences): 16 | L = letters / words * 100 17 | S = sentences / words * 100 18 | index = 0.0588 * L - 0.296 * S - 15.8 19 | return round(index) 20 | 21 | def print_grade(grade): 22 | if grade < 1: 23 | print("Before Grade 1") 24 | elif grade >= 16: 25 | print("Grade 16+") 26 | else: 27 | print(f"Grade {grade}") 28 | 29 | if __name__ == "__main__": 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/1.sql: -------------------------------------------------------------------------------- 1 | SELECT name FROM songs; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/2.sql: -------------------------------------------------------------------------------- 1 | SELECT name FROM songs ORDER BY tempo; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/3.sql: -------------------------------------------------------------------------------- 1 | SELECT name FROM songs ORDER BY duration_ms DESC LIMIT 5; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/4.sql: -------------------------------------------------------------------------------- 1 | SELECT name FROM songs WHERE danceability > 0.75 AND energy > 0.75 AND valence > 0.75; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/5.sql: -------------------------------------------------------------------------------- 1 | SELECT AVG(energy) AS average_energy FROM songs; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/6.sql: -------------------------------------------------------------------------------- 1 | SELECT songs.name FROM songs JOIN artists ON songs.artist_id = artists.id WHERE artists.name = 'Post Malone'; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/7.sql: -------------------------------------------------------------------------------- 1 | SELECT AVG(energy) AS average_energy FROM songs JOIN artists ON songs.artist_id = artists.id WHERE artists.name = 'Drake'; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/8.sql: -------------------------------------------------------------------------------- 1 | SELECT name FROM songs WHERE name LIKE '%feat.%'; 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/answers.txt: -------------------------------------------------------------------------------- 1 | Examining the contents of songs.db, particularly an individual's top 100 songs from 2018, provides insights into their musical preferences. An analysis of the average energy, valence, and danceability allows for the characterization of the listener's audio aura. However, it's essential to acknowledge the limitations of this method. Averaging across diverse songs may oversimplify nuances and fail to capture the distinct mood variations within the playlist. A more comprehensive approach might involve clustering similar songs or employing machine learning techniques for a more nuanced understanding of the listener's musical preferences and emotional resonances. 2 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week07_SQL/songs/songs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week07_SQL/songs/songs.db -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week08_Html_CSS_JS/homepage/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | 12 | 15 | 20 | 21 |
13 | 14 | 16 |

HI! IaM tHe sKEletOn Dev

i rose from the dead to code.... 17 | and my favourite drug is Calcium 💀👻🦴🦷

18 | Contact me 19 |
22 | 23 |
24 |

I love to code bruh

25 |
26 | 27 | 28 | 29 | 31 | 34 | 35 | 36 | 37 | 40 | 43 | 44 | 45 | 48 | 51 | 52 | 53 | 54 | 57 | 60 | 61 | 62 | 65 | 68 | 69 | 70 | 71 | 72 | 73 |
30 |
32 |

Skills

33 |
38 | Coding 39 | 41 | ★ ★ ★ ★ ☆ 42 |
46 | Drawing 47 | 49 | ★ ☆ ☆ ☆ ☆ 50 |
55 | Cooking 56 | 58 | ★ ★ ★ ☆ ☆ 59 |
63 | Python Development 64 | 66 | ★ ★ ★ ★ ☆ 67 |
74 |
75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week08_Html_CSS_JS/homepage/styles.css: -------------------------------------------------------------------------------- 1 | h1,h2,h3 { 2 | font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif; 3 | font-size: 1.75rem; 4 | line-height: 1; 5 | font-weight: bold; 6 | } 7 | 8 | * { 9 | font-family: 'Iosevka Curly', 'Source Code Pro', 'DejaVu Sans Mono', 'Ubuntu Mono', 'Consolas', monospace; 10 | } 11 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week08_Html_CSS_JS/trivia/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Trivia! 7 | 8 | 9 | 10 |
11 |

Trivia!

12 |
13 | 14 |
15 |
16 |

Part 1: Multiple Choice

17 |
18 |

What is the capital of France?

19 | 20 | 21 | 22 |
23 |
24 | 25 |
26 |

Part 2: Free Response

27 |
28 |

What is the largest planet in our solar system?

29 | 30 | 31 |
32 |
33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week08_Html_CSS_JS/trivia/script.js: -------------------------------------------------------------------------------- 1 | function checkAnswer(button) { 2 | const question = document.getElementById("question1"); 3 | const result = document.getElementById("result1"); 4 | 5 | const isCorrect = button.textContent === "Paris"; 6 | 7 | result.textContent = isCorrect ? "Correct!" : "Incorrect :/"; 8 | result.className = isCorrect ? "correct" : "incorrect"; 9 | 10 | button.style.backgroundColor = isCorrect ? "green" : "red"; 11 | 12 | const choices = document.querySelectorAll(".choice"); 13 | choices.forEach(choice => choice.disabled = true); 14 | } 15 | 16 | function checkFreeResponse() { 17 | const question = document.getElementById("question2"); 18 | const answerInput = document.getElementById("answerInput"); 19 | const result = document.getElementById("result2"); 20 | 21 | const isCorrect = answerInput.value.toLowerCase() === "jupiter"; 22 | 23 | result.textContent = isCorrect ? "Correct!" : "Incorrect"; 24 | result.className = isCorrect ? "correct" : "incorrect"; 25 | answerInput.className = isCorrect ? "correct" : "incorrect"; 26 | 27 | answerInput.disabled = true; 28 | document.querySelector("button").disabled = true; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week08_Html_CSS_JS/trivia/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Montserrat', sans-serif; 3 | background-color: #f4f4f4; 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | .header { 9 | background-color: #333; 10 | color: white; 11 | text-align: center; 12 | padding: 20px; 13 | } 14 | 15 | .container { 16 | max-width: 800px; 17 | margin: 20px auto; 18 | background-color: white; 19 | padding: 20px; 20 | border-radius: 8px; 21 | box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); 22 | } 23 | 24 | .section { 25 | margin-bottom: 30px; 26 | } 27 | 28 | h2 { 29 | color: #333; 30 | } 31 | 32 | .choice { 33 | display: block; 34 | margin: 10px 0; 35 | padding: 10px; 36 | width: 150px; 37 | background-color: #fff; 38 | cursor: pointer; 39 | } 40 | 41 | #result1, #result2 { 42 | margin-top: 10px; 43 | font-weight: bold; 44 | } 45 | 46 | #result1.correct { 47 | color: green; 48 | } 49 | 50 | #result1.incorrect { 51 | color: red; 52 | } 53 | 54 | #result2.correct { 55 | color: green; 56 | } 57 | 58 | #result2.incorrect { 59 | color: red; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/birthdays/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from cs50 import SQL 4 | from flask import Flask, flash, jsonify, redirect, render_template, request, session 5 | 6 | # Configure application 7 | app = Flask(__name__) 8 | 9 | # Ensure templates are auto-reloaded 10 | app.config["TEMPLATES_AUTO_RELOAD"] = True 11 | 12 | # Configure CS50 Library to use SQLite database 13 | db = SQL("sqlite:///birthdays.db") 14 | 15 | @app.after_request 16 | def after_request(response): 17 | """Ensure responses aren't cached""" 18 | response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" 19 | response.headers["Expires"] = 0 20 | response.headers["Pragma"] = "no-cache" 21 | return response 22 | 23 | 24 | @app.route("/", methods=["GET", "POST"]) 25 | def index(): 26 | if request.method == "POST": 27 | 28 | name = request.form.get("name") 29 | month = request.form.get("month") 30 | day = request.form.get("day") 31 | 32 | db.execute("INSERT INTO birthdays (name, month, day) VALUES (?, ?, ?)", name, month, day) 33 | 34 | # Redirect to the index page 35 | return redirect("/") 36 | 37 | else: 38 | # Fetch all entries from the database 39 | birthdays = db.execute("SELECT * FROM birthdays") 40 | 41 | # Render the index page with the fetched data 42 | return render_template("index.html", birthdays=birthdays) 43 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/birthdays/birthdays.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week09_Flask/birthdays/birthdays.db -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/birthdays/static/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | color: #212529; 4 | font-size: 1rem; 5 | font-weight: 400; 6 | line-height: 1.5; 7 | margin: 0; 8 | text-align: left; 9 | } 10 | 11 | .container { 12 | margin-left: auto; 13 | margin-right: auto; 14 | padding-left: 15px; 15 | padding-right: 15px; 16 | text-align: center; 17 | width: 90%; 18 | } 19 | 20 | .header { 21 | background-color: #477bff; 22 | color: #fff; 23 | margin-bottom: 2rem; 24 | padding: 2rem 1rem; 25 | text-align: center; 26 | } 27 | 28 | .section { 29 | padding-bottom: 1rem; 30 | padding-left: 2rem; 31 | padding-right: 2rem; 32 | padding-top: 0.5rem; 33 | } 34 | 35 | .section:hover { 36 | background-color: #f5f5f5; 37 | transition: color 2s ease-in-out, background-color 0.15s ease-in-out; 38 | } 39 | 40 | h1 { 41 | font-family: 'Montserrat', sans-serif; 42 | font-size: 48px; 43 | } 44 | 45 | button, input[type="submit"] { 46 | background-color: #d9edff; 47 | border: 1px solid transparent; 48 | border-radius: 0.25rem; 49 | font-size: 0.95rem; 50 | font-weight: 400; 51 | line-height: 1.5; 52 | padding: 0.375rem 0.75rem; 53 | text-align: center; 54 | transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; 55 | vertical-align: middle; 56 | } 57 | 58 | input[type="text"], input[type="number"] { 59 | line-height: 1.8; 60 | width: 25%; 61 | } 62 | 63 | input[type="text"]:hover, input[type="number"]:hover { 64 | background-color: #f5f5f5; 65 | transition: color 2s ease-in-out, background-color 0.15s ease-in-out; 66 | } 67 | 68 | table { 69 | background-color: transparent; 70 | margin-bottom: 1rem; 71 | width: 100%; 72 | } 73 | 74 | table th, 75 | table td { 76 | padding: 0.75rem; 77 | vertical-align: middle; 78 | } 79 | 80 | tbody tr:nth-of-type(odd) { 81 | background-color: rgb(179, 208, 255, 0.3) 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/birthdays/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Birthdays 8 | 9 | 10 |
11 |

Birthdays

12 |
13 |
14 |
15 |

Add a Birthday

16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 | 28 |
29 |

All Birthdays

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | {% for birthday in birthdays %} 40 | 41 | 42 | 43 | 44 | {% endfor %} 45 | 46 |
NameBirthday
{{ birthday.name }}{{ birthday.month }} {{ birthday.day }}
47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/finance.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week09_Flask/finance/finance.db -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/helpers.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import datetime 3 | import pytz 4 | import requests 5 | import subprocess 6 | import urllib 7 | import uuid 8 | 9 | from flask import redirect, render_template, session 10 | from functools import wraps 11 | 12 | 13 | def apology(message, code=400): 14 | """Render message as an apology to user.""" 15 | def escape(s): 16 | """ 17 | Escape special characters. 18 | 19 | https://github.com/jacebrowning/memegen#special-characters 20 | """ 21 | for old, new in [("-", "--"), (" ", "-"), ("_", "__"), ("?", "~q"), 22 | ("%", "~p"), ("#", "~h"), ("/", "~s"), ("\"", "''")]: 23 | s = s.replace(old, new) 24 | return s 25 | return render_template("apology.html", top=code, bottom=escape(message)), code 26 | 27 | 28 | def login_required(f): 29 | """ 30 | Decorate routes to require login. 31 | 32 | http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/ 33 | """ 34 | @wraps(f) 35 | def decorated_function(*args, **kwargs): 36 | if session.get("user_id") is None: 37 | return redirect("/login") 38 | return f(*args, **kwargs) 39 | return decorated_function 40 | 41 | 42 | def lookup(symbol): 43 | """Look up quote for symbol.""" 44 | 45 | # Prepare API request 46 | symbol = symbol.upper() 47 | end = datetime.datetime.now(pytz.timezone("US/Eastern")) 48 | start = end - datetime.timedelta(days=7) 49 | 50 | # Yahoo Finance API 51 | url = ( 52 | f"https://query1.finance.yahoo.com/v7/finance/download/{urllib.parse.quote_plus(symbol)}" 53 | f"?period1={int(start.timestamp())}" 54 | f"&period2={int(end.timestamp())}" 55 | f"&interval=1d&events=history&includeAdjustedClose=true" 56 | ) 57 | 58 | # Query API 59 | try: 60 | response = requests.get(url, cookies={"session": str(uuid.uuid4())}, headers={"User-Agent": "python-requests", "Accept": "*/*"}) 61 | response.raise_for_status() 62 | 63 | # CSV header: Date,Open,High,Low,Close,Adj Close,Volume 64 | quotes = list(csv.DictReader(response.content.decode("utf-8").splitlines())) 65 | quotes.reverse() 66 | price = round(float(quotes[0]["Adj Close"]), 2) 67 | return { 68 | "name": symbol, 69 | "price": price, 70 | "symbol": symbol 71 | } 72 | except (requests.RequestException, ValueError, KeyError, IndexError): 73 | return None 74 | 75 | 76 | def usd(value): 77 | """Format value as USD.""" 78 | return f"${value:,.2f}" 79 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/requirements.txt: -------------------------------------------------------------------------------- 1 | cs50 2 | Flask 3 | Flask-Session 4 | requests -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Computer_Science/Week09_Flask/finance/static/favicon.ico -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/static/styles.css: -------------------------------------------------------------------------------- 1 | /* Size for brand */ 2 | nav .navbar-brand 3 | { 4 | font-size: xx-large; 5 | } 6 | 7 | /* Colors for brand */ 8 | nav .navbar-brand .blue 9 | { 10 | color: #537fbe; 11 | } 12 | nav .navbar-brand .red 13 | { 14 | color: #ea433b; 15 | } 16 | nav .navbar-brand .yellow 17 | { 18 | color: #f5b82e; 19 | } 20 | nav .navbar-brand .green 21 | { 22 | color: #2e944b; 23 | } 24 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/apology.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Apology 5 | {% endblock %} 6 | 7 | {% block main %} 8 | 9 | {{ top }} 10 | {% endblock %} 11 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/buy.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Buy 5 | {% endblock %} 6 | 7 | {% block main %} 8 | 9 |

Buy Stocks

10 | 11 |
12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | {% endblock %} 24 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/history.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | History 5 | {% endblock %} 6 | 7 | {% block main %} 8 |

Transaction History

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | {% for transaction in transactions %} 20 | 21 | 22 | 23 | 24 | 25 | 26 | {% endfor %} 27 | 28 |
Transaction DateSymbolSharesPrice
{{ transaction['timestamp'] }}{{ transaction['symbol'] }}{{ transaction['shares'] }}{{ transaction['price'] }}
29 | {% endblock %} 30 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Portfolio 5 | {% endblock %} 6 | 7 | {% block main %} 8 | 9 |

Portfolio

10 | 11 |

Cash Balance: {{ user_cash | usd }}

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | {% for holding in holdings %} 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% endfor %} 33 | 34 |
SymbolNameSharesPriceTotal Value
{{ holding["symbol"] }}{{ holding["name"] }}{{ holding["total_shares"] }}{{ holding["price"] | usd }}{{ holding["total_value"] | usd }}
35 | 36 |

Total Portfolio Value: {{ total_portfolio_value | usd }}

37 | 38 | {% endblock %} 39 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/login.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Log In 5 | {% endblock %} 6 | 7 | {% block main %} 8 |
9 |
10 | 11 |
12 |
13 | 14 |
15 | 16 |
17 | {% endblock %} 18 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/quote.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Quote 5 | {% endblock %} 6 | 7 | {% block main %} 8 | 9 |

Get Stock Quote

10 | 11 |
12 |
13 | 14 | 15 |
16 | 17 |
18 | 19 | {% if quote %} 20 |

Quote for {{ quote["symbol"] }}

21 |

Name: {{ quote["name"] }}

22 |

Price: {{ quote["price"] | usd }}

23 | {% endif %} 24 | 25 | {% endblock %} 26 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/quoted.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Quoted 5 | {% endblock %} 6 | 7 | {% block main %} 8 | 9 |

Stock Quote

10 | 11 | {% if quote %} 12 |

Symbol: {{ quote["symbol"] }}

13 |

Name: {{ quote["name"] }}

14 |

Price: {{ quote["price"] | usd }}

15 | {% else %} 16 |

Invalid symbol or unable to fetch quote. Please try again.

17 | {% endif %} 18 | 19 | Get Another Quote 20 | 21 | {% endblock %} 22 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/register.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Register 5 | {% endblock %} 6 | 7 | {% block main %} 8 |
9 |
10 | 11 |
12 |
13 | 14 |
15 |
16 | 17 |
18 | 19 |
20 | {% endblock %} 21 | -------------------------------------------------------------------------------- /Introduction_To_Computer_Science/Week09_Flask/finance/templates/sell.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %} 4 | Sell 5 | {% endblock %} 6 | 7 | {% block main %} 8 | 9 |

Sell Stocks

10 | 11 |
12 |
13 | 14 | 20 |
21 |
22 | 23 | 24 |
25 | 26 |
27 | 28 | {% endblock %} 29 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/.gitignore: -------------------------------------------------------------------------------- 1 | */__pycache__ 2 | */**/__pycache__ 3 | 4 | */**/.pytest_cache -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_00/einstein/einstein.py: -------------------------------------------------------------------------------- 1 | print("E:", int(input("m: ")) * (300000000 ** 2)) 2 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_00/faces/faces.py: -------------------------------------------------------------------------------- 1 | print(str(input()).replace(":)", "🙂").replace(":(", "🙁")) 2 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_00/indoor/indoor.py: -------------------------------------------------------------------------------- 1 | inp = str(input()) 2 | print(inp.lower()) 3 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_00/playback/playback.py: -------------------------------------------------------------------------------- 1 | print("...".join(str(input()).split(" "))) 2 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_00/tip/tip.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | dollars = dollars_to_float(input("How much was the meal? ")) 3 | percent = percent_to_float( 4 | input("What percentage would you like to tip? ")) 5 | tip = dollars * percent 6 | print(f"Leave ${tip:.2f}") 7 | 8 | 9 | def dollars_to_float(d): 10 | return float(d[1:]) 11 | 12 | 13 | def percent_to_float(p): 14 | return int(p[:-1]) / 100 15 | 16 | 17 | main() 18 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_01/bank/bank.py: -------------------------------------------------------------------------------- 1 | g = input("Greeting: ").strip() 2 | 3 | if g.startswith("Hello"): 4 | print("$0") 5 | else: 6 | print(f"\$${20 if g[0].lower() == 'h' else 100}") 7 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_01/deep/deep.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | print("Yes" if bool( 4 | re.match( 5 | "(fou?rty ?-?two)|42", 6 | input("What is the Answer to the Great Question of Life, the Universe, and Everything? ").strip().lower() 7 | )) else "No") 8 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_01/extensions/extensions.py: -------------------------------------------------------------------------------- 1 | content_types = { 2 | "gif": "image/gif", 3 | "jpg": "image/jpeg", 4 | "jpeg": "image/jpeg", 5 | "png": "image/png", 6 | "pdf": "application/pdf", 7 | "txt": "text/plain", 8 | "zip": "application/zip", 9 | } 10 | 11 | print( 12 | content_types.get( 13 | input("File Name: ").split(".").pop().strip().lower(), 14 | "application/octet-stream")) 15 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_01/interpreter/interpreter.py: -------------------------------------------------------------------------------- 1 | print(float(eval(input("Expression: ")))) 2 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_01/meal/meal.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | time_str = input("What time is it? ") 3 | meal_time = check_meal_time(time_str) 4 | 5 | if meal_time: 6 | print(meal_time + " time") 7 | 8 | 9 | def convert(time): 10 | hours, minutes = map(int, time.split(':')) 11 | return hours + minutes / 60 12 | 13 | 14 | def check_meal_time(time_str): 15 | time = convert(time_str) 16 | 17 | if 7 <= time < 8: 18 | return "Breakfast" 19 | elif 12 <= time <= 13: 20 | return "Lunch" 21 | elif 18 <= time < 19: 22 | return "Dinner" 23 | else: 24 | return None 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_02/camel/camel.py: -------------------------------------------------------------------------------- 1 | print("snake_case:", 2 | "".join(["_" + i.lower() if i.isupper() 3 | else i for i in str(input("camelCase: "))]) 4 | ) 5 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_02/coke/coke.py: -------------------------------------------------------------------------------- 1 | # I have tried just about everything but my solution is not being accepted 2 | # by check50. 3 | """ 4 | s = 0 5 | while s < 50: 6 | print(f"Amount Due: {50 - s}") 7 | coin = int(input("Insert Coin: ")) 8 | if coin not in [25, 10, 5]: 9 | continue 10 | s += coin 11 | 12 | print(f"Change Owed: {max(s - 50, 0)}") 13 | """ 14 | 15 | # https://stackoverflow.com/questions/76821895/coke-machine-cs50-pset2-problem-2-while-loop-issue 16 | 17 | amount_due = 50 18 | coins = [5, 10, 25] 19 | 20 | while amount_due > 0: 21 | print(f"Amount Due: {amount_due}") 22 | 23 | coin = int(input("Insert Coin: ")) 24 | 25 | if coin in coins: 26 | amount_due -= coin 27 | 28 | print(f"Change Owed: {abs(amount_due)}") 29 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_02/foo: -------------------------------------------------------------------------------- 1 | while (s := 0) < 50: 2 | print(f"Amount Due: {50 - s}") 3 | coin = int(input("Insert Coin: ")) 4 | if coin not in [25, 10, 5]: 5 | continue 6 | s += coin 7 | 8 | print(f"Change Owed: {max(s - 50, 0)}") 9 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_02/nutrition/nutrition.py: -------------------------------------------------------------------------------- 1 | nutrition_data = { 2 | 'Apple': {'Calories': 130}, 3 | 'Avocado': {'Calories': 50}, 4 | 'Banana': {'Calories': 110}, 5 | 'Cantaloupe': {'Calories': 50}, 6 | 'Grapefruit': {'Calories': 60}, 7 | 'Grapes': {'Calories': 90}, 8 | 'Honeydew Melon': {'Calories': 50}, 9 | 'Kiwifruit': {'Calories': 90}, 10 | 'Lemon': {'Calories': 15}, 11 | 'Lime': {'Calories': 20}, 12 | 'Nectarine': {'Calories': 60}, 13 | 'Orange': {'Calories': 80}, 14 | 'Peach': {'Calories': 60}, 15 | 'Pear': {'Calories': 100}, 16 | 'Pineapple': {'Calories': 50}, 17 | 'Plums': {'Calories': 70}, 18 | 'Strawberries': {'Calories': 50}, 19 | 'Sweet Cherries': {'Calories': 100}, 20 | 'Tangerine': {'Calories': 50}, 21 | 'Watermelon': {'Calories': 80}, 22 | } 23 | 24 | 25 | def main(): 26 | fruit = input("Enter a fruit: ") 27 | fruit = fruit.title() 28 | 29 | if fruit in nutrition_data: 30 | calories = nutrition_data[fruit]['Calories'] 31 | print(f"Calories: {calories}") 32 | else: 33 | print("") 34 | 35 | 36 | if __name__ == "__main__": 37 | main() 38 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_02/plates/plates.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | print("Valid" if is_valid(input("Input: ")) else "Invalid") 3 | 4 | 5 | def is_valid(s): 6 | if not (len(s) >= 2 and len(s) <= 6): 7 | return False 8 | 9 | if any((i in s for i in [" ", ".", "?"])): 10 | return False 11 | 12 | nums = [i for i in s if i.isdigit()] 13 | if len(nums) and nums[0] == '0': 14 | return False 15 | 16 | if len(nums) and not (s[0].isdigit() or s[-1:].isdigit()): 17 | return False 18 | 19 | return True 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_02/twttr/twttr.py: -------------------------------------------------------------------------------- 1 | print("Output:", 2 | "".join([i for i in str(input("Input: ")) if i.lower() not in "aeiou"]) 3 | ) 4 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_03/fuel/fuel.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | while True: 3 | try: 4 | fraction_str = input("Enter a fraction (X/Y): ") 5 | numerator, denominator = map(int, fraction_str.split('/')) 6 | 7 | if not (isinstance(numerator, int) and isinstance( 8 | denominator, int) and denominator != 0 and numerator <= denominator): 9 | raise ValueError 10 | 11 | percentage = round((numerator / denominator) * 100) 12 | 13 | if percentage <= 1: 14 | print("E") 15 | elif percentage >= 99: 16 | print("F") 17 | else: 18 | print(f"{percentage}%") 19 | 20 | break 21 | except (ValueError, ZeroDivisionError): 22 | print("Invalid input. Please enter a valid fraction.") 23 | 24 | 25 | if __name__ == "__main__": 26 | main() 27 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_03/grocery/grocery.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | grocery_list = {} 3 | try: 4 | while True: 5 | item = input().title() 6 | grocery_list[item] = grocery_list.get(item, 0) + 1 7 | except EOFError: 8 | pass 9 | 10 | sorted_list = sorted(grocery_list.items(), key=lambda x: x[0]) 11 | 12 | for item, count in sorted_list: 13 | print(f"{count} {item.upper()}") 14 | 15 | 16 | if __name__ == "__main__": 17 | main() 18 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_03/outdated/outdated.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | 4 | def month_to_number(month): 5 | months = [ 6 | "January", "February", "March", "April", "May", "June", 7 | "July", "August", "September", "October", "November", "December" 8 | ] 9 | return months.index(month) + 1 10 | 11 | 12 | def convert_to_iso_date(): 13 | while True: 14 | user_input = input( 15 | "Date: ") 16 | user_input = user_input.strip() 17 | 18 | try: 19 | date_obj = datetime.strptime(user_input, "%m/%d/%Y") 20 | 21 | except ValueError: 22 | try: 23 | date_obj = datetime.strptime(user_input, "%B %d, %Y") 24 | 25 | except ValueError: 26 | print("Invalid date. Please try again.") 27 | continue 28 | 29 | iso_date = date_obj.strftime("%Y-%m-%d") 30 | print(iso_date) 31 | break 32 | 33 | 34 | if __name__ == "__main__": 35 | convert_to_iso_date() 36 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_03/taqueria/taqueria.py: -------------------------------------------------------------------------------- 1 | menu_prices = { 2 | "Baja Taco": 4.25, 3 | "Burrito": 7.50, 4 | "Bowl": 8.50, 5 | "Nachos": 11.00, 6 | "Quesadilla": 8.50, 7 | "Super Burrito": 8.50, 8 | "Super Quesadilla": 9.50, 9 | "Taco": 3.00, 10 | "Tortilla Salad": 8.00 11 | } 12 | 13 | total_cost = 0.00 14 | 15 | try: 16 | while True: 17 | print("Enter an item: ", end="") 18 | item = input() 19 | item = item.title() 20 | 21 | if item in menu_prices: 22 | total_cost += menu_prices[item] 23 | print(f"Total: ${total_cost:.2f}") 24 | elif not item: 25 | pass 26 | else: 27 | continue 28 | 29 | except EOFError: 30 | pass 31 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_04/adieu/adieu.py: -------------------------------------------------------------------------------- 1 | def bid_adieu(names): 2 | if len(names) == 1: 3 | print(f"Adieu, adieu, to {names[0]}") 4 | elif len(names) == 2: 5 | print(f"Adieu, adieu, to {names[0]} and {names[1]}") 6 | else: 7 | farewell = f"Adieu, adieu, to {', '.join(names[:-1])}, and {names[-1]}" 8 | print(farewell) 9 | 10 | 11 | def main(): 12 | names = [] 13 | try: 14 | while True: 15 | name = input() 16 | names.append(name) 17 | except EOFError: 18 | bid_adieu(names) 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_04/bitcoin/bitcoin.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import requests 3 | 4 | 5 | def main(): 6 | if len(sys.argv) != 2: 7 | print("Missing command-line argument") 8 | sys.exit(1) 9 | 10 | try: 11 | bitcoins_to_buy = float(sys.argv[1]) 12 | except ValueError: 13 | print("Command-line argument is not a number") 14 | sys.exit(1) 15 | 16 | try: 17 | response = requests.get( 18 | "https://api.coindesk.com/v1/bpi/currentprice.json") 19 | response.raise_for_status() 20 | data = response.json() 21 | bitcoin_price = data["bpi"]["USD"]["rate_float"] 22 | except requests.RequestException as e: 23 | print(f"Error fetching Bitcoin price: {e}") 24 | sys.exit(1) 25 | 26 | total_cost = bitcoins_to_buy * bitcoin_price 27 | print( 28 | f"The current cost of {bitcoins_to_buy:,.4f} Bitcoins is ${total_cost:,.4f}") 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_04/emojize/emojize.py: -------------------------------------------------------------------------------- 1 | import emoji 2 | 3 | if __name__ == "__main__": 4 | user_input = input("Input: ") 5 | print("Output:", emoji.emojize(user_input, language='alias')) 6 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_04/figlet/figlet.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pyfiglet 3 | 4 | 5 | def main(): 6 | if len(sys.argv) not in [1, 3] or (len(sys.argv) 7 | == 3 and sys.argv[1] not in ['-f', '--font']): 8 | sys.exit("Invalid usage") 9 | 10 | font = None 11 | if len(sys.argv) == 3: 12 | if sys.argv[1] not in ['-f', '--font'] or not sys.argv[2]: 13 | sys.exit("Invalid usage") 14 | font = sys.argv[2] 15 | 16 | text = input("Enter text: ") 17 | 18 | if font: 19 | try: 20 | ascii_art = pyfiglet.figlet_format(text, font=font) 21 | print(ascii_art) 22 | except pyfiglet.FigletError: 23 | sys.exit("Invalid usage") 24 | else: 25 | ascii_art = pyfiglet.figlet_format(text) 26 | print(ascii_art) 27 | 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_04/game/game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | 4 | def get_level(): 5 | while True: 6 | try: 7 | level = int(input("Level: ")) 8 | if level > 0: 9 | return level 10 | else: 11 | print("Please enter a positive integer.") 12 | except ValueError: 13 | print("Please enter a valid integer.") 14 | 15 | 16 | def guess_number(): 17 | return random.randint(1, level) 18 | 19 | 20 | def get_user_guess(): 21 | while True: 22 | try: 23 | guess = int(input("Guess: ")) 24 | if guess > 0: 25 | return guess 26 | except ValueError: 27 | print("Please enter a valid integer.") 28 | 29 | 30 | def main(): 31 | global level 32 | level = get_level() 33 | secret_number = guess_number() 34 | 35 | while True: 36 | user_guess = get_user_guess() 37 | 38 | if user_guess < secret_number: 39 | print("Too small!") 40 | elif user_guess > secret_number: 41 | print("Too large!") 42 | else: 43 | print("Just right!") 44 | break 45 | 46 | 47 | if __name__ == "__main__": 48 | main() 49 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_04/professor/professor.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | 4 | def main(): 5 | level = get_level() 6 | score = 0 7 | 8 | for _ in range(10): 9 | x, y = generate_integer(level) 10 | problem = f"{x} + {y} = " 11 | user_answer = prompt_for_answer(problem) 12 | 13 | if user_answer == x + y: 14 | print("Correct!") 15 | score += 1 16 | else: 17 | print("EEE") 18 | correct_answer = x + y 19 | for _ in range(2): # Allowing up to three tries 20 | user_answer = prompt_for_answer(problem) 21 | if user_answer == correct_answer: 22 | print("Correct!") 23 | score += 1 24 | break 25 | else: 26 | print("EEE") 27 | else: 28 | print(f"The correct answer is {correct_answer}") 29 | 30 | print(f"Your score is: {score}/10") 31 | 32 | 33 | def get_level(): 34 | while True: 35 | try: 36 | level = int(input("Level: ")) 37 | if level in [1, 2, 3]: 38 | return level 39 | else: 40 | print("Please enter 1, 2, or 3.") 41 | except ValueError: 42 | print("Please enter a valid number.") 43 | 44 | 45 | def generate_integer(level): 46 | if level == 1: 47 | x = random.randint(0, 9) 48 | y = random.randint(0, 9) 49 | elif level == 2: 50 | x = random.randint(10, 99) 51 | y = random.randint(10, 99) 52 | elif level == 3: 53 | x = random.randint(100, 999) 54 | y = random.randint(100, 999) 55 | else: 56 | raise ValueError("Invalid level") 57 | 58 | return x, y 59 | 60 | 61 | def prompt_for_answer(problem): 62 | while True: 63 | try: 64 | user_answer = int(input(problem)) 65 | return user_answer 66 | except ValueError: 67 | print("Please enter a valid number.") 68 | 69 | 70 | if __name__ == "__main__": 71 | main() 72 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/.gitignore: -------------------------------------------------------------------------------- 1 | */__pycache__ 2 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_bank/bank.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | pass 3 | 4 | 5 | def value(greeting): 6 | if greeting.lower().startswith("hello"): 7 | return 0 8 | else: 9 | return 20 if greeting[0].lower() == 'h' else 100 10 | 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_bank/test_bank.py: -------------------------------------------------------------------------------- 1 | import bank 2 | 3 | 4 | def test_value_starts_with_hello(): 5 | assert bank.value("Hello, World!") == 0 6 | 7 | 8 | def test_value_starts_with_h(): 9 | assert bank.value("Hi there!") == 20 10 | 11 | 12 | def test_value_default_case(): 13 | assert bank.value("What's up?") == 100 14 | 15 | 16 | def test_value_case_insensitive(): 17 | assert bank.value("HELLO, Everyone!") == 0 18 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_fuel/fuel.py: -------------------------------------------------------------------------------- 1 | def convert(fraction): 2 | try: 3 | numerator, denominator = map(int, fraction.split('/')) 4 | if denominator == 0: 5 | raise ZeroDivisionError 6 | 7 | if not (isinstance(numerator, int) and isinstance(denominator, 8 | int) and denominator != 0 and numerator <= denominator): 9 | raise ValueError 10 | 11 | percentage = round((numerator / denominator) * 100) 12 | return percentage 13 | except (ValueError, ZeroDivisionError): 14 | raise 15 | 16 | 17 | def gauge(percentage): 18 | try: 19 | if percentage <= 1: 20 | return "E" 21 | elif percentage >= 99: 22 | return "F" 23 | else: 24 | return f"{percentage}%" 25 | except ValueError: 26 | raise 27 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_fuel/test_fuel.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from fuel import convert, gauge 3 | 4 | 5 | def test_convert_valid_fraction(): 6 | result = convert("3/5") 7 | assert result == 60 8 | 9 | 10 | def test_convert_invalid_fraction_non_integer(): 11 | with pytest.raises(ValueError): 12 | convert("2.5/3") 13 | 14 | 15 | def test_convert_invalid_fraction_x_greater_than_y(): 16 | with pytest.raises(ValueError): 17 | convert("5/3") 18 | 19 | 20 | def test_convert_invalid_fraction_zero_division(): 21 | with pytest.raises(ZeroDivisionError): 22 | convert("5/0") 23 | 24 | 25 | def test_gauge_e_grade(): 26 | result = gauge(1) 27 | assert result == "E" 28 | 29 | 30 | def test_gauge_f_grade(): 31 | result = gauge(99) 32 | assert result == "F" 33 | 34 | 35 | def test_gauge_percentage_grade(): 36 | result = gauge(75) 37 | assert result == "75%" 38 | 39 | 40 | def main(): 41 | pytest.main(['-v', __file__]) 42 | 43 | 44 | if __name__ == "__main__": 45 | main() 46 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_plates/plates.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | print("Valid" if is_valid(input("Input: ")) else "Invalid") 3 | 4 | 5 | def is_valid(s): 6 | if not (len(s) >= 2 and len(s) <= 6): 7 | return False 8 | 9 | if any((i in s for i in [" ", ".", "?"])): 10 | return False 11 | 12 | nums = [i for i in s if i.isdigit()] 13 | if len(nums) and nums[0] == '0': 14 | return False 15 | 16 | if len(nums) and not (s[0].isdigit() or s[-1:].isdigit()): 17 | return False 18 | 19 | return True 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_plates/test_plates.py: -------------------------------------------------------------------------------- 1 | from plates import is_valid 2 | 3 | 4 | def main(): 5 | test_min_max_characters() 6 | test_start_with_two_letters() 7 | test_number_zero() 8 | test_number_zero() 9 | test_special_chars() 10 | 11 | 12 | def test_min_max_characters(): 13 | assert is_valid("AA") == True 14 | assert is_valid("ABCDEF") == True 15 | assert is_valid("A") == False 16 | assert is_valid("ABCDEFGH") == False 17 | 18 | 19 | def test_start_with_two_letters(): 20 | assert is_valid("AA") == True 21 | assert is_valid("A2") == False 22 | assert is_valid("2A") == False 23 | assert is_valid("2") == False 24 | 25 | 26 | def test_numbers_middle(): 27 | assert is_valid("AAA222") == True 28 | assert is_valid("AAA22A") == False 29 | 30 | 31 | def test_number_zero(): 32 | assert is_valid("CS50") == True 33 | assert is_valid("CS05") == False 34 | 35 | 36 | def test_special_chars(): 37 | assert is_valid("????") == False 38 | 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_twttr/test_twttr.py: -------------------------------------------------------------------------------- 1 | from twttr import shorten 2 | 3 | 4 | def test_shorten_no_vowels(): 5 | assert shorten("hello") == "hll" 6 | 7 | 8 | def test_shorten_with_vowels(): 9 | assert shorten("Python") == "Pythn" 10 | 11 | 12 | def test_shorten_empty_string(): 13 | assert shorten("") == "" 14 | 15 | 16 | def test_shorten_all_vowels(): 17 | assert shorten("AEIOUaeiou") == "" 18 | 19 | 20 | def test_shorten_capitalized_vowels(): 21 | assert shorten("AEIOU") == "" 22 | 23 | 24 | def test_shorten_lowercase_vowels(): 25 | assert shorten("aeiou") == "" 26 | 27 | 28 | def test_shorten_with_numbers(): 29 | assert shorten("hello123") == "hll123" 30 | 31 | 32 | def test_shorten_printing_in_uppercase(): 33 | assert shorten("HELLO") == "HLL" 34 | 35 | 36 | def test_shorten_with_punctuation(): 37 | assert shorten("Hello, World") == "Hll, Wrld" 38 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_05/test_twttr/twttr.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | pass 3 | 4 | 5 | def shorten(word): 6 | return "".join([i for i in word 7 | if i.lower() not in "aeiou"]) 8 | 9 | 10 | if __name__ == "__main__": 11 | main() 12 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/lines/lines.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def count_lines(file_path): 4 | try: 5 | with open(file_path, 'r') as file: 6 | lines = file.readlines() 7 | return len([line for line in lines if not is_comment_or_blank(line)]) 8 | except FileNotFoundError: 9 | sys.exit("File does not exist") 10 | except Exception as e: 11 | sys.exit(f"An error occurred: {e}") 12 | 13 | def is_comment_or_blank(line): 14 | cleaned_line = line.strip() 15 | return cleaned_line == '' or cleaned_line.startswith('#') or cleaned_line.startswith('"""') or cleaned_line.startswith("'''") 16 | 17 | def count_lines_exclude_docstrings(file_path): 18 | try: 19 | with open(file_path, 'r') as file: 20 | lines = file.readlines() 21 | in_docstring = False 22 | return len([line for line in lines if not is_comment_or_blank(line, in_docstring)]) 23 | except FileNotFoundError: 24 | sys.exit("File does not exist") 25 | except Exception as e: 26 | sys.exit(f"An error occurred: {e}") 27 | 28 | def is_comment_or_blank(line, in_docstring): 29 | cleaned_line = line.strip() 30 | 31 | if in_docstring: 32 | if cleaned_line.endswith('"""') or cleaned_line.endswith("'''"): 33 | in_docstring = False 34 | return True 35 | else: 36 | if cleaned_line.startswith('"""') or cleaned_line.startswith("'''"): 37 | in_docstring = True 38 | return cleaned_line == '' or cleaned_line.startswith('#') 39 | 40 | def main(): 41 | if len(sys.argv) != 2: 42 | sys.exit("Too few or too many command-line arguments") 43 | 44 | file_path = sys.argv[1] 45 | 46 | if not file_path.endswith('.py'): 47 | sys.exit("Not a Python file") 48 | 49 | lines_count = count_lines_exclude_docstrings(file_path) 50 | print(lines_count) 51 | 52 | if __name__ == "__main__": 53 | main() 54 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/pizza/pizza.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import csv 3 | 4 | def read_csv(file_path): 5 | try: 6 | with open(file_path, 'r') as file: 7 | return list(csv.DictReader(file)) 8 | except FileNotFoundError: 9 | sys.exit("File does not exist") 10 | except Exception as e: 11 | sys.exit(f"An error occurred: {e}") 12 | 13 | def print_pizza_table(file_path): 14 | pizza_data = read_csv(file_path) 15 | 16 | headers = pizza_data[0].keys() 17 | max_col_widths = {header: max(len(str(row[header])) for row in pizza_data) for header in headers} 18 | total_width = sum(max_col_widths.values()) + len(headers) * 3 - 1 19 | 20 | print(f"+{'-' * total_width}+") 21 | print(f"| {' | '.join(header.ljust(max_col_widths[header]) for header in headers)} |") 22 | print(f"+{'-' * total_width}+") 23 | 24 | for row in pizza_data: 25 | print(f"| {' | '.join(str(row[header]).ljust(max_col_widths[header]) for header in headers)} |") 26 | 27 | print(f"+{'-' * total_width}+") 28 | 29 | def main(): 30 | if len(sys.argv) != 2: 31 | sys.exit("Too few or too many command-line arguments") 32 | 33 | file_path = sys.argv[1] 34 | 35 | if not file_path.endswith('.csv'): 36 | sys.exit("Not a CSV file") 37 | 38 | print_pizza_table(file_path) 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/pizza/sicilian.csv: -------------------------------------------------------------------------------- 1 | Sicilian Pizza,Small,Large 2 | Cheese,$25.50,$39.95 3 | 1 item,$27.50,$41.95 4 | 2 items,$29.50,$43.95 5 | 3 items,$31.50,$45.95 6 | Special,$33.50,$47.95 7 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/scourgify/after.csv: -------------------------------------------------------------------------------- 1 | first,last,house 2 | Hannah,Abbott,Hufflepuff 3 | Katie,Bell,Gryffindor 4 | Susan,Bones,Hufflepuff 5 | Terry,Boot,Ravenclaw 6 | Lavender,Brown,Gryffindor 7 | Millicent,Bulstrode,Slytherin 8 | Cho,Chang,Ravenclaw 9 | Penelope,Clearwater,Ravenclaw 10 | Vincent,Crabbe,Slytherin 11 | Colin,Creevey,Gryffindor 12 | Dennis,Creevey,Gryffindor 13 | Cedric,Diggory,Hufflepuff 14 | Marietta,Edgecombe,Ravenclaw 15 | Justin,Finch-Fletchley,Hufflepuff 16 | Seamus,Finnigan,Gryffindor 17 | Anthony,Goldstein,Ravenclaw 18 | Gregory,Goyle,Slytherin 19 | Hermione,Granger,Gryffindor 20 | Angelina,Johnson,Gryffindor 21 | Lee,Jordan,Gryffindor 22 | Neville,Longbottom,Gryffindor 23 | Luna,Lovegood,Ravenclaw 24 | Remus,Lupin,Gryffindor 25 | Draco,Malfoy,Slytherin 26 | Scorpius,Malfoy,Slytherin 27 | Ernie,Macmillan,Hufflepuff 28 | Minerva,McGonagall,Gryffindor 29 | Eloise,Midgen,Gryffindor 30 | Cormac,McLaggen,Gryffindor 31 | Graham,Montague,Slytherin 32 | Theodore,Nott,Slytherin 33 | Pansy,Parkinson,Slytherin 34 | Padma,Patil,Gryffindor 35 | Parvati,Patil,Gryffindor 36 | Harry,Potter,Gryffindor 37 | Tom,Riddle,Slytherin 38 | Demelza,Robins,Gryffindor 39 | Newt,Scamander,Hufflepuff 40 | Horace,Slughorn,Slytherin 41 | Zacharias,Smith,Hufflepuff 42 | Severus,Snape,Slytherin 43 | Alicia,Spinnet,Gryffindor 44 | Pomona,Sprout,Hufflepuff 45 | Dean,Thomas,Gryffindor 46 | Romilda,Vane,Gryffindor 47 | Myrtle,Warren,Ravenclaw 48 | Fred,Weasley,Gryffindor 49 | George,Weasley,Gryffindor 50 | Ginny,Weasley,Gryffindor 51 | Percy,Weasley,Gryffindor 52 | Ron,Weasley,Gryffindor 53 | Oliver,Wood,Gryffindor 54 | Blaise,Zabini,Slytherin 55 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/scourgify/before.csv: -------------------------------------------------------------------------------- 1 | name,house 2 | "Abbott, Hannah",Hufflepuff 3 | "Bell, Katie",Gryffindor 4 | "Bones, Susan",Hufflepuff 5 | "Boot, Terry",Ravenclaw 6 | "Brown, Lavender",Gryffindor 7 | "Bulstrode, Millicent",Slytherin 8 | "Chang, Cho",Ravenclaw 9 | "Clearwater, Penelope",Ravenclaw 10 | "Crabbe, Vincent",Slytherin 11 | "Creevey, Colin",Gryffindor 12 | "Creevey, Dennis",Gryffindor 13 | "Diggory, Cedric",Hufflepuff 14 | "Edgecombe, Marietta",Ravenclaw 15 | "Finch-Fletchley, Justin",Hufflepuff 16 | "Finnigan, Seamus",Gryffindor 17 | "Goldstein, Anthony",Ravenclaw 18 | "Goyle, Gregory",Slytherin 19 | "Granger, Hermione",Gryffindor 20 | "Johnson, Angelina",Gryffindor 21 | "Jordan, Lee",Gryffindor 22 | "Longbottom, Neville",Gryffindor 23 | "Lovegood, Luna",Ravenclaw 24 | "Lupin, Remus",Gryffindor 25 | "Malfoy, Draco",Slytherin 26 | "Malfoy, Scorpius",Slytherin 27 | "Macmillan, Ernie",Hufflepuff 28 | "McGonagall, Minerva",Gryffindor 29 | "Midgen, Eloise",Gryffindor 30 | "McLaggen, Cormac",Gryffindor 31 | "Montague, Graham",Slytherin 32 | "Nott, Theodore",Slytherin 33 | "Parkinson, Pansy",Slytherin 34 | "Patil, Padma",Gryffindor 35 | "Patil, Parvati",Gryffindor 36 | "Potter, Harry",Gryffindor 37 | "Riddle, Tom",Slytherin 38 | "Robins, Demelza",Gryffindor 39 | "Scamander, Newt",Hufflepuff 40 | "Slughorn, Horace",Slytherin 41 | "Smith, Zacharias",Hufflepuff 42 | "Snape, Severus",Slytherin 43 | "Spinnet, Alicia",Gryffindor 44 | "Sprout, Pomona",Hufflepuff 45 | "Thomas, Dean",Gryffindor 46 | "Vane, Romilda",Gryffindor 47 | "Warren, Myrtle",Ravenclaw 48 | "Weasley, Fred",Gryffindor 49 | "Weasley, George",Gryffindor 50 | "Weasley, Ginny",Gryffindor 51 | "Weasley, Percy",Gryffindor 52 | "Weasley, Ron",Gryffindor 53 | "Wood, Oliver",Gryffindor 54 | "Zabini, Blaise",Slytherin 55 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/scourgify/scourgify.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import csv 3 | 4 | def scourgify(input_file, output_file): 5 | try: 6 | with open(input_file, 'r') as infile, open(output_file, 'w', newline='') as outfile: 7 | reader = csv.DictReader(infile) 8 | fieldnames = ['first', 'last', 'house'] 9 | writer = csv.DictWriter(outfile, fieldnames=fieldnames) 10 | writer.writeheader() 11 | 12 | for row in reader: 13 | full_name = row['name'].strip('"') 14 | last_name, first_name = map(str.strip, full_name.split(',')) 15 | writer.writerow({'first': first_name, 'last': last_name, 'house': row['house']}) 16 | 17 | except FileNotFoundError: 18 | sys.exit(f"Could not read {input_file}") 19 | except Exception as e: 20 | 21 | sys.exit(f"An error occurred: {e}") 22 | 23 | def main(): 24 | if len(sys.argv) != 3: 25 | sys.exit("Too few or too many command-line arguments") 26 | 27 | input_file = sys.argv[1] 28 | output_file = sys.argv[2] 29 | 30 | scourgify(input_file, output_file) 31 | print(f"Scourgification complete! Check {output_file} for the cleaned data.") 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/shirt/shirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_06/shirt/shirt.png -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_06/shirt/shirt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PIL import Image, ImageOps 3 | 4 | def overlay_shirt(input_path, output_path, shirt_path="shirt.png"): 5 | try: 6 | input_image = Image.open(input_path) 7 | shirt_image = Image.open(shirt_path) 8 | 9 | input_extension = input_path.lower().split('.')[-1] 10 | output_extension = output_path.lower().split('.')[-1] 11 | 12 | if input_extension != output_extension: 13 | sys.exit("Input and output must have the same extension.") 14 | 15 | # https://www.reddit.com/r/cs50/comments/uvqiz0/cs50p_project6_shirtpy_image_does_not_match/ 16 | input_image = ImageOps.fit(input_image, shirt_image.size) 17 | 18 | input_image.paste(shirt_image, (0, 0), shirt_image) 19 | input_image.save(output_path) 20 | 21 | print(f"Virtual shirt overlay complete! Check {output_path} for the result.") 22 | except FileNotFoundError: 23 | sys.exit(f"Input image {input_path} does not exist.") 24 | except Exception as e: 25 | sys.exit(f"An error occurred: {e}") 26 | 27 | def main(): 28 | if len(sys.argv) != 3: 29 | sys.exit("Usage: python shirt.py ") 30 | 31 | input_path = sys.argv[1] 32 | output_path = sys.argv[2] 33 | 34 | valid_extensions = ('.jpg', '.jpeg', '.png') 35 | if not input_path.lower().endswith(valid_extensions) or not output_path.lower().endswith(valid_extensions): 36 | sys.exit("Invalid input or output format. Use .jpg, .jpeg, or .png.") 37 | 38 | overlay_shirt(input_path, output_path) 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/__pycache__/numb3rs.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/__pycache__/numb3rs.cpython-310.pyc -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/__pycache__/test_numb3rs.cpython-310-pytest-7.4.4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/__pycache__/test_numb3rs.cpython-310-pytest-7.4.4.pyc -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/numb3rs.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | def main(): 5 | print(validate(input("IPv4 Address: "))) 6 | 7 | 8 | def validate(ip): 9 | s = [i.isdigit() and int(i) <= 255 for i in ip.strip().split(".")] 10 | return all(s) and len(s) == 4 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/test_numb3rs.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from numb3rs import validate 3 | 4 | def test_valid_ipv4(): 5 | assert validate("127.0.0.1") == True 6 | assert validate("255.255.255.255") == True 7 | assert validate("192.168.1.1") == True 8 | 9 | def test_invalid_ipv4(): 10 | assert validate("512.512.512.512") == False 11 | assert validate("1.2.3.1000") == False 12 | assert validate("cat") == False 13 | assert validate("256.0.0.1") == False 14 | assert validate("192.168.1.1.1") == False 15 | 16 | def test_edge_cases(): 17 | # Minimum valid IPv4 address 18 | assert validate("0.0.0.0") == True 19 | 20 | # Maximum valid IPv4 address 21 | assert validate("255.255.255.255") == True 22 | 23 | # Valid IPv4 addresses with leading zeros 24 | assert validate("001.002.003.004") == True 25 | assert validate("010.020.030.040") == True 26 | 27 | # Valid IPv4 addresses with spaces 28 | assert validate(" 127.0.0.1 ") == True 29 | assert validate(" 192.168.1.1 ") == True 30 | 31 | def test_mixed_formats(): 32 | # Valid IPv4 addresses in mixed formats 33 | assert validate("192.168.1.001") == True 34 | assert validate(" 010.020.030.040 ") == True 35 | 36 | def test_invalid_formats(): 37 | # Invalid IPv4 formats 38 | assert validate("256.0.0.1") == False 39 | assert validate("1.2.3.1000") == False 40 | assert validate("cat") == False 41 | assert validate("192.168.1.1.1") == False 42 | 43 | if __name__ == "__main__": 44 | pytest.main() 45 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/response/response.py: -------------------------------------------------------------------------------- 1 | import validators 2 | 3 | def main(): 4 | email = input("What's your email address? ") 5 | validate_email(email) 6 | 7 | def validate_email(email): 8 | if validators.email(email): 9 | print("Valid") 10 | else: 11 | print("Invalid") 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/response/test_response.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from response import validate_email 3 | 4 | def test_valid_email(): 5 | assert validate_email("malan@harvard.edu") == "Valid" 6 | assert validate_email("user@example.com") == "Valid" 7 | assert validate_email("john.doe123@domain.org") == "Valid" 8 | 9 | def test_invalid_email(): 10 | assert validate_email("malan@@@harvard.edu") == "Invalid" 11 | assert validate_email("user@example") == "Invalid" 12 | assert validate_email("john.doe@com") == "Invalid" 13 | assert validate_email("invalid.email@.com") == "Invalid" 14 | 15 | def test_mistyped_email(): 16 | assert validate_email("john.doe@domain..com") == "Invalid" 17 | assert validate_email("user@.example.com") == "Invalid" 18 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/um/test_um.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from um import count 3 | 4 | def test_single_um(): 5 | assert count("um") == 1 6 | 7 | def test_um_with_punctuation(): 8 | assert count("um?") == 1 9 | assert count("Um, thanks for the album.") == 1 10 | 11 | def test_multiple_um(): 12 | assert count("Um, thanks, um...") == 2 13 | assert count("um um um") == 3 14 | 15 | def test_case_insensitivity(): 16 | assert count("Um, uM, uM.") == 3 17 | 18 | def test_no_um(): 19 | assert count("Hello, world!") == 0 20 | assert count("The quick brown fox jumps over the lazy dog.") == 0 21 | 22 | def test_um_within_words(): 23 | assert count("humble umbrella") == 0 24 | assert count("drum") == 0 25 | 26 | def test_um_as_whole_word(): 27 | assert count("umbrella") == 0 28 | assert count("album") == 0 29 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/um/um.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | 5 | def main(): 6 | print(count(input("Text: "))) 7 | 8 | 9 | def count(s): 10 | pattern = re.compile(r"\b(um)\b") 11 | return len(re.findall(pattern, s.strip().lower())) 12 | 13 | 14 | if __name__ == "__main__": 15 | main() 16 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/watch/watch.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def main(): 4 | print(parse(input("HTML: "))) 5 | 6 | def parse(s): 7 | pattern = r"https?://(www\.)?youtube\.com/embed/[\w-]+" 8 | found = re.search(pattern, s) 9 | return f"https://youtu.be/{found.group().split('/').pop()}" if found else None 10 | 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/working/__pycache__/test_working.cpython-310-pytest-7.4.4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_07/working/__pycache__/test_working.cpython-310-pytest-7.4.4.pyc -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/working/__pycache__/working.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_07/working/__pycache__/working.cpython-310.pyc -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/working/test_working.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from working import convert 3 | 4 | def test_valid_12_hour_format(): 5 | assert convert("9 AM to 5 PM") == "09:00 to 17:00" 6 | assert convert("9:00 AM to 5:00 PM") == "09:00 to 17:00" 7 | assert convert("10 PM to 8 AM") == "22:00 to 08:00" 8 | assert convert("10:30 PM to 8:50 AM") == "22:30 to 08:50" 9 | 10 | def test_invalid_formats(): 11 | with pytest.raises(ValueError): 12 | convert("9:60 AM to 5:60 PM") 13 | 14 | def test_invalid_times(): 15 | with pytest.raises(ValueError): 16 | convert("12:60 AM to 5:00 PM") 17 | with pytest.raises(ValueError): 18 | convert("13:00 PM to 5:00 PM") 19 | with pytest.raises(ValueError): 20 | convert("9 AM to 13 PM") 21 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_07/working/working.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | 5 | def main(): 6 | print(convert(input("Hours: "))) 7 | 8 | 9 | def convert(s): 10 | pattern = r"[0-9]?[0-9](\:[0-5][0-9])? ([APap][Mm])?" 11 | elems = [elem.group() for elem in re.finditer(pattern, s.lower())] 12 | 13 | if len(elems) < 2: 14 | raise ValueError 15 | 16 | is_am = lambda e: "am" in e 17 | 18 | t = [] 19 | 20 | for elem in elems: 21 | lhs, rhs = elem[:-3].split(":") if ":" in elem else (elem[:-3], None) 22 | 23 | lhs = int(lhs) 24 | 25 | if lhs > 12 or (rhs and int(rhs) >= 60): 26 | raise ValueError 27 | 28 | 29 | if not is_am(elem) and lhs == 12: 30 | hours = "00:00" 31 | else: 32 | hours = int(lhs) + 12 if not is_am(elem) else int(lhs) 33 | 34 | formatted_time = f"{hours:02d}:{rhs}" if rhs else f"{hours:02d}:00" 35 | t.append(formatted_time) 36 | 37 | return " to ".join(t) 38 | 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/jar/jar.py: -------------------------------------------------------------------------------- 1 | class Jar: 2 | def __init__(self, capacity=12): 3 | if not isinstance(capacity, int) or capacity < 0: 4 | raise ValueError("Capacity must be a non-negative integer") 5 | self._capacity = capacity 6 | self._size = 0 7 | 8 | def __str__(self): 9 | return "🍪" * self._size 10 | 11 | def deposit(self, n): 12 | if not isinstance(n, int) or n < 0: 13 | raise ValueError("Number of cookies to deposit must be a non-negative integer") 14 | if self._size + n > self._capacity: 15 | raise ValueError("Exceeds jar capacity") 16 | self._size += n 17 | 18 | def withdraw(self, n): 19 | if not isinstance(n, int) or n < 0: 20 | raise ValueError("Number of cookies to withdraw must be a non-negative integer") 21 | if n > self._size: 22 | raise ValueError("Not enough cookies in the jar") 23 | self._size -= n 24 | 25 | @property 26 | def capacity(self): 27 | return self._capacity 28 | 29 | @property 30 | def size(self): 31 | return self._size 32 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/jar/test_jar.py: -------------------------------------------------------------------------------- 1 | from jar import Jar 2 | import pytest 3 | def test_init(): 4 | jar = Jar() 5 | assert jar.capacity == 12 6 | 7 | def test_str(): 8 | jar = Jar() 9 | jar.deposit(3) 10 | assert str(jar) == "🍪🍪🍪" 11 | 12 | def test_deposit(): 13 | jar = Jar() 14 | jar.deposit(2) 15 | assert jar.size == 2 16 | 17 | with pytest.raises(ValueError): 18 | jar.deposit(20) 19 | 20 | def test_withdraw(): 21 | jar = Jar() 22 | jar.deposit(5) 23 | jar.withdraw(2) 24 | assert jar.size == 3 25 | 26 | with pytest.raises(ValueError): 27 | jar.withdraw(5) 28 | 29 | with pytest.raises(ValueError): 30 | jar.withdraw(-1) 31 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/seasons/seasons.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | import re 4 | import inflect 5 | 6 | import sys 7 | 8 | infl_engine = inflect.engine() 9 | 10 | def calculate_time_in_minutes_as_word(date1, date2) -> str: 11 | try: 12 | d1 = datetime.strptime(date1, "%Y-%m-%d") 13 | d2 = datetime.strptime(date2, "%Y-%m-%d") 14 | except ValueError: 15 | raise 16 | 17 | minutes = round(abs((d2 - d1).total_seconds()) / 60) 18 | 19 | word = re.sub(r"\b ?(and) ?\b", " ", infl_engine.number_to_words(minutes)) 20 | return f"{word[0].upper() + word[1:]} minutes" 21 | 22 | def main(): 23 | inp = input("Date of Birth (YYYY-MM-DD): ") 24 | today = str(date.today()) 25 | 26 | try: 27 | out = calculate_time_in_minutes_as_word(inp, today) 28 | except ValueError: 29 | print("Invalid date format") 30 | sys.exit(1) 31 | 32 | print(f"{out}") 33 | 34 | if __name__ == "__main__": 35 | main() 36 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/seasons/test_seasons.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pytest 3 | from seasons import calculate_time_in_minutes_as_word 4 | 5 | def test_valid_timeframes(): 6 | d1 = "1999-01-01" 7 | d2 = "2000-01-01" 8 | ans = "Five hundred twenty-five thousand, six hundred minutes" 9 | 10 | assert ans == calculate_time_in_minutes_as_word(d1, d2) 11 | 12 | d1 = "1998-01-01" 13 | ans = "One million, fifty-one thousand, two hundred minutes" 14 | 15 | assert ans == calculate_time_in_minutes_as_word(d1, d2) 16 | 17 | def test_invalid_timeframes(): 18 | with pytest.raises(ValueError): 19 | calculate_time_in_minutes_as_word("invalid", "invalid") 20 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/shirtificate/shirtificate.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_08/shirtificate/shirtificate.pdf -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/shirtificate/shirtificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/ProblemSet_08/shirtificate/shirtificate.png -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/ProblemSet_08/shirtificate/shirtificate.py: -------------------------------------------------------------------------------- 1 | from fpdf import FPDF 2 | 3 | def get_name(): 4 | name = input("Enter your name: ") 5 | return name.strip() 6 | 7 | class CS50Shirtificate(FPDF): 8 | def add_header(self): 9 | self.add_page() 10 | self.set_font("helvetica", "B", 45) 11 | self.cell(0, 60, "CS50 Shirtificate", align="C") 12 | 13 | def add_body(self, name): 14 | self.image("./shirtificate.png", x=0, y=65) 15 | font_size = 30 - (len(name) % 30) 16 | self.set_font_size(font_size) 17 | self.set_text_color(255, 255, 255) 18 | self.text(x=47.5 + (font_size if font_size < 15 else 20), y=120, text=f"{name.title()} took CS50") 19 | 20 | name = get_name() 21 | 22 | pdf = CS50Shirtificate() 23 | 24 | pdf.add_header() 25 | pdf.add_body(name) 26 | 27 | pdf.output("shirtificate.pdf") 28 | 29 | print("Your 'shirtificate.pdf' is ready!") 30 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/README.md: -------------------------------------------------------------------------------- 1 | # CS50's Introduction to Programming with Python 2 | 3 | Started: Jan 26 2024 4 | 5 | 6 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/final_project/README.md: -------------------------------------------------------------------------------- 1 | # Practically API Wrapper 2 | 3 | #### Video Demo: https://www.youtube.com/watch?v=LuwIeIkvSHw 4 | #### Description: 5 | 6 | Unofficial api wrapper for [practically](https://www.practically.com) which is an OS used by many schools to publish assignments, report cards and lectures. 7 | 8 | - [Quickstart](#quickstart) 9 | - [Guide](#guide) 10 | - [Session](#session) 11 | - [Get User](#get-user) 12 | - [Get Classrooms](#get-classrooms) 13 | - [Get Assignments](#get-assignments) 14 | - [Recipes](#recipes) 15 | - [Get all assignments that are due in the future](get-all-assignments-that-are-due-in-the-future) 16 | 17 | ## Quickstart 18 | 19 | ```python 20 | from practically import Practically 21 | 22 | p = Practically() 23 | p.create_session("your-assigned-username", "your-password") 24 | 25 | user = p.get_user() 26 | print(user.first_name, user.last_name) 27 | ``` 28 | 29 | ## Guide 30 | 31 | ```python 32 | prac = Practically( 33 | base_url = "https://teach.practically.com", 34 | session_file = "session.pickle" 35 | ) 36 | ``` 37 | 38 | ### Session 39 | 40 | ```python 41 | prac.create_session("username", "password") 42 | ``` 43 | 44 | or, if you are using dotenv you can 45 | 46 | ```python 47 | prac.create_session_from_env("username_key", "password_key") 48 | ``` 49 | 50 | If a valid `session_id` is not found in the `session_file` it will create a new one. You can check if the current session is invalid using. 51 | 52 | ```python 53 | prac.is_session_expired_or_invalid() 54 | ``` 55 | 56 | ### Get User 57 | 58 | ```python 59 | user = prac.get_user() 60 | ``` 61 | - `user.email` 62 | - `user.first_name` 63 | - `user.last_name` 64 | 65 | ### Get Classrooms 66 | 67 | A user can be enrolled in one or more classrooms. 68 | 69 | ```python 70 | classrooms = prac.get_classrooms() 71 | print(len(classrooms)) # __getitem__ and __len__ can be used 72 | ``` 73 | 74 | A single clasroom looks like so 75 | 76 | - `classroom.name` 77 | - `classroom.owner` 78 | - `classroom.id` 79 | 80 | ### Get Assignments 81 | 82 | This returns all the assignments for the user 83 | 84 | ```python 85 | assignments = prac.get_assignments("123456") // you can get this through classrooms 86 | print(len(assignments)) # __getitem__ and __len__ can be used 87 | ``` 88 | 89 | A single clasroom looks like so 90 | 91 | - `assignment.title`: string 92 | - `assignment.start_time`: returns a datetime object 93 | - `assignment.end_time`: returns a datetime object 94 | - `assignment.attached_pdf_url`: return the link to the pdf CDN 95 | 96 | ## Recipes 97 | 98 | ### Get all assignments that are due in the future 99 | 100 | ```python 101 | from practically.practically import Practically 102 | 103 | from datetime import datetime 104 | 105 | from dotenv import load_dotenv 106 | load_dotenv() 107 | 108 | p = Practically() 109 | p.create_session_from_env("USERNAME", "PASSWORD") 110 | 111 | classroom_id = p.get_classrooms()[0].id 112 | assignments = [ 113 | a.title 114 | for a in p.get_assignments(classroom_id) 115 | if a.end_time > datetime.today() 116 | ] 117 | 118 | ``` 119 | 120 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/final_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Introduction_To_Programming_with_Python/final_project/__init__.py -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/final_project/requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.12.3 2 | certifi==2023.11.17 3 | cfgv==3.4.0 4 | charset-normalizer==3.3.2 5 | distlib==0.3.8 6 | exceptiongroup==1.2.0 7 | filelock==3.13.1 8 | identify==2.5.33 9 | idna==3.6 10 | iniconfig==2.0.0 11 | nodeenv==1.8.0 12 | packaging==23.2 13 | platformdirs==4.1.0 14 | pluggy==1.4.0 15 | pre-commit==3.6.0 16 | pytest==8.0.0 17 | python-dotenv==1.0.1 18 | PyYAML==6.0.1 19 | requests==2.31.0 20 | soupsieve==2.5 21 | tomli==2.0.1 22 | urllib3==2.1.0 23 | virtualenv==20.25.0 24 | -------------------------------------------------------------------------------- /Introduction_To_Programming_with_Python/final_project/test_project.py: -------------------------------------------------------------------------------- 1 | from dotenv import load_dotenv 2 | 3 | load_dotenv() 4 | 5 | from .project import Practically 6 | 7 | p = Practically() 8 | p.create_session_from_env("USERNAME", "PASSWORD") 9 | 10 | 11 | def test_if_can_get_classroom(): 12 | classrooms = p.get_classrooms() 13 | assert classrooms != None and len(classrooms) > 0 14 | 15 | 16 | def test_if_classroom_is_initialized(): 17 | classrooms = p.get_classrooms() 18 | assert classrooms[0].name != None 19 | 20 | 21 | def test_if_user_can_login(): 22 | user = p.get_user() 23 | assert len(user.first_name) > 1 24 | 25 | 26 | def test_should_work_if_session_is_invalid(): 27 | p.session_id = "foobarbaz" 28 | p.create_session_from_env("USERNAME", "PASSWORD") 29 | 30 | user = p.get_user() 31 | 32 | assert user is not None 33 | assert len(user.last_name) > 1 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Aadvik P 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/.gitignore: -------------------------------------------------------------------------------- 1 | */env 2 | */**/env 3 | 4 | 5 | */*.sqlite3 6 | 7 | */__pycache__ 8 | */**/__pycache__ 9 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project00_Search/imghp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Search 5 | 6 | 7 | 8 | 12 |
13 | 14 | 15 |
16 | Google 17 |
18 | images 19 |
20 |
21 |
22 | 23 | 24 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project00_Search/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Search 5 | 6 | 7 | 8 | 12 | 13 |
14 |
15 | Google 16 |
17 |
18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project00_Search/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap'); 2 | 3 | * { 4 | margin: 0; 5 | padding: 0; 6 | font-family: var(--font-sans); 7 | } 8 | 9 | :root { 10 | --bg-primary: #202124; 11 | --bg-secondary: #303134; 12 | --fg-primary: #e8eaed; 13 | --fg-secondary: #969ba1; 14 | --btn-accent: #5f6368; 15 | --blue-accent: #2a6af6; 16 | --font-sans: 'roboto', sans-serif; 17 | } 18 | 19 | body { 20 | background-color: var(--bg-primary); 21 | min-height: 100vh; 22 | } 23 | 24 | main { 25 | display: flex; 26 | flex-direction: column; 27 | gap: 1.5rem; 28 | align-items: center; 29 | min-width: 400px; 30 | max-width: 600px; 31 | width: 80%; 32 | margin: 20vh auto; 33 | } 34 | 35 | form { 36 | display: flex; 37 | flex-direction: column; 38 | align-items: center; 39 | width: 100%; 40 | gap: 1.75rem; 41 | } 42 | 43 | form div { 44 | display: flex; 45 | justify-content: center; 46 | gap: 1rem; 47 | } 48 | 49 | .btn { 50 | all: unset; 51 | cursor: pointer; 52 | } 53 | 54 | .btn--primary { 55 | border-radius: 4px; 56 | background-color: var(--bg-secondary); 57 | color: var(--fg-primary); 58 | padding: .7rem 1.25rem; 59 | } 60 | 61 | input[type="text"] { 62 | all: unset; 63 | width: 100%; 64 | border-radius: 100px; 65 | border: 2px solid var(--bg-secondary); 66 | height: 2.75em; 67 | padding-left: 1.25rem; 68 | color: var(--fg-primary); 69 | } 70 | 71 | .main__title { 72 | width: 272px; 73 | height: 92px; 74 | position: relative; 75 | } 76 | 77 | .actions { 78 | width: 100%; 79 | display: flex; 80 | justify-content: end; 81 | gap: 1.5rem; 82 | padding-block: 1.25rem; 83 | color: var(--fg-primary); 84 | margin-left: -1.5rem; 85 | } 86 | 87 | .hero-accent { 88 | position: absolute; 89 | bottom: 0; 90 | right: 0; 91 | color: var(--blue-accent); 92 | } 93 | 94 | .main__title img { 95 | width: 100%; 96 | } 97 | 98 | @media (hover: hover) { 99 | input:hover, input:focus { 100 | background-color: var(--bg-secondary) 101 | } 102 | 103 | .btn--primary:hover { 104 | outline: 1px solid var(--btn-accent) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class EncyclopediaConfig(AppConfig): 5 | name = 'encyclopedia' 6 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/migrations/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/static/encyclopedia/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | background-color: white; 4 | } 5 | 6 | code { 7 | white-space: pre; 8 | } 9 | 10 | h1 { 11 | margin-top: 0px; 12 | padding-top: 20px; 13 | } 14 | 15 | textarea { 16 | height: 90vh; 17 | width: 80%; 18 | } 19 | 20 | 21 | .main { 22 | padding: 10px; 23 | height: 100vh !important; 24 | overflow-y: scroll !important; 25 | } 26 | 27 | .search { 28 | width: 100%; 29 | font-size: 15px; 30 | line-height: 15px; 31 | } 32 | 33 | .sidebar { 34 | background-color: #f0f0f0; 35 | height: 100vh; 36 | padding: 20px; 37 | } 38 | 39 | .sidebar h2 { 40 | margin-top: 5px; 41 | } 42 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/templates/encyclopedia/edit_entry.html: -------------------------------------------------------------------------------- 1 | {% extends "encyclopedia/layout.html" %} 2 | 3 | {% block title %} 4 | Editing "{{ entry_title }}" 5 | {% endblock %} 6 | 7 | {% block body %} 8 | 9 |
10 | {% csrf_token %} 11 | 12 | 13 |
14 | 15 | 16 |
17 |
18 | 19 | 20 |
21 | 22 | 23 | Discard 24 |
25 | 26 | {% endblock %} 27 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/templates/encyclopedia/entry.html: -------------------------------------------------------------------------------- 1 | {% extends "encyclopedia/layout.html" %} 2 | 3 | {% block title %} 4 | {{ entry_title }} 5 | {% endblock %} 6 | 7 | {% block body %} 8 | 9 | 10 | Edit 11 | 12 |
13 | {{ entry_content | safe }} 14 |
15 | 16 | {% endblock %} 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/templates/encyclopedia/error.html: -------------------------------------------------------------------------------- 1 | {% extends "encyclopedia/layout.html" %} 2 | 3 | {% block title %} 4 | Error! 5 | {% endblock %} 6 | 7 | {% block body %} 8 |

{{ error_name }}

9 |

{{ error_desc }}

10 | {% endblock %} 11 | 12 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/templates/encyclopedia/index.html: -------------------------------------------------------------------------------- 1 | {% extends "encyclopedia/layout.html" %} 2 | 3 | {% block title %} 4 | Encyclopedia 5 | {% endblock %} 6 | 7 | {% block body %} 8 |

All Pages

9 | 10 | 11 | {% if entries|length == 0 %} 12 | No entries found 13 | {% else %} 14 | 15 |
    16 | {% for entry in entries %} 17 |
  • 18 | {{ entry }} 19 |
  • 20 | {% endfor %} 21 | 22 | 23 |
24 | {% endif %} 25 | 26 | {% endblock %} 27 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/templates/encyclopedia/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | 7 | {% block title %}{% endblock %} 8 | 9 | 10 | 11 | 12 |
13 | 30 |
31 | {% block body %} 32 | {% endblock %} 33 |
34 |
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/templates/encyclopedia/new_entry.html: -------------------------------------------------------------------------------- 1 | {% extends "encyclopedia/layout.html" %} 2 | 3 | {% block title %} 4 | New Entry 5 | {% endblock %} 6 | 7 | {% block body %} 8 | 9 |
10 | {% csrf_token %} 11 | 12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 | 21 | 22 | Discard 23 |
24 | 25 | {% endblock %} 26 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | 4 | from . import views 5 | 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("wiki//edit", views.edit_entry), 9 | path("random", views.random_entry), 10 | path("wiki//", views.entry), 11 | path("new_entry/", views.new_entry), 12 | ] 13 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/util.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from django.core.files.base import ContentFile 4 | from django.core.files.storage import default_storage 5 | import markdown 6 | 7 | 8 | def list_entries(): 9 | """ 10 | Returns a list of all names of encyclopedia entries. 11 | """ 12 | _, filenames = default_storage.listdir("entries") 13 | return list(sorted(re.sub(r"\.md$", "", filename) 14 | for filename in filenames if filename.endswith(".md"))) 15 | 16 | 17 | def save_entry(title, content): 18 | """ 19 | Saves an encyclopedia entry, given its title and Markdown 20 | content. If an existing entry with the same title already exists, 21 | it is replaced. 22 | """ 23 | filename = f"entries/{title}.md" 24 | if default_storage.exists(filename): 25 | default_storage.delete(filename) 26 | default_storage.save(filename, ContentFile(content)) 27 | 28 | def markdown_to_html(content): 29 | """ 30 | Uses python-markdown to convert md to html and returns it. 31 | Returns None in case of error 32 | """ 33 | try: 34 | return markdown.markdown(content) 35 | except Exception: 36 | return None 37 | 38 | 39 | def get_entry(title): 40 | """ 41 | Retrieves an encyclopedia entry by its title. If no such 42 | entry exists, the function returns None. 43 | """ 44 | try: 45 | f = default_storage.open(f"entries/{title}.md") 46 | return f.read().decode("utf-8") 47 | except FileNotFoundError: 48 | return None 49 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/encyclopedia/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.http import HttpResponse, HttpResponseBadRequest 3 | 4 | from . import util 5 | import random 6 | 7 | def random_entry(request): 8 | return redirect(f"wiki/{random.choice(util.list_entries())}") 9 | 10 | def edit_entry(request, entry_name: str): 11 | entry_content = util.get_entry(entry_name) 12 | return render(request, "encyclopedia/edit_entry.html", { 13 | "entry_title": entry_name, 14 | "entry_content": entry_content 15 | }) 16 | 17 | 18 | def new_entry(request): 19 | if request.method == 'GET': 20 | return render(request, "encyclopedia/new_entry.html") 21 | 22 | e_title = request.POST.get("entry_title") 23 | e_content = request.POST.get("entry_content") 24 | 25 | if not e_title or not e_content: 26 | return HttpResponseBadRequest("Either the title or the content were found to be missing") 27 | 28 | if not request.POST.get("editing") and (util.get_entry(e_title) is not None): 29 | return HttpResponseBadRequest("Entry already exists, use some other name") 30 | 31 | util.save_entry(e_title, e_content) 32 | return redirect(f"/wiki/{e_title}") 33 | 34 | def index(request): 35 | query = request.GET.get("q") 36 | entries = util.list_entries() 37 | 38 | if query is None: 39 | return render(request, "encyclopedia/index.html", { 40 | "entries": entries 41 | }) 42 | 43 | if util.get_entry(query) is not None: 44 | return redirect(f"wiki/{query.lower()}") 45 | 46 | entries = list(filter(lambda entry: query.lower() in entry.lower(), entries)) 47 | return render(request, "encyclopedia/index.html", { 48 | "entries": entries 49 | }) 50 | 51 | 52 | 53 | def entry(request, entry_name: str): 54 | found_entry = util.get_entry(entry_name) 55 | if found_entry is None: 56 | return render(request, "encyclopedia/error.html", { 57 | "error_desc": f"Was unable to find \"{entry_name}\", it probably doesn't exist", 58 | "error_name": "Entry not found" 59 | }, status=404) 60 | 61 | html_content = util.markdown_to_html(found_entry) 62 | 63 | return render(request, "encyclopedia/entry.html", { 64 | "entry_title": entry_name, 65 | "entry_content": html_content 66 | }) 67 | 68 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/entries/CSS.md: -------------------------------------------------------------------------------- 1 | # CSS 2 | 3 | CSS is a language that can be used to add style to an [HTML](/wiki/HTML) page. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/entries/Django.md: -------------------------------------------------------------------------------- 1 | # Django 2 | 3 | Django is a web framework written using [Python](/wiki/Python) that allows for the design of web applications that generate [HTML](/wiki/HTML) dynamically. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/entries/Git.md: -------------------------------------------------------------------------------- 1 | # Git 2 | 3 | Git is a version control tool that can be used to keep track of versions of a software project. 4 | 5 | ## GitHub 6 | 7 | GitHub is an online service for hosting git repositories. 8 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/entries/HTML.md: -------------------------------------------------------------------------------- 1 | # HTML 2 | 3 | HTML is a markup language that can be used to define the structure of a web page. HTML elements include 4 | 5 | * headings 6 | * paragraphs 7 | * lists 8 | * links 9 | * and more! 10 | 11 | The most recent major version of HTML is HTML5. -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/entries/Python.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | Python is a programming language that can be used both for writing **command-line scripts** or building **web applications**. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wiki.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/wiki/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project01_Wiki/wiki/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/wiki/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for wiki project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wiki.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/wiki/urls.py: -------------------------------------------------------------------------------- 1 | """wiki URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import include, path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('', include("encyclopedia.urls")) 22 | ] 23 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project01_Wiki/wiki/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for wiki project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wiki.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Auction, Bid, Comment, User 4 | 5 | 6 | admin.site.register(Auction) 7 | admin.site.register(User) 8 | admin.site.register(Bid) 9 | admin.site.register(Comment) 10 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AuctionsConfig(AppConfig): 5 | name = 'auctions' 6 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-16 13:08 2 | 3 | import django.contrib.auth.models 4 | import django.contrib.auth.validators 5 | import django.utils.timezone 6 | from django.db import migrations, models 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ('auth', '0012_alter_user_first_name_max_length'), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name='User', 20 | fields=[ 21 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 22 | ('password', models.CharField(max_length=128, verbose_name='password')), 23 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 24 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 25 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 26 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 27 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 28 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 29 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 30 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 31 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 32 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), 33 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), 34 | ], 35 | options={ 36 | 'verbose_name': 'user', 37 | 'verbose_name_plural': 'users', 38 | 'abstract': False, 39 | }, 40 | managers=[ 41 | ('objects', django.contrib.auth.models.UserManager()), 42 | ], 43 | ), 44 | ] 45 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0002_auction_bid_comment.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-16 13:14 2 | 3 | import django.db.models.deletion 4 | from django.conf import settings 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('auctions', '0001_initial'), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Auction', 17 | fields=[ 18 | ('id', models.BigAutoField(primary_key=True, serialize=False)), 19 | ('created_at', models.DateTimeField(auto_now_add=True)), 20 | ('title', models.CharField(max_length=255)), 21 | ('description', models.TextField()), 22 | ('starting_bid', models.DecimalField(decimal_places=2, max_digits=10)), 23 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 24 | ], 25 | options={ 26 | 'abstract': False, 27 | }, 28 | ), 29 | migrations.CreateModel( 30 | name='Bid', 31 | fields=[ 32 | ('id', models.BigAutoField(primary_key=True, serialize=False)), 33 | ('created_at', models.DateTimeField(auto_now_add=True)), 34 | ('bid_amount', models.DecimalField(decimal_places=2, max_digits=10)), 35 | ('auction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auctions.auction')), 36 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 37 | ], 38 | options={ 39 | 'abstract': False, 40 | }, 41 | ), 42 | migrations.CreateModel( 43 | name='Comment', 44 | fields=[ 45 | ('id', models.BigAutoField(primary_key=True, serialize=False)), 46 | ('created_at', models.DateTimeField(auto_now_add=True)), 47 | ('text', models.TextField()), 48 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 49 | ], 50 | options={ 51 | 'abstract': False, 52 | }, 53 | ), 54 | ] 55 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0003_comment_auction.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 05:52 2 | 3 | import django.db.models.deletion 4 | from django.db import migrations, models 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('auctions', '0002_auction_bid_comment'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='comment', 16 | name='auction', 17 | field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='auctions.auction'), 18 | ), 19 | ] 20 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0004_auction_cover_image.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 06:05 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0003_comment_auction'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='auction', 15 | name='cover_image', 16 | field=models.ImageField(default=None, upload_to='images/'), 17 | preserve_default=False, 18 | ), 19 | ] 20 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0005_alter_auction_cover_image.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 06:06 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0004_auction_cover_image'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='auction', 15 | name='cover_image', 16 | field=models.ImageField(default=None, upload_to='images/'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0006_alter_auction_cover_image.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 06:07 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0005_alter_auction_cover_image'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='auction', 15 | name='cover_image', 16 | field=models.ImageField(default=None, null=True, upload_to='images/'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0007_alter_auction_cover_image.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 06:07 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0006_alter_auction_cover_image'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='auction', 15 | name='cover_image', 16 | field=models.ImageField(blank=True, null=True, upload_to='images/'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0008_alter_auction_cover_image.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 06:08 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0007_alter_auction_cover_image'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='auction', 15 | name='cover_image', 16 | field=models.ImageField(blank=True, default='', null=True, upload_to='images/'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0009_remove_auction_cover_image_auction_category_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 06:35 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0008_alter_auction_cover_image'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='auction', 15 | name='cover_image', 16 | ), 17 | migrations.AddField( 18 | model_name='auction', 19 | name='category', 20 | field=models.CharField(choices=[('Fashion', 'FASHION'), ('None', 'NONE'), ('Toys', 'TOYS'), ('Electronics', 'ELECTRONICS'), ('Home', 'HOME')], default='None', max_length=32, null=True), 21 | ), 22 | migrations.AddField( 23 | model_name='auction', 24 | name='image_url', 25 | field=models.URLField(blank=True), 26 | ), 27 | ] 28 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/0010_auction_status.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-18 11:20 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0009_remove_auction_cover_image_auction_category_and_more'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='auction', 15 | name='status', 16 | field=models.CharField(choices=[('Closed', 'CLOSED'), ('Open', 'OPEN'), ('Deleted', 'DELETED')], default='Open', max_length=32, null=True), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/migrations/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/models.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.models import AbstractUser 2 | from django.db import models 3 | from django.contrib.auth import get_user_model 4 | 5 | class User(AbstractUser): 6 | pass 7 | 8 | class Base(models.Model): 9 | id = models.BigAutoField(primary_key=True) 10 | created_at = models.DateTimeField(auto_now_add=True) 11 | 12 | class Meta: 13 | abstract = True 14 | 15 | CATEGORIES = tuple((x, x.upper()) for x in ["Fashion", "None", "Toys", "Electronics", "Home"]) 16 | STATUS = tuple((x, x.upper()) for x in ["Closed", "Open", "Deleted"]) 17 | 18 | class Auction(Base): 19 | user = models.ForeignKey(User, on_delete=models.CASCADE) 20 | image_url = models.URLField(blank=True) 21 | category = models.CharField(max_length=32, choices=CATEGORIES, default="None", null=True) 22 | title = models.CharField(max_length=255) 23 | description = models.TextField() 24 | starting_bid = models.DecimalField(max_digits=10, decimal_places=2) 25 | status = models.CharField(max_length=32, choices=STATUS, default="Open", null=True) 26 | 27 | def __str__(self): 28 | return self.title 29 | 30 | class Bid(Base): 31 | user = models.ForeignKey(User, on_delete=models.CASCADE) 32 | auction = models.ForeignKey(Auction, on_delete=models.CASCADE) 33 | bid_amount = models.DecimalField(max_digits=10, decimal_places=2) 34 | 35 | class Comment(Base): 36 | auction = models.ForeignKey(Auction, on_delete=models.CASCADE, default=None) 37 | user = models.ForeignKey(User, on_delete=models.CASCADE) 38 | text = models.TextField() 39 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/static/auctions/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 10px; 3 | } 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/templates/auctions/create_listing.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |
6 |
7 | {% csrf_token %} 8 |
9 | 10 | 11 |
12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 |
21 | 22 | 23 |
24 | 25 | Discard 26 |
27 |
{% endblock %} 28 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/templates/auctions/index.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 |

Active Listings ({{ active_listing_count }})

5 | 6 |
7 | {% for listing in active_listings %} 8 |
9 | Card image cap 10 |
{{ listing.title }}
11 |
12 |
Starts at ${{ listing.starting_bid }}
13 |
{{ listing.category }}
14 |

{{ listing.description }}

15 | View 16 |
17 |
18 | {% endfor %} 19 |
20 | 21 |
22 | 23 |

Closed Auctions ( {{ closed_listing_count }} )

24 | 25 |
26 | {% for listing in closed_listings %} 27 |
28 | Card image cap 29 |
{{ listing.title }}
30 |
31 |
Started at ${{ listing.starting_bid }}
32 |
{{ listing.category }}
33 |

{{ listing.description }}

34 |

Auction Closed

35 |
36 |
37 | {% endfor %} 38 |
39 | {% endblock %} 40 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/templates/auctions/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | {% block title %}Auctions{% endblock %} 7 | 8 | 9 | 10 | 11 |

Auctions

12 |
13 | {% if user.is_authenticated %} 14 | Signed in as {{ user.username }}. 15 | {% else %} 16 | Not signed in. 17 | {% endif %} 18 |
19 | 46 |
47 | {% block body %} 48 | {% endblock %} 49 | 50 | 51 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/templates/auctions/login.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Login

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | Don't have an account? Register here. 23 | 24 | {% endblock %} -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/templates/auctions/register.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Register

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 | 26 |
27 | 28 | Already have an account? Log In here. 29 | 30 | {% endblock %} -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/auctions/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path("", views.index, name="index"), 7 | path("login", views.login_view, name="login"), 8 | path("logout", views.logout_view, name="logout"), 9 | path("register", views.register, name="register"), 10 | path("watchlist", views.watchlist, name="watchlist"), 11 | path("listing/", views.view_listing, name="listing"), 12 | path("create_listing", views.create_listing, name="create_listing"), 13 | path("add_comment", views.add_comment, name="add_comment"), 14 | path("close_auction", views.close_auction, name="close_auction"), 15 | path("place_bid", views.place_bid, name="place_bid") 16 | ] 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/commerce/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project02_Commerce/commerce/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/commerce/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for commerce project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/commerce/urls.py: -------------------------------------------------------------------------------- 1 | """commerce URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import include, path 18 | 19 | urlpatterns = [ 20 | path("admin/", admin.site.urls), 21 | path("", include("auctions.urls")) 22 | ] -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/commerce/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for commerce project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project02_Commerce/db.sqlite3 -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/images/91PeFpf5NNL._AC_UF10001000_QL80_.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project02_Commerce/images/91PeFpf5NNL._AC_UF10001000_QL80_.jpg -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/images/Untitled.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project02_Commerce/images/Untitled.jpeg -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project02_Commerce/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Email, User 4 | 5 | 6 | admin.site.register(User) 7 | admin.site.register(Email) 8 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class MailConfig(AppConfig): 5 | name = 'mail' 6 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/migrations/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/models.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.models import AbstractUser 2 | from django.db import models 3 | 4 | 5 | class User(AbstractUser): 6 | pass 7 | 8 | 9 | class Email(models.Model): 10 | user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="emails") 11 | sender = models.ForeignKey("User", on_delete=models.PROTECT, related_name="emails_sent") 12 | recipients = models.ManyToManyField("User", related_name="emails_received") 13 | subject = models.CharField(max_length=255) 14 | body = models.TextField(blank=True) 15 | timestamp = models.DateTimeField(auto_now_add=True) 16 | read = models.BooleanField(default=False) 17 | archived = models.BooleanField(default=False) 18 | 19 | def serialize(self): 20 | return { 21 | "id": self.id, 22 | "sender": self.sender.email, 23 | "recipients": [user.email for user in self.recipients.all()], 24 | "subject": self.subject, 25 | "body": self.body, 26 | "timestamp": self.timestamp.strftime("%b %d %Y, %I:%M %p"), 27 | "read": self.read, 28 | "archived": self.archived 29 | } 30 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/static/mail/styles.css: -------------------------------------------------------------------------------- 1 | textarea { 2 | min-height: 400px; 3 | } 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/templates/mail/inbox.html: -------------------------------------------------------------------------------- 1 | {% extends "mail/layout.html" %} 2 | {% load static %} 3 | 4 | {% block body %} 5 |

{{ request.user.email }}

6 | 7 | 8 | 9 | 10 | 11 | Log Out 12 |
13 | 14 |
15 |
16 | 17 |
18 |

New Email

19 |
20 |
21 | From: 22 |
23 |
24 | To: 25 |
26 |
27 | 28 |
29 | 30 | 31 |
32 |
33 | {% endblock %} 34 | 35 | {% block script %} 36 | 37 | {% endblock %} 38 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/templates/mail/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | {% block title %}Mail{% endblock %} 7 | 8 | 9 | {% block script %} 10 | {% endblock %} 11 | 12 | 13 |
14 | {% block body %} 15 | {% endblock %} 16 |
17 | 18 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/templates/mail/login.html: -------------------------------------------------------------------------------- 1 | {% extends "mail/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Login

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | Don't have an account? Register here. 23 | 24 | {% endblock %} -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/templates/mail/register.html: -------------------------------------------------------------------------------- 1 | {% extends "mail/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Register

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 | 23 |
24 | 25 | Already have an account? Log In here. 26 | 27 | {% endblock %} -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/mail/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path("", views.index, name="index"), 7 | path("login", views.login_view, name="login"), 8 | path("logout", views.logout_view, name="logout"), 9 | path("register", views.register, name="register"), 10 | 11 | # API Routes 12 | path("emails", views.compose, name="compose"), 13 | path("emails/", views.email, name="email"), 14 | path("emails/", views.mailbox, name="mailbox"), 15 | ] 16 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project3.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/project3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project03_Mail/project3/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/project3/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for project3 project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project3.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/project3/urls.py: -------------------------------------------------------------------------------- 1 | """project3 URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import include, path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('', include('mail.urls')) 22 | ] 23 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project03_Mail/project3/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for project3 project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project3.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project4.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project04_Network/network/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import User, Post, Like, Follow 4 | 5 | admin.site.register(User) 6 | admin.site.register(Post) 7 | admin.site.register(Like) 8 | admin.site.register(Follow) 9 | 10 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class NetworkConfig(AppConfig): 5 | name = 'network' 6 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-19 05:13 2 | 3 | import django.contrib.auth.models 4 | import django.contrib.auth.validators 5 | import django.utils.timezone 6 | from django.db import migrations, models 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ('auth', '0012_alter_user_first_name_max_length'), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name='User', 20 | fields=[ 21 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 22 | ('password', models.CharField(max_length=128, verbose_name='password')), 23 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 24 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 25 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 26 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 27 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 28 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 29 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 30 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 31 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 32 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), 33 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), 34 | ], 35 | options={ 36 | 'verbose_name': 'user', 37 | 'verbose_name_plural': 'users', 38 | 'abstract': False, 39 | }, 40 | managers=[ 41 | ('objects', django.contrib.auth.models.UserManager()), 42 | ], 43 | ), 44 | ] 45 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/migrations/0002_follow_post_like.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.1 on 2024-01-19 06:30 2 | 3 | import django.db.models.deletion 4 | from django.conf import settings 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('network', '0001_initial'), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Follow', 17 | fields=[ 18 | ('id', models.AutoField(primary_key=True, serialize=False)), 19 | ('created_at', models.DateTimeField(auto_now_add=True)), 20 | ('follow_from', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='follow_from', to=settings.AUTH_USER_MODEL)), 21 | ('follow_to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='follow_to', to=settings.AUTH_USER_MODEL)), 22 | ], 23 | ), 24 | migrations.CreateModel( 25 | name='Post', 26 | fields=[ 27 | ('id', models.AutoField(primary_key=True, serialize=False)), 28 | ('text', models.TextField()), 29 | ('created_at', models.DateTimeField(auto_now_add=True)), 30 | ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 31 | ], 32 | ), 33 | migrations.CreateModel( 34 | name='Like', 35 | fields=[ 36 | ('id', models.AutoField(primary_key=True, serialize=False)), 37 | ('created_at', models.DateTimeField(auto_now_add=True)), 38 | ('liked_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 39 | ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='network.post')), 40 | ], 41 | ), 42 | ] 43 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project04_Network/network/migrations/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import AbstractUser 3 | 4 | class User(AbstractUser): 5 | pass 6 | 7 | class Post(models.Model): 8 | id = models.AutoField(primary_key=True) 9 | author = models.ForeignKey(User, on_delete=models.CASCADE) 10 | text = models.TextField() 11 | created_at = models.DateTimeField(auto_now_add=True) 12 | 13 | class Like(models.Model): 14 | id = models.AutoField(primary_key=True) 15 | post = models.ForeignKey(Post, on_delete=models.CASCADE) 16 | liked_by = models.ForeignKey(User, on_delete=models.CASCADE) 17 | created_at = models.DateTimeField(auto_now_add=True) 18 | 19 | class Follow(models.Model): 20 | id = models.AutoField(primary_key=True) 21 | follow_from = models.ForeignKey(User, on_delete=models.CASCADE, related_name='follow_from') 22 | follow_to = models.ForeignKey(User, on_delete=models.CASCADE, related_name='follow_to') 23 | created_at = models.DateTimeField(auto_now_add=True) 24 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/static/network/styles.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project04_Network/network/static/network/styles.css -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/templates/network/following.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 | 5 | {% if users|length > 0 %} 6 | {% for user in users %} 7 | 8 |
9 |
10 |
11 |

{{ user.follow_from.username }}

12 |
13 | 14 | {% if user.is_authenticated %} 15 | 16 | {% endif %} 17 |
18 |
19 | 20 | 21 | {% endfor %} 22 | {% else %} 23 | 24 | No {{ page_type }} Found! 25 | 26 | {% endif %} 27 | 28 | 29 | {% endblock %} 30 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/templates/network/index.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 |

All Posts

5 | 6 | {% if user.is_authenticated %} 7 |
8 |
9 |

New Post

10 | 11 | {% for message in messages %} 12 | 15 | 16 | 23 | 24 | {% endfor %} 25 | 26 |
27 | {% csrf_token %} 28 |
29 | 30 |
31 | 32 |
33 |
34 |
35 | {% endif %} 36 | 37 | {% include "network/post_list.html" %} 38 | {% endblock %} 39 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/templates/network/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | {% block title %}Social Network{% endblock %} 7 | 8 | 9 | 10 | 11 | 12 | 13 | 44 | 45 |
46 | {% block body %} 47 | {% endblock %} 48 |
49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/templates/network/login.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Login

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | Don't have an account? Register here. 23 | 24 | {% endblock %} -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/templates/network/profile.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |
6 |
7 |
8 | 9 |
10 |

{{ current_user.username }}

11 | Joined: {{ current_user.date_joined }} 12 |
13 | 14 | 18 |
19 | 20 | {% if user.is_authenticated and user.id != current_user.id %} 21 | 22 |
23 | {% csrf_token %} 24 | 25 | {% if following %} 26 | 27 | {% else %} 28 | 29 | {% endif %} 30 |
31 | 32 | {% endif %} 33 | 34 |
35 |
36 | 37 | {% include "network/post_list.html" %} 38 | 39 | {% endblock %} 40 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/templates/network/register.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Register

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 | 26 |
27 | 28 | Already have an account? Log In here. 29 | 30 | {% endblock %} -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/network/urls.py: -------------------------------------------------------------------------------- 1 | 2 | from django.urls import path 3 | 4 | from . import views 5 | 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("login", views.login_view, name="login"), 9 | path("logout", views.logout_view, name="logout"), 10 | path("register", views.register, name="register"), 11 | 12 | path("create_post", views.create_post, name="create_post"), 13 | path("profile/", views.profile_page, name="profile_page"), 14 | path("profile//following", views.following_page, {'follow_type': 'following'}, name="following"), 15 | path("profile//followers", views.following_page, {'follow_type': 'followers'}, name="followers"), 16 | 17 | path("follow", views.follow, name="follow"), 18 | path("like/", views.like, name="like"), 19 | 20 | path("edit_post", views.edit_post, name="edit_post") 21 | 22 | ] 23 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/project4/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aadv1k/cs50/5b769c0bd21e3a9498c1b7605ac5a066e870f6bc/Web_Programming_With_Python_And_JavaScript/Project04_Network/project4/__init__.py -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/project4/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for project4 project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project4.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/project4/urls.py: -------------------------------------------------------------------------------- 1 | """project4 URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import include, path 18 | 19 | urlpatterns = [ 20 | path("admin/", admin.site.urls), 21 | path("", include("network.urls")), 22 | ] 23 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/Project04_Network/project4/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for project4 project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project4.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Web_Programming_With_Python_And_JavaScript/README.md: -------------------------------------------------------------------------------- 1 | # CS50's Web Programming with Python and JavaScript 2 | 3 | Started: 15th Jan 2024 4 | 5 | | Submissions | Lecture(s) | 6 | |----------------------------------------------|------------------------------------| 7 | | [Project 0 - Search](./Project00_Search) | Week 0: HTML, CSS | 8 | | [Project 1 - Wiki](./Project01_Wiki) | Week 1: Git | 9 | | | Week 2: Python | 10 | | | Week 3: Django | 11 | | [Project 3 - Commerce](./Project03_Commerce) | Week 4: SQL, Models and Migrations | 12 | | | Week 5: User Interfaces | 13 | | [Project 4 - Network](./Project04_Network) | Week 7: Testing, CI/CD | 14 | 15 | --------------------------------------------------------------------------------