├── .gitignore ├── .gitmodules ├── .image └── projects.png ├── LICENSE ├── README.md ├── beginner ├── Bin2Dec-App │ ├── .images │ │ ├── bin2dec.gif │ │ ├── bin2dec_bash.gif │ │ └── bin2dec_html.gif │ ├── Bash │ │ └── binary2decimal.sh │ ├── C │ │ └── bin2dec.c │ ├── README.md │ ├── js │ │ ├── index.html │ │ ├── main.js │ │ └── style.css │ ├── python │ │ ├── bin2dec.py │ │ └── bin2dec_pyqt.py │ └── requirements.txt ├── Hello │ ├── README.md │ └── js │ │ ├── index.html │ │ ├── main.js │ │ ├── style.css │ │ └── welcome_page.html ├── README.md ├── calculator │ ├── .images │ │ ├── js.png │ │ ├── v1.png │ │ └── v2.gif │ ├── Bash │ │ └── calc.sh │ ├── README.md │ ├── js │ │ ├── index.html │ │ ├── main.js │ │ └── style.css │ └── python │ │ ├── main.py │ │ └── version_2.py ├── color_cycle │ ├── .images │ │ ├── bash.gif │ │ ├── js.gif │ │ └── python.gif │ ├── Bash │ │ └── color.sh │ ├── README.md │ ├── js │ │ ├── index.html │ │ ├── main.js │ │ └── style.css │ └── python │ │ ├── list1.py │ │ └── main.py ├── countdown_timer │ ├── C │ │ └── countdowntimer.c │ ├── README.md │ ├── js │ │ ├── index.html │ │ ├── main.js │ │ └── style.css │ └── python │ │ ├── README.md │ │ ├── countdown-timer.py │ │ └── requirements.txt ├── csv2json │ ├── .images │ │ └── demo.png │ ├── README.md │ └── python │ │ ├── main.py │ │ ├── main.ui │ │ └── ui_main.py ├── curves │ ├── README.md │ └── python │ │ └── main_hypo.py ├── dollars_to_cents │ ├── .images │ │ └── demo.png │ ├── README.md │ ├── js │ │ ├── index.html │ │ └── main.js │ └── python │ │ ├── main.py │ │ ├── main.ui │ │ └── ui_main.py ├── dynamiccssvariable │ ├── .images │ │ └── test.gif │ ├── README.md │ ├── loginpage.ui │ ├── main.py │ └── ui_loginpage.py ├── firstdb │ ├── README.md │ └── desktopgui │ │ ├── Makefile │ │ ├── database.cpp │ │ └── database.h ├── flipimage │ ├── .images │ │ └── test.gif │ ├── README.md │ ├── main.py │ ├── main.ui │ └── ui_main.py ├── githubstatus │ ├── README.md │ └── webbased │ │ ├── index.html │ │ ├── main.js │ │ └── style.css ├── input_validation │ ├── README.md │ └── js │ │ ├── index.html │ │ ├── main.js │ │ └── style.css ├── keyvalue │ ├── .images │ │ └── test.gif │ ├── README.md │ ├── main.py │ ├── main.ui │ └── ui_main.py ├── lorem │ ├── .images │ │ └── preview.png │ ├── README.md │ └── webbased │ │ ├── index.html │ │ ├── main.js │ │ ├── style.css │ │ └── test.js ├── notes │ ├── .images │ │ └── test.png │ ├── README.md │ ├── desktopgui │ │ ├── Makefile │ │ ├── initialsetup.cpp │ │ ├── initialsetup.h │ │ ├── main.cpp │ │ ├── notepad.cpp │ │ └── notepad.h │ └── webbased │ │ ├── index.html │ │ ├── main.js │ │ └── style.css ├── pendulum │ ├── README.md │ └── main.py ├── recipe │ ├── README.md │ └── webbased │ │ ├── chad_tea.html │ │ ├── generaterecipe.py │ │ ├── images │ │ └── tea.jpg │ │ ├── index.html │ │ ├── main.js │ │ ├── recipesjson │ │ └── chad_tea.json │ │ ├── recipetemplate.html │ │ └── style.css ├── sorting_algorithm_visualizer │ ├── C │ │ ├── bubblesort.c │ │ ├── insertionsort.c │ │ ├── mergesort.c │ │ ├── quicksort.c │ │ └── selectionsort.c │ ├── README.md │ └── python │ │ ├── bubblesort.py │ │ ├── insertionsort.py │ │ ├── mergesort.py │ │ ├── quicksort.py │ │ ├── selectionsort.py │ │ └── visualization.py ├── starfield_visualization │ ├── README.md │ ├── cloud.py │ └── main.py ├── trueorfalse │ ├── .images │ │ └── test.gif │ ├── README.md │ ├── main.py │ ├── main.ui │ └── ui_main.py ├── weatherapp │ ├── .images │ │ └── desktoptest.png │ ├── README.md │ ├── desktopgui │ │ ├── main.ui │ │ ├── ui_main.py │ │ └── weatherapp.py │ └── webbased │ │ ├── index.html │ │ ├── main.js │ │ └── style.css └── windchill │ ├── README.md │ ├── desktopgui │ ├── Makefile │ ├── main.ui │ ├── ui_main.cpp │ └── ui_main.h │ └── webbased │ ├── index.html │ ├── main.js │ └── style.css ├── books ├── README.md ├── cpp_exercises │ ├── Makefile │ ├── README.md │ ├── basics.cpp │ └── classes.cpp └── playingwithimages │ └── image.jpg ├── codingproblem ├── README.md ├── dcp │ ├── README.md │ ├── codes │ │ ├── problem11.c │ │ ├── problem12.py │ │ ├── problem13.py │ │ ├── problem14.py │ │ ├── problem3.c │ │ ├── problem4.c │ │ ├── problem5.py │ │ ├── problem6.c │ │ ├── problem7.py │ │ ├── treeds.h │ │ ├── trie.c │ │ ├── trie.h │ │ └── words.txt │ ├── problem1.md │ ├── problem10.md │ ├── problem11.md │ ├── problem12.md │ ├── problem13.md │ ├── problem14.md │ ├── problem15.md │ ├── problem16.md │ ├── problem17.md │ ├── problem2.md │ ├── problem3.md │ ├── problem4.md │ ├── problem5.md │ ├── problem6.md │ ├── problem7.md │ ├── problem8.md │ └── problem9.md └── projecteuler │ ├── README.md │ ├── problem1.c │ └── problem2.c ├── designpatterns ├── README.md ├── main.cpp └── visitor │ ├── CMakeLists.txt │ ├── README.md │ ├── card │ ├── CMakeLists.txt │ ├── bronzecard.h │ ├── creditcard.h │ ├── gasoffer.h │ ├── goldcard.h │ ├── offervisitor.h │ └── silvercard.h │ └── main.cpp ├── games └── tictactoe │ ├── C │ └── tictactoecmd.c │ ├── README.md │ └── python │ └── tictactoe_cmd.py ├── garden ├── README.md └── elf_analysis │ ├── Makefile │ ├── elf │ └── hello.c ├── karanprojects ├── Ciphers │ ├── decrypt.py │ └── encrypt.py ├── README.md ├── airline_hotel_reservation_system │ └── reserve.py ├── alarm_clock │ ├── alarm.py │ └── requirements.txt ├── bank_manager │ ├── cpp │ │ ├── account.h │ │ ├── main.cpp │ │ └── savingaccount.h │ └── python │ │ └── bankmanager.py ├── coin_flip_simulation │ ├── C │ │ └── cmd.c │ ├── README.md │ └── python │ │ └── cmd.py ├── company_manager │ ├── README.md │ ├── cpp │ │ ├── company.cpp │ │ └── employee.h │ └── python │ │ └── company_manager.py ├── distance_between_two_cities │ └── distance.py ├── expense_tracker │ ├── .images │ │ └── test.gif │ ├── README.md │ ├── items.csv │ ├── requirements.txt │ ├── run.py │ ├── sample │ │ ├── __main__.py │ │ ├── mainwindow.py │ │ ├── overviewpage.py │ │ └── table.py │ └── test.csv ├── fastexpo │ └── main.cpp ├── fibonacci_sequence │ └── C │ │ └── main.c ├── flowershops │ ├── README.md │ ├── cpp │ │ └── flowers.cpp │ └── python │ │ └── flowers.py ├── image_gallery │ └── gallery.py ├── mortgage_calculator │ └── mortage.py ├── patient_doctor_scheduler │ └── schedule.py ├── recipe_creator_manager │ └── receipe.py ├── regex_query_tool │ ├── README.md │ └── src │ │ ├── __main__.py │ │ ├── dialogbox.py │ │ └── mainwindow.py ├── shapes │ └── shape.py ├── sieve_of_Eratosthenes │ ├── C │ │ └── cmd.c │ ├── README.md │ └── python │ │ └── cmd.py ├── text │ ├── C │ │ ├── fizzbuzz.c │ │ ├── palindrome.c │ │ ├── reverse.c │ │ ├── vowels.c │ │ └── words.c │ └── python │ │ ├── fizzbuzz.py │ │ ├── palindrome.py │ │ ├── reverse.py │ │ ├── vowels.py │ │ └── words.py ├── text_editor │ ├── README.md │ └── gui.py ├── tiles │ ├── C │ │ └── tiles.c │ ├── README.md │ └── python │ │ └── main.py └── unit_converter │ ├── README.md │ └── main.py ├── projectC ├── README.md ├── datastructures │ ├── README.md │ ├── arrays │ │ ├── C++ │ │ │ ├── list.cpp │ │ │ └── list.h │ │ ├── C │ │ │ ├── list.c │ │ │ ├── list.h │ │ │ └── test.c │ │ └── README.md │ ├── linkedlist │ │ ├── C++ │ │ │ ├── linkedlist.cpp │ │ │ └── linkedlist.h │ │ ├── C │ │ │ ├── linkedlist.c │ │ │ ├── linkedlist.h │ │ │ └── test.c │ │ └── README.md │ └── queue │ │ ├── C_ARRAYS │ │ ├── queue.c │ │ └── queue.h │ │ ├── C_LL │ │ ├── queue.c │ │ └── queue.h │ │ ├── Cplus_LL │ │ ├── queue.cpp │ │ └── queue.h │ │ └── README.md ├── shellcommands │ ├── README.md │ ├── cat.c │ ├── echo.c │ └── ls.c └── tictactoe │ ├── Makefile │ ├── README.md │ └── src │ ├── game.h │ ├── logic.c │ ├── logic.h │ ├── main.c │ ├── rendering.c │ └── rendering.h └── researchpapers ├── Makefile ├── code ├── BTree │ ├── btree.c │ └── btree.h ├── MakingDataStructuresPersistent │ ├── fatnode.c │ ├── fatnode.h │ └── nodecopying.h └── RTree │ ├── rtree.c │ └── rtree.h ├── other ├── .images │ ├── btree │ │ └── tree.png │ └── rtree │ │ ├── img1.png │ │ ├── img2.png │ │ ├── scene1.png │ │ ├── scene2.png │ │ └── scene3.png ├── btree.md ├── rtree.md └── smarteratomicsmartpointers.md ├── papers ├── .images │ └── nearestneighbours │ │ ├── definition1.png │ │ ├── definition1_mindist.png │ │ ├── edeqn.png │ │ ├── edsamplecalc.png │ │ ├── examplepoints.png │ │ ├── manhattan.png │ │ ├── regressiongraph.png │ │ ├── regressiongraph2.png │ │ └── samplegraph.png ├── makingdatastructurespersitent.md └── nearestneighbor.md └── tests └── README.md /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/.gitmodules -------------------------------------------------------------------------------- /.image/projects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/.image/projects.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 kanna 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > This repository will be used a practice ground to *solidify* different concepts that I learn. 2 | --- 3 | 4 | #### Map-Of-Content 5 | 6 | - [Beginner](beginner): Contains all the projects from [florinpop17's](https://github.com/florinpop17/app-ideas) repo. (`archived`) 7 | - [Karan's project list solutions](karanprojects): Contains folder for the [karan's project](https://github.com/karan/Projects/). (`archived`) 8 | - [Project Based on C/C++](projectC): Contains projects from [project based tutorial in C](https://github.com/rby90/Project-Based-Tutorials-in-C) repo. 9 | - [Design Patterns](designpatterns): Contains several design patterns I implemented 10 | - [CodingProblem/Exercises](codingproblem): Contains coding problems from sites like leetcode 11 | - [Games](games): Contains small games 12 | - [Books](books): Contains solutions to coding problems from books 13 | - [Research Papers](researchpapers): Contains my *stupid* summaries on several implementation 14 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/.images/bin2dec.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/Bin2Dec-App/.images/bin2dec.gif -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/.images/bin2dec_bash.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/Bin2Dec-App/.images/bin2dec_bash.gif -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/.images/bin2dec_html.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/Bin2Dec-App/.images/bin2dec_html.gif -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/Bash/binary2decimal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "This is program converts binary numbers to decimal\n" 3 | 4 | #reading the input 5 | read input; 6 | 7 | 8 | length=${#input} 9 | #checking for digits greater than 9 10 | if [[ $length -ge 9 ]] 11 | then 12 | echo "binary number cannot be greater than 8" 1>&2 13 | exit 14 | fi 15 | 16 | #checking for other digits 17 | if [[ $input =~ [2-9] ]] 18 | then 19 | echo "binary number cannot contain numbers other than 0 and 1" 1>&2 20 | exit 21 | fi 22 | 23 | decimal=`echo "ibase=2;obase=A;$input" | bc` 24 | echo "decimal number is $decimal" 25 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/C/bin2dec.c: -------------------------------------------------------------------------------- 1 | // converts binary number to a decimal number 2 | 3 | #include 4 | 5 | int BinaryToDecimal(int binary) 6 | { 7 | int n = binary; 8 | int decimal = 0; 9 | int base = 1; 10 | int last_digit = 0; 11 | 12 | while (n != 0) 13 | { 14 | last_digit = n % 10 ; 15 | decimal += last_digit * base; 16 | base *= 2; 17 | n /= 10; 18 | } 19 | 20 | return decimal; 21 | } 22 | 23 | int main() 24 | { 25 | int x = BinaryToDecimal(10000); 26 | printf("Binary Number is %d\n",x); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Binary to Decimal 6 | 7 | 8 | 9 |
10 |

CONVERTER

11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/js/main.js: -------------------------------------------------------------------------------- 1 | // convert binary to decimal and "alert" the answer 2 | function BinaryToDecimal(binary) 3 | { 4 | return parseInt(binary,2); 5 | }; 6 | 7 | 8 | function foo() 9 | { 10 | let binary_value = document.getElementById("bin").value; 11 | document.getElementById("dec").value = BinaryToDecimal(binary_value); 12 | alert("Binary value of "+binary_value+" = "+BinaryToDecimal(binary_value)); 13 | }; 14 | 15 | function validateForm() 16 | { 17 | let x = document.getElementById("bin").value; 18 | let regex=/^[0-1]+$/; 19 | if (x == "") 20 | { 21 | alert("input is empty") 22 | return false; 23 | } 24 | else if (x.match(regex)) 25 | // number check 26 | { 27 | foo() 28 | return true; 29 | } 30 | alert("wrong input"+"="+x); 31 | return false; 32 | }; 33 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/js/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | margin:0; 3 | padding:0; 4 | font-family:sans-serif; 5 | background: #34495e; 6 | } 7 | .box{ 8 | width:300px; 9 | padding:40px; 10 | position: absolute; 11 | top:50%; 12 | left:50%; 13 | transform: translate(-50%,-50%); 14 | background: #191919; 15 | text-align:center; 16 | } 17 | .box h1{ 18 | color: white; 19 | font-weight:250; 20 | } 21 | .box input[id = "bin"],.box input[id = "dec"]{ 22 | border:0; 23 | background:none; 24 | display:block; 25 | margin: 20px auto; 26 | text-align:center; 27 | border: 2px solid #3498db; 28 | width: 200px; 29 | color:white; 30 | border-radius: 24px; 31 | transition: 0.25s; 32 | } 33 | .box input[id= "bin"]:focus{ 34 | width:280px; 35 | border-color:#2ecc71; 36 | } 37 | .box input[type="submit"]{ 38 | border:0; 39 | background:none; 40 | display:block; 41 | margin: 20px auto; 42 | text-align:center; 43 | border: 2px solid #3498db; 44 | color:white; 45 | border-radius: 24px; 46 | transition: 1.0s; 47 | cursor: pointer; 48 | } 49 | 50 | .box input[type="submit"]:hover{ 51 | border-color:#2ecc71; 52 | background:#2ecc71; 53 | } 54 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/python/bin2dec.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | class Application(tk.Frame): 4 | 5 | def __init__(self, master=None): 6 | super().__init__(master) 7 | self.master = master 8 | master.title("binary to decimal") 9 | master.maxsize(900,600) 10 | master.config(bg = "pink") 11 | 12 | frame = tk.Frame(master,width=600,height=200,bg="white") 13 | frame.grid(row = 0,column = 0,padx=10,pady=5) 14 | 15 | label = ttk.Label(frame, text='Enter Binary Number:').grid(row = 0,column =0,padx = 5,pady=5 ) 16 | button = ttk.Button(frame, text='Convert',command=self.generate).grid(row = 0,column = 4,padx = 5,pady = 5) 17 | 18 | self.username = tk.StringVar() 19 | self.results = tk.StringVar() 20 | answer = ttk.Label(frame,textvariable=self.results).grid(row=1,column=1,padx = 5 ,pady = 5) 21 | name = ttk.Entry(frame, textvariable=self.username).grid(row = 0, column = 1,padx = 5,pady=5) 22 | 23 | 24 | def generate(self,*args): 25 | value = str(self.username.get()) 26 | try: 27 | value = str(self.username.get()) 28 | self.results.set("Answer = {}".format(int(value,2))) 29 | except ValueError: 30 | self.results.set("Invalid Input {}".format(value)) 31 | 32 | root = tk.Tk() 33 | app = Application(master=root) 34 | app.mainloop() 35 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/python/bin2dec_pyqt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtWidgets as qtw 3 | from PyQt5 import QtCore as qtc 4 | from PyQt5 import QtGui as qtg 5 | 6 | 7 | 8 | class binary(qtg.QValidator): 9 | 10 | def validate(self,string,index): 11 | print(string,index) 12 | 13 | if all([i=="1" or i == "0" for i in str(string)]): 14 | state = qtg.QValidator.Acceptable 15 | elif string == "": 16 | state = qtg.QValidator.Intermediate 17 | else: 18 | state = qtg.QValidator.Invalid 19 | return (state,string,index) 20 | 21 | class MainWindow(qtw.QWidget): 22 | 23 | def __init__(self,*args,**kwargs): 24 | super().__init__() 25 | self.setLayout(qtw.QGridLayout()) 26 | 27 | 28 | label1 = qtw.QLabel("Enter a Binary Number") 29 | self.convert = qtw.QPushButton("Convert") 30 | self.answer = qtw.QLabel() 31 | self.line = qtw.QLineEdit() 32 | self.line.setValidator(binary()) 33 | self.answer.setAlignment(qtc.Qt.AlignHCenter) 34 | self.layout().addWidget(label1,0,1) 35 | self.layout().addWidget(self.line,0,2) 36 | self.layout().addWidget(self.answer,1,0,1,4) 37 | self.layout().addWidget(self.convert,0,4) 38 | 39 | self.convert.clicked.connect(self.converter) 40 | 41 | self.show() 42 | 43 | def converter(self): 44 | decimal = self.line.text() 45 | binary = int(str(decimal),2) 46 | self.answer.setText(str(binary)) 47 | 48 | 49 | if __name__ == "__main__": 50 | app = qtw.QApplication(sys.argv) 51 | win = MainWindow() 52 | sys.exit(app.exec_()) 53 | -------------------------------------------------------------------------------- /beginner/Bin2Dec-App/requirements.txt: -------------------------------------------------------------------------------- 1 | Package Version 2 | ----------------- --------- 3 | PyQt5 5.15.0 4 | PyQt5-sip 12.8.0 5 | -------------------------------------------------------------------------------- /beginner/Hello/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HELLo 6 | 7 | 8 | 9 |
10 |

sellyoursoul.com

11 |
12 | 13 | 14 |
15 |
16 | 17 | 18 |
19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /beginner/Hello/js/main.js: -------------------------------------------------------------------------------- 1 | function checkCurrentBody(){ 2 | return document.body.id; 3 | } 4 | 5 | function app(){ 6 | if (checkCurrentBody() == "") { 7 | // Event Listeners 8 | const submitbutton = document.getElementById('form'); 9 | submitbutton.addEventListener('submit',(e) =>{ 10 | 11 | e.preventDefault(); 12 | username = document.getElementById("username"); 13 | password = document.getElementById("pass"); 14 | 15 | // storing the values in session 16 | sessionStorage.setItem('user',username.value); 17 | 18 | const ip = get_the_api(); 19 | window.location.href='welcome_page.html'; 20 | }) 21 | }else if (checkCurrentBody()=="welcomepage"){ 22 | addWelcomeText(); 23 | // adding a listener to the logout button 24 | const logout = document.getElementById("logout"); 25 | logout.addEventListener('click',(e) => { 26 | e.preventDefault(); 27 | console.log("this button works"); 28 | window.location.replace('index.html'); 29 | }) 30 | } 31 | } 32 | 33 | function get_the_api(){ 34 | 35 | // link 36 | var endpoint = 'http://ip-api.com/json/?fields=status,query'; 37 | var xhr = new XMLHttpRequest(); 38 | // open a request 39 | xhr.open('GET', endpoint, true); 40 | xhr.onload = function(){ 41 | if (this.status == 200) { 42 | var response = JSON.parse(this.responseText); 43 | 44 | //check if the response is successful from the status 45 | if (response.status !== 'success'){ 46 | console.log('alert error') 47 | return ; 48 | } 49 | return response.query; 50 | } 51 | } 52 | xhr.send(); 53 | } 54 | 55 | function addWelcomeText(){ 56 | // function for the welcomepage 57 | if (checkCurrentBody() === 'welcomepage'){ 58 | fetch('https://fourtonfish.com/hellosalut/?mode=auto') 59 | .then( function(response){ 60 | return response.json() 61 | } ) 62 | .then( function( jsonData ){ 63 | welcome_text = jsonData['hello']+"! "+sessionStorage.getItem('user'); 64 | document.getElementById("introduction").textContent = welcome_text; 65 | } ); 66 | } 67 | } 68 | 69 | app(); 70 | -------------------------------------------------------------------------------- /beginner/Hello/js/style.css: -------------------------------------------------------------------------------- 1 | body, #welcome_page{ 2 | margin:0; 3 | padding:0; 4 | font-family:sans-serif; 5 | background:#FCFCFC; 6 | } 7 | 8 | .box, #mainframe{ 9 | width:300px; 10 | top:50%; 11 | left:50%; 12 | padding:40px; 13 | position: absolute; 14 | transform: translate(-50%,-50%); 15 | background: #C6C5B9; 16 | text-align:center; 17 | } 18 | 19 | .box h1 { 20 | color:#040403; 21 | } 22 | -------------------------------------------------------------------------------- /beginner/Hello/js/welcome_page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | welcome! 6 | 7 | 8 | 9 |
10 |

sellyoursoul.com

11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /beginner/calculator/.images/js.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/calculator/.images/js.png -------------------------------------------------------------------------------- /beginner/calculator/.images/v1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/calculator/.images/v1.png -------------------------------------------------------------------------------- /beginner/calculator/.images/v2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/calculator/.images/v2.gif -------------------------------------------------------------------------------- /beginner/calculator/Bash/calc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare -a op=(+ - '*' /) 4 | 5 | while true 6 | do 7 | read -p "enter first number: " n1 8 | read -p "enter second number: " n2 9 | echo "Expression List ${op[@]} " 10 | read -p "enter expression: " exp 11 | 12 | ans=$(echo "$n1 $exp $n2" |bc -l) 13 | printf "%s %s %s = %s\n\n" "$n1" "$exp" "$n2" "$ans" 14 | 15 | done 16 | -------------------------------------------------------------------------------- /beginner/calculator/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Calculator 5 | 6 | 7 | 8 | 9 |
10 |
11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 |
34 |
35 |
36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /beginner/calculator/js/main.js: -------------------------------------------------------------------------------- 1 | const f1 = document.querySelector('#display'); 2 | const button = document.querySelectorAll('.bt'); 3 | const equal = document.querySelector('#equal_btn'); 4 | const clear = document.querySelector('.clearbtn'); 5 | 6 | // adding a event listener 7 | f1.addEventListener('input',validate); 8 | button.forEach((b)=>b.addEventListener('click',enterNumber)); 9 | equal.addEventListener('click',calculate); 10 | clear.addEventListener('click',() => f1.value = 0); 11 | 12 | let length_check = () => f1.value.length < 9; 13 | 14 | function validate(e){ 15 | let val = e.target.value; 16 | console.log(val); 17 | } 18 | 19 | function enterNumber(e){ 20 | let val = e.target.value; 21 | let re = /ERR/; 22 | if (length_check() == true && re.test(f1.value)== false){ 23 | f1.value += val; 24 | }else if(re.test(f1.value)== true){ 25 | f1.value = val; 26 | } 27 | } 28 | 29 | function calculate(e){ 30 | console.log("works") 31 | try{ 32 | let val = eval(f1.value); 33 | f1.value = val; 34 | } catch (error){ 35 | f1.value = "ERR"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /beginner/calculator/js/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background: #E3DBDB; 3 | } 4 | 5 | .container{ 6 | width: 250px; 7 | height: 400px; 8 | margin: 100px auto; 9 | border-radius: 10px; 10 | background: #4E3D42; 11 | box-shadow: -5px -5px 10px 0px #6D6466,5px 5px 10px 0px #9F9F92; 12 | } 13 | 14 | .holder{ 15 | background:#4E3D42; 16 | width: 200px; 17 | margin: 20px auto; 18 | } 19 | 20 | #display{ 21 | border: none; 22 | outline: none; 23 | text-align: right; 24 | margin: 30px 0px 20px 0px; 25 | background: #4E3D42; 26 | width: 200px; 27 | height: auto; 28 | padding-top: 10px; 29 | padding-bottom: 10px; 30 | font-weight: 800; 31 | box-shadow: inset 0px 0px 10px 0px black; 32 | } 33 | .bt{ 34 | border: none; 35 | margin:0px 0px 35px 0px; 36 | width: 45px; 37 | height: 45px; 38 | cursor: pointer; 39 | outline: none; 40 | font-size: 15px; 41 | font-weight: bold; 42 | box-shadow: inset 0px 0px 10px 0px black; 43 | background: #E3DBDB; 44 | display: inline-block; 45 | } 46 | 47 | .bt1{ 48 | border: none; 49 | margin:0px 0px 0px 0px; 50 | width: 45px; 51 | height: 45px; 52 | cursor: pointer; 53 | outline: none; 54 | font-size: 15px; 55 | font-weight: bold; 56 | box-shadow: inset 0px 0px 10px 0px black; 57 | background: #E3DBDB; 58 | display: inline-block; 59 | } 60 | 61 | .clearbtn{ 62 | border: none; 63 | margin:0px 0px 0px 0px; 64 | width: 45px; 65 | height: 45px; 66 | cursor: pointer; 67 | outline: none; 68 | font-size: 15px; 69 | font-weight: bold; 70 | box-shadow: inset 0px 0px 10px 0px black; 71 | background: #E3DBDB; 72 | display: inline-block; 73 | } 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /beginner/color_cycle/.images/bash.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/color_cycle/.images/bash.gif -------------------------------------------------------------------------------- /beginner/color_cycle/.images/js.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/color_cycle/.images/js.gif -------------------------------------------------------------------------------- /beginner/color_cycle/.images/python.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/color_cycle/.images/python.gif -------------------------------------------------------------------------------- /beginner/color_cycle/Bash/color.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # color codes 4 | expand_bg="\e[K" 5 | blue_bg="\e[0;104m${expand_bg}" 6 | red_bg="\e[0;101m${expand_bg}" 7 | green_bg="\e[0;102m${expand_bg}" 8 | yellow_bg="\e[0;103m${expand_bg}" 9 | white_bg="\e[0;107m${expand_bg}" 10 | 11 | #High Intensty backgrounds 12 | 13 | blackhi="\e[0;100m${expand_bg}" 14 | redhi="\e[0;101m${expand_bg}" 15 | greenhi="\e[0;102m${expand_bg}" 16 | yellowhi="\e[0;103m${expand_bg}" 17 | bluehi="\e[0;104m${expand_bg}" 18 | purplehi="\e[0;105m${expand_bg}" 19 | cyanhi="\e[0;106m${expand_bg}" 20 | whitehi="\e[0;107m${expand_bg}" 21 | 22 | reset="\e[0m" 23 | 24 | 25 | col=`tput cols` 26 | lin=`tput lines` 27 | 28 | color(){ 29 | var=$1 30 | for (( c=1; c<=$lin; c++ )) 31 | do 32 | echo -e "${var}${reset}" 33 | done 34 | 35 | sleep 5 36 | } 37 | 38 | color $blue_bg 39 | color $red_bg 40 | color $green_bg 41 | color $yellow_bg 42 | color $white_bg 43 | color $bluehi 44 | color $redhi 45 | color $greenhi 46 | color $yellowhi 47 | color $whitehi 48 | color $blackhi 49 | color $purplehi 50 | color $cyanhi 51 | -------------------------------------------------------------------------------- /beginner/color_cycle/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | color cycle 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /beginner/color_cycle/js/main.js: -------------------------------------------------------------------------------- 1 | const colorselector=document.querySelector('#firstcolor'); 2 | const startButton=document.querySelector('#startbutton'); 3 | const filler=document.querySelector('body'); 4 | const outsideband=document.querySelector('.settings'); 5 | 6 | 7 | // event listener 8 | 9 | colorselector.addEventListener('change',watchColorChange); 10 | startButton.addEventListener('click',mainLoop); 11 | 12 | 13 | function watchColorChange(e){ 14 | filler.style.backgroundColor = e.target.value; 15 | startbutton.style.background=e.target.value; 16 | outsideband.style.backgroundColor=e.target.value; 17 | } 18 | 19 | function mainLoop(e){ 20 | console.log("fruit loops"); 21 | filler.classList.toggle("animation"); 22 | startButton.classList.toggle("animation"); 23 | outsideband.classList.toggle("animation"); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /beginner/color_cycle/js/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background:red; 3 | } 4 | 5 | 6 | 7 | @keyframes movingBox { 8 | 0% { 9 | background:red; 10 | } 11 | 12 | 25% { 13 | background:pink; 14 | } 15 | 16 | 50% { 17 | background:blue; 18 | } 19 | 20 | 75% { 21 | background:cyan; 22 | } 23 | 85%{ 24 | background:green; 25 | } 26 | 100%{ 27 | background:yellow; 28 | } 29 | } 30 | 31 | .animation{ 32 | animation: movingBox 12s infinite; 33 | } 34 | 35 | .settings{ 36 | width:200px; 37 | height:30px; 38 | margin:20px auto; 39 | background: red; 40 | } 41 | #startbutton{ 42 | margin:4px 4px 5px 4px; 43 | border:none; 44 | width:64x; 45 | line-height:20px; 46 | text-align:center; 47 | vertical-align:bottom; 48 | padding: 0 20px; 49 | background-color:red; 50 | } 51 | #firstcolor{ 52 | margin:4px 4px 5px 4px; 53 | border:none; 54 | height:20px; 55 | width:64x; 56 | line-height:20px; 57 | text-align:center; 58 | vertical-align:bottom; 59 | padding: 0 20px; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /beginner/countdown_timer/C/countdowntimer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // global variables 6 | 7 | int hour = 10; 8 | int minutes = 1; 9 | int second = 10; 10 | int flag = 0; 11 | 12 | 13 | void delay(int ms){ 14 | clock_t TimeDelay= ms + clock(); 15 | while(TimeDelay > clock()); 16 | } 17 | 18 | void print(){ 19 | system("clear"); // clear screen 20 | printf("**************\n"); 21 | printf("\t%d:%d:%d\t\n",hour,minutes,second); 22 | printf("**************\n"); 23 | } 24 | 25 | 26 | int main(){ 27 | 28 | 29 | while (1){ 30 | if ((hour==0)&&(minutes==0)&&(second==0)){ 31 | break; 32 | } 33 | second--; 34 | if (second < 0){ 35 | minutes -= 1; 36 | second = 59; 37 | } 38 | if (minutes < 0){ 39 | hour -= 1; 40 | minutes = 59; 41 | } 42 | print(); 43 | delay(500000); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /beginner/countdown_timer/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | countdown 6 | 7 | 8 | 9 |
10 |

timer

11 |
12 |
13 | 14 | 15 |
16 |
17 | 18 |
19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /beginner/countdown_timer/js/main.js: -------------------------------------------------------------------------------- 1 | // selectors 2 | frame = document.getElementById("frame"); 3 | startdate = document.getElementById("start"); 4 | startbtn = document.getElementById("startbtn"); 5 | 6 | 7 | 8 | startbtn.addEventListener("click",(e) => { 9 | e.preventDefault(); 10 | // change the value from start to pause and vice versa 11 | let content = startbtn.textContent; 12 | if (content === "start"){ 13 | starttimer(); 14 | } 15 | }) 16 | 17 | 18 | function getDate(){ 19 | // obtaining and setting up the date. 20 | let today = new Date(); 21 | let today_ISO = today.toISOString().slice(0,10); 22 | let enddate = new Date(startdate.valueAsNumber); 23 | let enddate_ISO = enddate.toISOString().slice(0,10); 24 | 25 | if (enddate - today < 0){ 26 | frame.textContent = "Long Gone!"; 27 | }else{ 28 | // convert milliseconds to days 29 | let diff = enddate - today; 30 | let seconds,minutes,hours,days; 31 | 32 | seconds = parseInt(Math.floor(diff / 1000)); 33 | minutes = parseInt(Math.floor(seconds / 60)); 34 | hours = parseInt(Math.floor(minutes / 60)); 35 | days = parseInt(Math.floor(hours / 24)); 36 | 37 | s = parseInt(seconds % 60); 38 | m = parseInt(minutes % 60); 39 | h = parseInt(hours % 24); 40 | 41 | return [h,m,s]; 42 | } 43 | } 44 | 45 | function starttimer(){ 46 | let datearray = getDate(); 47 | function timer(){ 48 | datearray[2]--; 49 | // if seconds == 0 50 | if (datearray[2] < 0){ 51 | datearray[1] -= 1; 52 | datearray[2] = 59; 53 | } 54 | if (datearray[1] < 0){ 55 | datearray[2] -= 1; 56 | datearray[1] = 59; 57 | } 58 | 59 | if ((datearray[2] == 0)&&(datearray[1] == 0)&&datearray[2] == 0){ 60 | frame.textContent = "END"; 61 | return; 62 | } 63 | frame.textContent = datearray[0]+":"+datearray[1]+":"+datearray[2]; 64 | } 65 | 66 | // using set interval function 67 | setInterval(timer,1000); 68 | } 69 | 70 | 71 | -------------------------------------------------------------------------------- /beginner/countdown_timer/js/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | margin:0; 3 | padding:0; 4 | font-family:sans-serif; 5 | background:#FCFCFC; 6 | } 7 | 8 | div{ 9 | width:300px; 10 | top:50%; 11 | left:50%; 12 | padding:40px; 13 | position: absolute; 14 | transform: translate(-50%,-50%); 15 | background: #C6C5B9; 16 | text-align:center; 17 | } 18 | 19 | #day{ 20 | width:300px; 21 | top:25%; 22 | left:50%; 23 | padding:40px; 24 | position: absolute; 25 | transform: translate(-50%,-50%); 26 | background: #C6C5B9; 27 | text-align:center; 28 | } 29 | -------------------------------------------------------------------------------- /beginner/countdown_timer/python/README.md: -------------------------------------------------------------------------------- 1 | # Python implementation of the Countdown Timer 2 | 3 | - [x]The `countdown-timer.py` file is pretty massive, at 300 lines, but about two-thirds of that is basically creating the GUI using PyQt5's Qt Designer. Thought I should point that out. 4 | 5 | - [x]Run `pip install -r requirements.txt` in your virtual environment to get the required packages. -------------------------------------------------------------------------------- /beginner/countdown_timer/python/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/countdown_timer/python/requirements.txt -------------------------------------------------------------------------------- /beginner/csv2json/.images/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/csv2json/.images/demo.png -------------------------------------------------------------------------------- /beginner/curves/README.md: -------------------------------------------------------------------------------- 1 | # Progress 2 | 3 | ### Hypocycloid 4 | 5 | # Project 6 | ## CURVES 7 | 8 | **Tier:** 1-Beginner 9 | 10 | ## User Stories 11 | 12 | - [x] Roulettes 13 | - [x] Astroid 14 | - [x] Hypotrochoid w/ different "k" values 15 | 16 | 17 | - [ ] Fractals 18 | - [ ] Dragon curve 19 | - [ ] Mandelbrot set 20 | - [ ] Fibonacci word fractal 21 | - [ ] Menger sponge 22 | - [ ] Sierpinski triangle 23 | 24 | - [ ] Spirals 25 | - [ ] Euler Spiral 26 | - [ ] Golden Spiral 27 | - [ ] Helix 28 | - [x] Archimedean spiral 29 | 30 | ## Bonus features 31 | 32 | - [ ] Hypocycloids "rolling" inside one another 33 | 34 | ## Useful links, Resources and Example Projects 35 | 36 | [Curves](https://en.wikipedia.org/wiki/Category:Curves) 37 | 38 | [Rolling Hypocycloids](https://www.malinc.se/m/RollingHypocycloids.php) 39 | 40 | [Math behind Hypocycloids](https://mathworld.wolfram.com/Hypocycloid.html) 41 | -------------------------------------------------------------------------------- /beginner/dollars_to_cents/.images/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/dollars_to_cents/.images/demo.png -------------------------------------------------------------------------------- /beginner/dollars_to_cents/README.md: -------------------------------------------------------------------------------- 1 | # Dollars To Cents 2 | 3 | ### Demo 4 | 5 |

6 | 7 |

8 | 9 | **Tier:** 1-Beginner 10 | 11 | Converting dollars to cents would enable you to practice your fundamental knowledge of programming. Loops, if conditions and a simple algorithm will be used. 12 | Your task is to let the user input a dollar value (float), assuming that it can also accept extra cents (ex. $2.75), and convert it into an integer (in this case, if $2.75 = 275). After this, convert into coins with the sub-type of dollars: penny, nickel, dime and quarter. Use an algorithm that would divide the dollar value to the four coin types, and output few coins as possible. 13 | 14 | The challenge: Try this without using any frameworks. 15 | 16 | (EX. If you have $0.58, I would have 4 coins: 2 quarters, 0 dimes, 1 nickel and 3 pennies) 17 | 18 | ## User Stories 19 | 20 | - [x] User can enter a dollar value 21 | - [x] User can see the total cents from the converted dollar value 22 | 23 | ## Bonus features 24 | 25 | - [x] User can see how many were pennies, nickels, quarters and dimes from the total cents 26 | 27 | ## Useful links and resources 28 | 29 | - [Math functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) 30 | - [Loops and iterations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration) 31 | - [Money values in JavaScript](https://timleland.com/money-in-javascript/) 32 | 33 | ## Example projects 34 | 35 | - [Dollars to cents converter](https://github.com/LimonJuice322/Dollars-to-cents-converter) 36 | 37 | -------------------------------------------------------------------------------- /beginner/dollars_to_cents/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dollar to Cents 6 | 7 | 8 |
9 |

Dollar to Cents Converter

10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /beginner/dollars_to_cents/js/main.js: -------------------------------------------------------------------------------- 1 | // convert dollar to decimal and "alert" the answer 2 | function DollarToCoins(number) 3 | { 4 | number = number * 100; 5 | let penny, nickel, dime, quarter, balance; 6 | quarter = Math.floor(number / 25); 7 | balance = number % 25; 8 | dime = Math.floor(balance / 10); 9 | balance = balance % 10; 10 | nickel = Math.floor(balance / 5); 11 | balance = balance % 5; 12 | penny = Math.floor(balance / 1); 13 | let s = "Quarters: " + quarter + "\nDimes: " + dime + "\nNickels: " + nickel + "\nPennies: " + penny; 14 | alert(s); 15 | return s; 16 | }; 17 | 18 | function validateForm() 19 | { 20 | let x = document.getElementById("dollar").value; 21 | if (x == "") 22 | { 23 | alert("input is empty") 24 | return false; 25 | } 26 | let dollarAmt = document.getElementById("dollar").value; 27 | DollarToCoins(dollarAmt); 28 | }; -------------------------------------------------------------------------------- /beginner/dollars_to_cents/python/main.py: -------------------------------------------------------------------------------- 1 | from PyQt5 import QtWidgets as qtw 2 | from PyQt5 import QtGui as qtg 3 | from PyQt5 import QtCore as qtc 4 | from ui_main import Ui_Form 5 | import sys 6 | 7 | class Widget(qtw.QWidget): 8 | """ 9 | """ 10 | def __init__(self, *args, **kwargs): 11 | super().__init__() 12 | self.ui = Ui_Form() 13 | self.ui.setupUi(self) 14 | 15 | self.ui.convert.clicked.connect(self.convertvalue) 16 | # setting up a validator 17 | self.ui.amount.setValidator(qtg.QDoubleValidator()) 18 | 19 | def convertvalue(self): 20 | """ 21 | converts dollars to cents 22 | """ 23 | amount = self.ui.amount.text() 24 | if amount: 25 | values = {'quarter':25,'dime':10,'nickel': 5,'penny': 1} 26 | # obtaining the value from the 27 | # widget 28 | # converting the value into cents 29 | amountincents = float(amount) * 100 30 | 31 | quantity = dict() 32 | 33 | # iterating through the values 34 | for name,value in values.items(): 35 | quantity[name], amountincents = divmod(amountincents, value) 36 | if not amountincents: 37 | break 38 | 39 | message = "" 40 | for name,value in quantity.items(): 41 | message += f"{name} {value}\n" 42 | 43 | return qtw.QMessageBox.information(self,"converted amount",message) 44 | 45 | 46 | if __name__ == "__main__": 47 | app = qtw.QApplication(sys.argv) 48 | form = Widget() 49 | form.show() 50 | app.exec_() 51 | -------------------------------------------------------------------------------- /beginner/dollars_to_cents/python/main.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 240 10 | 191 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | -1 20 | -1 21 | 241 22 | 191 23 | 24 | 25 | 26 | 27 | 28 | 29 | Dollars To Cents 30 | 31 | 32 | Qt::AlignCenter 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Enter the amount 46 | 47 | 48 | 49 | 50 | 51 | 52 | Convert 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /beginner/dynamiccssvariable/.images/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/dynamiccssvariable/.images/test.gif -------------------------------------------------------------------------------- /beginner/firstdb/desktopgui/Makefile: -------------------------------------------------------------------------------- 1 | P=database 2 | CFLAGS=`pkg-config --cflags Qt5Widgets` 3 | LDLIBS=`pkg-config --libs Qt5Widgets` 4 | CC=g++ 5 | 6 | make main: 7 | $(CC) $(P).cpp -o $(P) $(LDLIBS) $(CFLAGS) -l sqlite3 -fPIC 8 | -------------------------------------------------------------------------------- /beginner/firstdb/desktopgui/database.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "sqlite3.h" 9 | #include "database.h" 10 | 11 | 12 | static int callback(void * data, int argc, char **argv, char ** azColName){ 13 | int i; 14 | fprintf(stderr, "%s: ",(const char *)data); 15 | for (i = 0; i < argc; i++){ 16 | printf("%s = %s \n",azColName[i], argv[i] ? argv[i]: "NULL"); 17 | } 18 | printf("\n"); 19 | return 0; 20 | } 21 | 22 | /* 23 | * return sqlite3 pointer 24 | * creates a database & table 25 | */ 26 | sqlite3 * createDatabase(){ 27 | sqlite3 * database; 28 | int status = 0; 29 | status = sqlite3_open(databasename, &database); 30 | 31 | if (status) { 32 | std::cerr << "ERR: CANNOT OPEN DATABASE " << sqlite3_errmsg(database) << std::endl; 33 | exit(EXIT_FAILURE); 34 | } else { 35 | std::cout << "SUCCESS: DATABASE OPENED SUCCESFULLY" << std::endl; 36 | sqlite3_close(database); 37 | return database; 38 | } 39 | } 40 | 41 | std::string generateSqlString(int id, char *firstname, char *secondname, int age, int salary){ 42 | char bufferstring[100]; 43 | std::snprintf(bufferstring, 99, 44 | "INSERT INTO PERSON VALUES(%d, '%s', '%s', %d, %d);", id, firstname, secondname, age, salary); 45 | return bufferstring; 46 | } 47 | 48 | int main(int argc, char **argv) 49 | { 50 | 51 | /*initializing DB*/ 52 | sqlite3* database = createDatabase(); 53 | /*creating a table*/ 54 | int exit = 0; 55 | exit = sqlite3_open(databasename, &database); 56 | char * errorMessage; 57 | 58 | /*creating the employee table*/ 59 | exit = sqlite3_exec(database, tablesql.c_str(), NULL, 0, &errorMessage); 60 | if (exit != SQLITE_OK){ 61 | std::cerr << "ERR: CANNOT CREATE TABLE" << std::endl; 62 | sqlite3_free(errorMessage); 63 | } else { 64 | std::cout << "SUCCESS: TABLE CREATED SUCCESFULLY" << std::endl; 65 | sqlite3_close(database); 66 | } 67 | return 0; 68 | 69 | // QApplication app(argc, argv); 70 | // QLabel hello("Hello world!"); 71 | 72 | // hello.show(); 73 | // return app.exec(); 74 | } 75 | -------------------------------------------------------------------------------- /beginner/firstdb/desktopgui/database.h: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_H 2 | #define DATABASE_H 3 | 4 | char databasename[] = "employee.db"; 5 | 6 | std::string tablesql = "CREATE TABLE PERSON(" 7 | "ID INT PRIMARY KEY NOT NULL, " 8 | "NAME TEXT NOT NULL, " 9 | "SURNAME TEXT NOT NULL, " 10 | "AGE INT NOT NULL, " 11 | "ADDRESS CHAR(50), " 12 | "SALARY REAL );"; 13 | 14 | #endif // DATABASE_H -------------------------------------------------------------------------------- /beginner/flipimage/.images/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/flipimage/.images/test.gif -------------------------------------------------------------------------------- /beginner/flipimage/README.md: -------------------------------------------------------------------------------- 1 | # FlipImage 2 | 3 |

4 | 5 |

6 | 7 | **Tier:** 1-Beginner 8 | 9 | It's important for Web Developers to understand the basics of manipulating 10 | images since rich web applications rely on images to add value to the user 11 | interface and user experience (UI/UX). 12 | 13 | FlipImage explores one aspect of image manipulation - image rotation. This 14 | app displays a square pane containing a single image presented in a 2x2 15 | matrix. Using a set of up, down, left, and right arrows adjacent to each 16 | of the images the user may flip them vertically or horizontally. 17 | 18 | 19 | ## User Stories 20 | 21 | - [x] User can see a pane containing a single image repeated in a 2x2 matrix 22 | - [x] User can flip any one of the images vertically or horizontally using a set of up, down, left, and right arrows next to the image 23 | 24 | ## Bonus features 25 | 26 | - [ ] User can change the default image by entering the URL of a different image in an input field 27 | - [ ] User can display the new image by clicking a 'Display' button next to the input field 28 | - [ ] User can see an error message if the new images URL is not found 29 | 30 | ## Useful links and resources 31 | 32 | - [How to Flip an Image](https://www.w3schools.com/howto/howto_css_flip_image.asp) 33 | - [Create a CSS Flipping Animatin](https://davidwalsh.name/css-flip) 34 | - [Animation Help](https://stackoverflow.com/questions/55258872/how-to-animate-an-image-icon-widget) 35 | - [cat.jpg]() 36 | 37 | ## Example projects 38 | 39 | [Image Effects by @bennettfeely](https://codepen.io/seyedi/pen/gvqYQv) 40 | -------------------------------------------------------------------------------- /beginner/flipimage/main.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 582 10 | 764 11 | 12 | 13 | 14 | 15 | 582 16 | 764 17 | 18 | 19 | 20 | 21 | 582 22 | 764 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | background-color: rgb(199, 87, 37); 30 | 31 | 32 | 33 | 34 | -10 35 | 10 36 | 601 37 | 741 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 539 46 | 739 47 | 48 | 49 | 50 | 51 | 599 52 | 739 53 | 54 | 55 | 56 | 57 | 0 58 | 59 | 60 | 0 61 | 62 | 63 | 0 64 | 65 | 66 | 0 67 | 68 | 69 | 0 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /beginner/flipimage/ui_main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'mainoAXcpg.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 5.15.2 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | 12 | from PyQt5.QtWidgets import * 13 | from PyQt5.QtGui import * 14 | from PyQt5.QtCore import * 15 | 16 | class Ui_Form(object): 17 | def setupUi(self, Form): 18 | if not Form.objectName(): 19 | Form.setObjectName(u"Form") 20 | Form.resize(582, 764) 21 | Form.setMinimumSize(QSize(582, 764)) 22 | Form.setMaximumSize(QSize(582, 764)) 23 | Form.setStyleSheet(u"background-color: rgb(199, 87, 37);") 24 | self.gridLayoutWidget = QWidget(Form) 25 | self.gridLayoutWidget.setObjectName(u"gridLayoutWidget") 26 | self.gridLayoutWidget.setGeometry(QRect(-10, 10, 601, 741)) 27 | self.verticalLayout_2 = QVBoxLayout(self.gridLayoutWidget) 28 | self.verticalLayout_2.setObjectName(u"verticalLayout_2") 29 | self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) 30 | self.imagewidget = QWidget(self.gridLayoutWidget) 31 | self.imagewidget.setObjectName(u"imagewidget") 32 | self.imagewidget.setMinimumSize(QSize(539, 739)) 33 | self.imagewidget.setMaximumSize(QSize(599, 739)) 34 | self.verticalLayout = QVBoxLayout(self.imagewidget) 35 | self.verticalLayout.setSpacing(0) 36 | self.verticalLayout.setObjectName(u"verticalLayout") 37 | self.verticalLayout.setContentsMargins(0, 0, 0, 0) 38 | 39 | self.verticalLayout_2.addWidget(self.imagewidget) 40 | 41 | 42 | self.retranslateUi(Form) 43 | 44 | QMetaObject.connectSlotsByName(Form) 45 | # setupUi 46 | 47 | def retranslateUi(self, Form): 48 | Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) 49 | # retranslateUi 50 | 51 | -------------------------------------------------------------------------------- /beginner/githubstatus/webbased/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Github Status 4 | 5 | 6 | 7 | 8 |
9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /beginner/githubstatus/webbased/main.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | //var statusbar = document.getElementById("statuswindow"); 3 | 4 | function createStatusWidget(statusname, currentstatus){ 5 | let div = document.createElement('div'); 6 | div.className = "status-content"; 7 | div.id = "status-content"; 8 | 9 | div.innerHTML = `

${statusname}-${currentstatus}

` 10 | return div; 11 | } 12 | 13 | function addtoDiv(element){ 14 | statusbar.appendChild(element); 15 | } 16 | 17 | function getStatus(){ 18 | request('https://www.githubstatus.com/', { json: true }, (err, res, body) => { 19 | let results = body.components; 20 | console.log(results); 21 | for (let i = 0; i < results.length; i++){ 22 | //element = createStatusWidget(results[i]['name'],results[i]['status']) 23 | console.log(results[i]['name'] + " " + results[i]['status']); 24 | //addtoDiv(element); 25 | } 26 | }); 27 | } 28 | 29 | getStatus(); -------------------------------------------------------------------------------- /beginner/githubstatus/webbased/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/githubstatus/webbased/style.css -------------------------------------------------------------------------------- /beginner/input_validation/README.md: -------------------------------------------------------------------------------- 1 | # Javascript Validation With Regex 2 | 3 | 4 | 5 | **Tier:** 1-Beginner 6 | 7 | In this challenge, you'd create a javascript validation script to validate the inputs entered by a user using RegEx. 8 | 9 | You could always refer to the [Regular Expression Library](http://regexlib.com/(X(1)A(GijS7qxVy-6Gyc4cweUyFoK4ZvRn2WnlOe8SSKuq9sT7ps-2nbiTmZZMTCn_rFk4-mNoGnYL-DPU8pJhmNNOtkP-syqWE4WO_1aVt4bPa5nTsQPQe6VRAALnm6QW3YIWbYkVS78JFbZN39vmMI1UYiWlHXKwNMB99WjsZOn0qc_8dcN0unp2KMOBw0P__3OH0))/CheatSheet.aspx?AspxAutoDetectCookieSupport=1) for support 10 | 11 | For this project, there'd be three required inputs for validation: 12 | - The first would require the user to enter five (5) capital letters, six (6) symbols and two hyphens (-) in any order. This could be used as a password. 13 | - The second which could be used as username would require the user to enter letters without spaces 14 | - The third which could be used as email address would require the user to enter only email addresses on gmail (...@gmail.com). 15 | 16 | ## User Stories 17 | 18 | - [x] User should be notified of any invalid inputs by error messages displayed on the form. 19 | - [x] The submit button on the form would never be executed until all entries are validated. 20 | 21 | ## Useful links and resources 22 | 23 | - [Javascript form validation using regular expressions](http://form.guide/snippets/javascript-form-validation-using-regular-expression.html) 24 | - [JavaScript Form Validation Using Regular Expressions](https://study.com/academy/lesson/javascript-form-validation-using-regular-expressions-definition-example.html) 25 | 26 | ## Example project 27 | 28 | - [Native HTML5 validation with CSS & Regex](https://codepen.io/helgesverre/pen/vWRevp) 29 | -------------------------------------------------------------------------------- /beginner/input_validation/js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Input Validation 6 | 7 | 8 | 9 |
10 |
11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /beginner/input_validation/js/main.js: -------------------------------------------------------------------------------- 1 | // selectors 2 | 3 | username = document.getElementById("username"); 4 | email = document.getElementById("email"); 5 | button = document.getElementById("btn"); 6 | password = document.getElementById("pass"); 7 | 8 | button.addEventListener("click",(e) => { 9 | e.preventDefault(); 10 | console.log(e); 11 | // function to validate the string 12 | if (validateEmail(email.value) && validatePassword(str) && validateName(str)){ 13 | alert("sucess"); 14 | }else{ 15 | alert("error") 16 | } 17 | 18 | }) 19 | 20 | function validateEmail(str){ 21 | let re = /.@gmail.com$/; 22 | var con = re.test(str); 23 | return con; 24 | } 25 | 26 | function validatePassword(str){ 27 | let re = /^(?=.*[A-Z]{5})(?=.*[^/w]{6})(?=.*[-]{2})$/; 28 | var con = re.test(str); 29 | return con; 30 | } 31 | 32 | function validateName(str){ 33 | let re = /[^\s]/; 34 | var con = re.test(str); 35 | return con; 36 | } 37 | -------------------------------------------------------------------------------- /beginner/input_validation/js/style.css: -------------------------------------------------------------------------------- 1 | #main{ 2 | width:300px; 3 | top:50%; 4 | left:50%; 5 | padding:40px; 6 | position: absolute; 7 | transform: translate(-50%,-50%); 8 | background: #C6C5B9; 9 | text-align:center; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /beginner/keyvalue/.images/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/keyvalue/.images/test.gif -------------------------------------------------------------------------------- /beginner/keyvalue/README.md: -------------------------------------------------------------------------------- 1 | # Key Value 2 | 3 |

4 | 5 |

6 | 7 | **Tier:** 1-Beginner 8 | 9 | Have you ever thought about what it means that the computer you are using is 10 | a digital device? Among other things it means that everything its capable of 11 | is achieved by translating a digital signal into a sequence of binary digits - 0's and 1's. These binary digits form codes used to represent data. 12 | 13 | The keyboard you used to retrieve this project description is a great example 14 | of this. Pressing a key generates a digital signal that is translated by the 15 | computer into a code representing the key that was pressed. 16 | 17 | The goal of the Key Value app is to display the encoded value on screen each 18 | time a key is pressed on the keyboard. 19 | 20 | ## User Stories 21 | 22 | - [x] User can see a display panel containing a text area where the key value 23 | and key code will be displayed along with display areas for four other 24 | indicators related to the keys on the keyboard - alt key, control key, 25 | meta key, and shift key. 26 | - [x] User can see the key code and key value displayed in the display panel 27 | corresponding to the key when it is pressed. 28 | - [x] User can see the appropriate indicator change from 'False' to 'True' 29 | when the alt, control, meta, or shift key is pressed. 30 | 31 | ## Bonus features 32 | 33 | - [ ] User can hear a unique tone played when a key is pressed. 34 | - [ ] User can see the background color of the key code and value change when 35 | a key is pressed. 36 | 37 | ## Useful links and resources 38 | 39 | - [Digital Electronics](https://en.wikipedia.org/wiki/Digital_electronics) 40 | - [Keyboard Event](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent) 41 | - [PyQt5 Key Mapping](https://stackoverflow.com/questions/50851350/get-printable-name-of-any-qkeyevent-key-value) 42 | 43 | ## Example projects 44 | 45 | [Javascript Keyevent Test Script](https://unixpapa.com/js/testkey.html) 46 | -------------------------------------------------------------------------------- /beginner/keyvalue/main.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 760 10 | 440 11 | 12 | 13 | 14 | 15 | 760 16 | 440 17 | 18 | 19 | 20 | 21 | 760 22 | 440 23 | 24 | 25 | 26 | keyvalue 27 | 28 | 29 | background-color: rgb(13, 13, 13); 30 | 31 | 32 | 33 | 34 | 0 35 | 0 36 | 761 37 | 441 38 | 39 | 40 | 41 | 42 | 5 43 | 44 | 45 | 0 46 | 47 | 48 | 49 | 50 | color:rgb(248, 248, 248); 51 | 52 | 53 | 54 | 55 | 56 | 57 | QPushButton::focus{ 58 | background-color: rgb(0, 255, 127); 59 | } 60 | 61 | color: rgb(0, 255, 0); 62 | 63 | 64 | reset 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /beginner/keyvalue/ui_main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'mainYtosBE.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 5.15.2 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | 12 | from PyQt5.QtWidgets import * 13 | from PyQt5.QtGui import * 14 | from PyQt5.QtCore import * 15 | 16 | class Ui_Form(object): 17 | def setupUi(self, Form): 18 | if not Form.objectName(): 19 | Form.setObjectName(u"Form") 20 | Form.resize(760, 440) 21 | Form.setMinimumSize(QSize(760, 440)) 22 | Form.setMaximumSize(QSize(760, 440)) 23 | Form.setStyleSheet(u"background-color: rgb(13, 13, 13);") 24 | self.gridLayoutWidget = QWidget(Form) 25 | self.gridLayoutWidget.setObjectName(u"gridLayoutWidget") 26 | self.gridLayoutWidget.setGeometry(QRect(0, 0, 761, 441)) 27 | self.gridLayout = QGridLayout(self.gridLayoutWidget) 28 | self.gridLayout.setSpacing(0) 29 | self.gridLayout.setObjectName(u"gridLayout") 30 | self.gridLayout.setContentsMargins(0, 0, 0, 5) 31 | self.plainTextEdit = QPlainTextEdit(self.gridLayoutWidget) 32 | self.plainTextEdit.setObjectName(u"plainTextEdit") 33 | self.plainTextEdit.setStyleSheet(u"color:rgb(248, 248, 248);") 34 | 35 | self.gridLayout.addWidget(self.plainTextEdit, 0, 0, 1, 1) 36 | 37 | self.reset = QPushButton(self.gridLayoutWidget) 38 | self.reset.setObjectName(u"reset") 39 | self.reset.setStyleSheet(u"QPushButton::focus{\n" 40 | " background-color: rgb(0, 255, 127);\n" 41 | "}\n" 42 | "\n" 43 | "color: rgb(0, 255, 0);") 44 | 45 | self.gridLayout.addWidget(self.reset, 1, 0, 1, 1) 46 | 47 | 48 | self.retranslateUi(Form) 49 | 50 | QMetaObject.connectSlotsByName(Form) 51 | # setupUi 52 | 53 | def retranslateUi(self, Form): 54 | Form.setWindowTitle(QCoreApplication.translate("Form", u"keyvalue", None)) 55 | self.reset.setText(QCoreApplication.translate("Form", u"reset", None)) 56 | # retranslateUi 57 | 58 | -------------------------------------------------------------------------------- /beginner/lorem/.images/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/lorem/.images/preview.png -------------------------------------------------------------------------------- /beginner/lorem/webbased/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lorem Ipsum Generator 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 |
12 |
13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /beginner/lorem/webbased/main.js: -------------------------------------------------------------------------------- 1 | /*import loremipsum npm module into the script*/ 2 | const lorem = require("lorem-ipsum"); 3 | 4 | /* add event listener to the generate button*/ 5 | let generator = document.getElementById("generator"); 6 | let loremdiv = document.getElementById("loremdiv"); 7 | generator.addEventListener("click", generatelorem); 8 | 9 | function generatelorem(){ 10 | /*grabbing the number of paragraphs 11 | *the user wants to generate 12 | */ 13 | let paragraphs = 14 | document.getElementById("numberofparagraphs").value; 15 | 16 | 17 | const loremClass = new lorem.LoremIpsum({ 18 | sentencesPerParagraph: { 19 | max: 8, 20 | min: 4 21 | }, 22 | wordsPerSentence: { 23 | max: 16, 24 | min: 4 25 | } 26 | }); 27 | 28 | /*generating the lorem ipsum content and 29 | *assigning it to a variable 30 | */ 31 | let content = loremClass.generateParagraphs(paragraphs); 32 | /*creating a text area widget and adding content generated 33 | *from loremipsum module into the widget. 34 | */ 35 | let loremcontent = document.createElement("textarea"); 36 | loremcontent.textContent = content; 37 | /*clearing the previous content from the div*/ 38 | loremdiv.textContent = ""; 39 | loremdiv.appendChild(loremcontent); 40 | 41 | /*adding a copy button*/ 42 | let copybutton = document.createElement("button"); 43 | copybutton.innerText = "copy to clipboard"; 44 | copybutton.onclick = () => { 45 | navigator.clipboard.writeText(content); 46 | }; 47 | 48 | loremdiv.appendChild(copybutton); 49 | } -------------------------------------------------------------------------------- /beginner/lorem/webbased/style.css: -------------------------------------------------------------------------------- 1 | .decisionbox { 2 | top:5%; 3 | text-align: center; 4 | }; -------------------------------------------------------------------------------- /beginner/notes/.images/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/notes/.images/test.png -------------------------------------------------------------------------------- /beginner/notes/README.md: -------------------------------------------------------------------------------- 1 | # Notes App 2 | 3 | ### [Desktop GUI](desktopgui) 4 | 5 | I know this is bad style of coding but this is my first project where i coded using `C++` using the framework `PyQt5` and half of the code is incomplete, I need to get better at class syntax in `C++`. Currently the user can: 6 | 7 | - user can create a note 8 | - user can edit a note 9 | - user can kinda save a note 10 | 11 | To Run: 12 | - Navigate into the `desktopgui` folder and use `make` to compile the project 13 | ``` 14 | make && ./main 15 | ``` 16 | 17 | #### Demo 18 | 19 | ![](.images/test.png) 20 | 21 | 22 | ### [Web Based](webbased) 23 | 24 | - [livepreview](https://codepen.io/kana800/pen/ZEyxbdx) 25 | 26 | --- 27 | 28 | **Tier:** 1-Beginner 29 | 30 | Create and store your notes for later purpose! 31 | 32 | ## User Stories 33 | 34 | - [x] User can create a note 35 | - [x] User can edit a note 36 | - [x] User can delete a note 37 | - [x] When closing the browser window the notes will be stored and when the User returns, the data will be retrieved 38 | 39 | ## Bonus features 40 | 41 | - [ ] User can create and edit a note in Markdown format. On save it will convert Markdown to HTML 42 | - [ ] User can see the date when he created the note 43 | 44 | ## Useful links and resources 45 | 46 | - [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) 47 | - [Markdown Guide](https://www.markdownguide.org/basic-syntax/) 48 | - [Marked - A markdown parser](https://github.com/markedjs/marked) 49 | 50 | ## Example projects 51 | 52 | - [Markdown Notes built with Angular on Codepen](https://codepen.io/nickmoreton/full/gbyygq) 53 | - [Markdown Notes built with React](https://github.com/email2vimalraj/notes-app) 54 | - [Markdown Notes built with Angular 7 and bootstrap 4](https://github.com/omdnaik/angular-ui) 55 | -------------------------------------------------------------------------------- /beginner/notes/desktopgui/Makefile: -------------------------------------------------------------------------------- 1 | P=main 2 | CFLAGS=`pkg-config --cflags Qt5Widgets` 3 | LDLIBS=`pkg-config --libs Qt5Widgets` 4 | CC=g++ 5 | 6 | make main: 7 | $(CC) $(P).cpp -o $(P) $(LDLIBS) $(CFLAGS) -fPIC 8 | -------------------------------------------------------------------------------- /beginner/notes/desktopgui/initialsetup.h: -------------------------------------------------------------------------------- 1 | #ifndef INITIALSETUP_H 2 | #define INITIALSETUP_H 3 | 4 | bool directoryExists(const char * directory); 5 | bool createDirectory(const char * directory); 6 | void createUntitledFile(const char * directory); 7 | void initializeProgram(const char * directory); 8 | 9 | #endif // INITIALSETUP_H -------------------------------------------------------------------------------- /beginner/notes/desktopgui/notepad.h: -------------------------------------------------------------------------------- 1 | #ifndef NOTEPAD_H 2 | #define NOTEPAD_H 3 | 4 | class NotePad{ 5 | public: // methods 6 | static QWidget *notewindow; 7 | static QString s_filename; 8 | public: // methods 9 | NotePad(QString filename); 10 | static void savenote(); 11 | static void closenote(); 12 | static void renamenote(); 13 | }; 14 | 15 | 16 | #endif // NOTEPAD_H -------------------------------------------------------------------------------- /beginner/notes/webbased/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Notes 4 | 5 | 6 | 7 |
8 |
9 | NotePad: 10 |
11 | 12 |
13 | 14 |
15 |
16 | 17 |
18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /beginner/notes/webbased/style.css: -------------------------------------------------------------------------------- 1 | .container { 2 | height:200px; 3 | position: relative; 4 | border: 3px solid greenyellow; 5 | } 6 | 7 | .vertical-centered { 8 | margin:0; 9 | position: absolute; 10 | top:5%; 11 | left:50%; 12 | -ms-transform: translate(-50%,0%); 13 | transform: translate(-50%,0%); 14 | } 15 | 16 | .notebox{ 17 | position: relative; 18 | text-align: center; 19 | } 20 | 21 | .notebox-content{ 22 | text-align: left; 23 | font-size: small; 24 | border: 1px thin black; 25 | } 26 | -------------------------------------------------------------------------------- /beginner/pendulum/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Progress 3 | 4 |

5 | 6 |

7 | 8 | # Project 9 | ## Pendulum 10 | **Tier:** 1-Beginner 11 | 12 | 13 | ## User Stories 14 | 15 | - [x] Animation of pendulum using pygame 16 | - [ ] User can select the starting angle (controlled by the mouse) 17 | - [ ] Display the speed and the acceleration 18 | 19 | ## Bonus features (Future) 20 | 21 | - [ ] Double Pendulum (Tier 2) 22 | 23 | ## Useful links and resources 24 | 25 | [Pendulum](https://en.wikipedia.org/wiki/Pendulum#Period_of_oscillation) 26 | 27 | ## Example projects 28 | 29 | -------------------------------------------------------------------------------- /beginner/pendulum/main.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import math 3 | pygame.init() 4 | clock = pygame.time.Clock() 5 | 6 | # DISPLAY 7 | screen_width = 500 8 | screen_height = 500 9 | screen = pygame.display.set_mode((screen_width,screen_height)) 10 | pygame.display.set_caption("Pendulum Animation") 11 | 12 | # COLORS 13 | white = pygame.Color(255,255,255) 14 | black = pygame.Color(0,0,0) 15 | red = pygame.Color(255,0,0) 16 | grey = pygame.Color(112,128,144) 17 | # VARIABLES 18 | length = 250 19 | angle = 90 20 | acceleration = 0 21 | velocity = 0 22 | 23 | # RECT FOR STORING COORDINATES 24 | class bob: 25 | def __init__(self,x,y,angle): 26 | self.x = x 27 | self.y = y 28 | self.angle = angle 29 | def draw(self): 30 | #circle = pygame.draw.circle(screen,(112,128,144),[(int(screen_width/2)),50],250) 31 | rod = pygame.draw.aalines(screen,white,False,[(int(screen_width/2),50),(self.x,self.y)]) 32 | riley = pygame.draw.circle(screen,(47,79,79),[self.x,self.y],20) 33 | #pygame.draw.arc(screen,(0,0,0),[0,50,500,250],0,self.angle) 34 | 35 | def length_calc(length,angle): 36 | ball.x = int(screen_width/2 + length * math.sin(angle)) 37 | ball.y = int(50+ length * math.cos(angle)) 38 | ball.angle = angle 39 | 40 | ball = bob(250,250,0) 41 | while True: 42 | 43 | for event in pygame.event.get(): 44 | if event.type == pygame.QUIT: 45 | pygame.quit() 46 | break 47 | 48 | screen.fill((220,220,220)) 49 | ball.draw() 50 | length_calc(length,angle) 51 | 52 | acceleration = -0.005 * math.sin(angle) 53 | velocity += acceleration 54 | velocity *= 0.99 55 | angle += velocity 56 | 57 | pygame.display.flip() 58 | clock.tick(30) 59 | -------------------------------------------------------------------------------- /beginner/recipe/webbased/chad_tea.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Test Recipe

9 |
    10 |
  • Meal Type
  • 11 |
  • Servings
  • 12 |
  • Difficulty
  • 13 |
14 |
15 |
16 | recipe image 17 |
18 |
    19 |
20 |
21 |

Instructions

22 |

23 |
24 |
25 | 26 | 29 | 30 | -------------------------------------------------------------------------------- /beginner/recipe/webbased/images/tea.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/recipe/webbased/images/tea.jpg -------------------------------------------------------------------------------- /beginner/recipe/webbased/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | recipe app 4 | 5 | 6 | 7 | 8 |

Recipe App

9 |
10 | 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /beginner/recipe/webbased/recipesjson/chad_tea.json: -------------------------------------------------------------------------------- 1 | { 2 | "recipe-info":{ 3 | "recipename":"Chad Tea", 4 | "recipetype":"Breakfast", 5 | "recipeservings":"One", 6 | "recipedifficulty":"Easy" 7 | }, 8 | "recipe-image":"images/tea.jpg", 9 | "recipe-ingredients": ["3 Tbs. green tea leaves", 10 | "4 oz. (8 Tbs.) unsalted butter","1/2 cup firmly packed light brown sugar", 11 | "1/4 cup mild honey","6-3/4 oz. (1-1/2 cups) unbleached all-purpose flour", 12 | "1 tsp. ground ginger","1/4 tsp. table salt","2 large eggs", 13 | "1 tsp. vanilla extract","1 tsp. finely grated orange zest", 14 | "1 tsp. baking soda","1/3 cup (1-3/4 oz.) dried cranberries; more for garnish", 15 | "4 oz. (1 cup) confectioners’ sugar, sifted"], 16 | "recipe-preparation":"Position a rack in the center of the oven and heat the oven to 350°F. Line 12 standard-size muffin cups with paper liners.\nBring 1 cup water to a boil, remove from the heat, stir in the tea, and steep for 5 minutes. Strain through a fine-mesh sieve, pressing to extract as much liquid as possible.\nIn a 2-quart saucepan, melt the butter over medium-low heat. Stir in the brown sugar and honey, and set aside to cool.\nIn a food processor or large bowl, combine the flour, ginger, and salt, and pulse to blend. Scrape in the butter mixture and blend. Add the eggs, vanilla, and orange zest and process until combined.\nStir the baking soda into 1/2 cup of the tea. Add to the batter along with the cranberries, and pulse. Portion the batter among the muffin cups, filling each about full. Bake, rotating halfway through, until a toothpick inserted in the center of the muffins comes out with moist crumbs clinging to it, about 15 minutes. Cool in the pan on a rack. Once cool, remove the muffins from the pan.\nIn a small bowl, combine the confectioners’ sugar with 1 Tbs. of the remaining tea. Whisk, adding more tea 1 tsp. at a time as necessary to make a thick but pourable icing. Drizzle over the cooled muffins, sprinkle with a few dried cranberries, and let set about 15 minutes before serving. The muffins are best the day they’re baked.\n" 17 | } -------------------------------------------------------------------------------- /beginner/recipe/webbased/recipetemplate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Test Recipe

9 |
    10 |
  • Meal Type
  • 11 |
  • Servings
  • 12 |
  • Difficulty
  • 13 |
14 |
15 |
16 | recipe image 17 |
18 |
    19 |
20 |
21 |

Instructions

22 |

23 |
24 |
25 | 26 | 29 | 30 | -------------------------------------------------------------------------------- /beginner/recipe/webbased/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | text-align: center; 3 | } 4 | 5 | .recipe-navigator { 6 | text-align: left; 7 | } 8 | 9 | .recipe-type{ 10 | padding-left: 0%; 11 | } 12 | 13 | .responsive-image{ 14 | width:25%; 15 | height: 25%; 16 | } 17 | 18 | .recipe-type li{ 19 | font-size: small; 20 | font-style: italic; 21 | display: inline; 22 | } 23 | 24 | .ingredients { 25 | text-align: left; 26 | } 27 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/C/bubblesort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int arr[] = {9,4,8,5,6,8,9}; 6 | int size = sizeof(arr) / sizeof(arr[0]); 7 | for (int x = 0; x < size; x++) 8 | { 9 | for (int y = 0; y < size - 1;y++) 10 | if (arr[y] > arr[y+1]) 11 | { 12 | int temp = arr[y]; 13 | arr[y] = arr[y+1]; 14 | arr[y+1]= temp; 15 | } 16 | } 17 | 18 | for (int p = 0; p < size;p++) 19 | { 20 | printf("element %d = %d\n",p,arr[p]); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/C/insertionsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Printer(int arr[],int *size) 4 | { 5 | for (int i = 0 ; i < *size ; i++) 6 | { 7 | printf("element %d = %d\n",i,arr[i]); 8 | } 9 | } 10 | 11 | 12 | int main() 13 | { 14 | int arr[] = {9,4,8,6,5,4}; 15 | int size = sizeof(arr)/sizeof(arr[0]); 16 | 17 | for (int i = 1; i < size; i++) 18 | { 19 | int value = arr[i]; 20 | int hole = i; // index 21 | while (hole > 0 && arr[hole -1 ] > value) 22 | { 23 | arr[hole] = arr[hole - 1]; 24 | hole -= 1; 25 | } 26 | arr[hole] = value; 27 | } 28 | 29 | // printing the array 30 | Printer(arr,&size); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/C/mergesort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void merge(int arr[],int left,int mid,int right) 4 | { 5 | 6 | 7 | int leftpart[(mid+1)-left]; 8 | int rightpart[(right+1)-(mid+1)]; 9 | 10 | // initializing left array 11 | 12 | for (int i = left;i < mid + 1;i++) 13 | { 14 | leftpart[i] = arr[i]; 15 | } 16 | 17 | // initializing right array 18 | for (int i = mid+1;i < right + 1;i++) 19 | { 20 | rightpart[i] = arr[i]; 21 | } 22 | 23 | //size of leftpart 24 | int s_left_part = sizeof(leftpart)/sizeof(leftpart[0]); 25 | //size of rightpart 26 | int s_right_part = sizeof(rightpart)/sizeof(rightpart[0]); 27 | 28 | int leftindex = 0; 29 | int rightindex = 0; 30 | 31 | for (int i = left;i < right + 1;i++) 32 | { 33 | if (s_left_part > leftindex && s_right_part > rightindex) 34 | { 35 | if (leftpart[leftindex] > rightpart[rightindex]) 36 | { 37 | arr[i] = rightpart[rightindex]; 38 | rightindex += 1; 39 | } 40 | else 41 | { 42 | arr[i] = leftpart[leftindex]; 43 | leftindex += 1; 44 | } 45 | } 46 | else if (s_left_part > leftindex) 47 | { 48 | arr[i] = leftpart[leftindex]; 49 | leftindex+= 1 ; 50 | } 51 | else 52 | { 53 | arr[i] = rightpart[rightindex]; 54 | rightindex+= 1 ; 55 | } 56 | } 57 | } 58 | 59 | void merge_sort_algorithm(int arr[],int left,int right) 60 | { 61 | if (left < right) 62 | { 63 | int mid = (left + right) /2; 64 | merge_sort_algorithm(arr, left,mid); 65 | merge_sort_algorithm(arr, mid+1,right); 66 | merge(arr,left,mid,right); 67 | } 68 | } 69 | 70 | 71 | int main() 72 | { 73 | int arr[] = {9,6,4,8,6,9}; 74 | int size = sizeof(arr) / sizeof(arr[0]); 75 | 76 | merge_sort_algorithm(arr,0,size -1); 77 | 78 | for (int k = 0; k < size;k++) 79 | { 80 | printf("arr %d = %d\n",k,arr[k]); 81 | } 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/C/quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int partition(int* A,int start,int end) 4 | { 5 | int pivot = A[end]; 6 | int pIndex = start; // partition index 7 | int temp; 8 | for (int i = start; i 2 | 3 | 4 | void PrintArray(int *arr, int *size) 5 | { 6 | for (int i = 0; i < *size;i++) { 7 | printf("element %d = %d\n",i,arr[i]); 8 | } 9 | } 10 | 11 | 12 | int main() 13 | { 14 | int arr[] = {4,5,9,8,4,6,2,4}; 15 | int size = sizeof(arr)/sizeof(arr[0]); 16 | 17 | for (int i = 0; i < size - 2;i++) 18 | { 19 | int min = i; 20 | for (int k = i+1; k < size ;k++) 21 | { 22 | if (arr[k] < arr[min]) 23 | { 24 | min = k; 25 | } 26 | } 27 | int temp = arr[i]; 28 | arr[i] = arr[min]; 29 | arr[min] = temp; 30 | } 31 | 32 | PrintArray(arr, &size); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/README.md: -------------------------------------------------------------------------------- 1 | # Algorithms 2 | ## Bubble Sort 3 |

4 | 5 |

6 | 7 | 8 | # References 9 | 1. [Youtube Tutorials](https://www.youtube.com/channel/UCWr4ecy8tuk6ClCAIN9H8Rw) 10 | 2. [Notes on Sorting](https://www.geeksforgeeks.org/sorting-algorithms/) 11 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/python/bubblesort.py: -------------------------------------------------------------------------------- 1 | import time 2 | def bubblesort(n,speed,drawdata): 3 | x = len(n) 4 | for p in range(x): 5 | for i in range(0,x-1): 6 | if n[i] > n[i+1]: 7 | n[i],n[i+1]=n[i+1],n[i] 8 | drawdata(n,["black" if x == i or x==i+1 else 'grey' for x in range(len(n))]) 9 | time.sleep(speed) 10 | drawdata(n,["grey" for x in range(len(n))]) 11 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/python/insertionsort.py: -------------------------------------------------------------------------------- 1 | import time 2 | def insertionsort(n,speed,drawdata): 3 | array_length = len(n) 4 | for i in range(1,array_length): 5 | k = ["grey" for i in range(len(n))] 6 | value = n[i] 7 | hole = i 8 | k[hole]="yellow" 9 | drawdata(n,k) 10 | while hole > 0 and n[hole-1]>value: 11 | n[hole] = n[hole-1] 12 | hole = hole -1 13 | n[hole]=value 14 | k[hole]="yellow" 15 | drawdata(n,k) 16 | time.sleep(speed) 17 | drawdata(n,["grey" for x in range(len(n))]) 18 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/python/mergesort.py: -------------------------------------------------------------------------------- 1 | #merge sort algorithm for-loop ~kinda~ 2 | import time 3 | 4 | # main algorithm 5 | def mergesort(data,sleeper,drawdata): 6 | merge_sort_algorithm(data,0,len(data)-1,drawdata,sleeper) 7 | 8 | 9 | def merge_sort_algorithm(data,left,right,drawdata,sleeper): 10 | if left < right: 11 | mid = (left+right)//2 12 | merge_sort_algorithm(data,left,mid,drawdata,sleeper) 13 | merge_sort_algorithm(data,mid+1,right,drawdata,sleeper) 14 | merge(data,left,mid,right,drawdata,sleeper) 15 | 16 | 17 | def merge(data,left,mid,right,drawdata,sleeper): 18 | drawdata(data, colorarray(len(data),left,mid,right)) 19 | time.sleep(sleeper) 20 | leftpart=data[left:mid+1] 21 | rightpart = data[mid+1:right+1] 22 | 23 | leftindex = rightindex = 0 24 | 25 | for dataindex in range(left,right+1): 26 | if len(leftpart) > leftindex and len(rightpart) > rightindex: 27 | if leftpart[leftindex] > rightpart[rightindex]: 28 | data[dataindex] = rightpart[rightindex] 29 | rightindex += 1 30 | else: 31 | data[dataindex] = leftpart[leftindex] 32 | leftindex += 1 33 | elif len(leftpart) > leftindex: 34 | data[dataindex] = leftpart[leftindex] 35 | leftindex += 1 36 | else: 37 | data[dataindex] = rightpart[rightindex] 38 | rightindex += 1 39 | 40 | drawdata(data,["pink" if x >= left and x <= right else "blue" for x in range(len(data))]) 41 | time.sleep(sleeper) 42 | 43 | 44 | def colorarray(n,left,mid,right): 45 | colorarr=[] 46 | for i in range(n): 47 | if i >= left and i <= right: 48 | if i>=left and i <= mid: 49 | colorarr.append("yellow") 50 | else: 51 | colorarr.append("green") 52 | else: 53 | colorarr.append("blue") 54 | return colorarr 55 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/python/quicksort.py: -------------------------------------------------------------------------------- 1 | #quick sort algorithm 2 | 3 | import time 4 | 5 | def quick_sort(data,drawdata,speedy): 6 | quicksort(data,0,len(data)-1,drawdata,speedy) 7 | 8 | def quicksort(arr,start,end,drawdata,speedy): 9 | 10 | drawdata(arr,getcolor(len(arr),start,end,start,start)) 11 | time.sleep(speedy) 12 | 13 | if start < end: 14 | partition_index = partition(arr,start,end,drawdata,speedy) 15 | 16 | quicksort(arr,start,partition_index-1,drawdata,speedy) 17 | quicksort(arr,partition_index+1,end,drawdata,speedy) 18 | return arr 19 | 20 | def partition(arr,start,end,drawdata,speedy): 21 | pivot = arr[end] 22 | pIndex = start 23 | for i in range(start,end): 24 | if arr[i] < pivot: 25 | drawdata(arr,getcolor(len(arr),start,end,pIndex,i,True)) 26 | time.sleep(speedy) 27 | arr[pIndex],arr[i] =arr[i],arr[pIndex] 28 | pIndex += 1 29 | drawdata(arr,getcolor(len(arr),start,end,pIndex,i,)) 30 | time.sleep(speedy) 31 | 32 | 33 | drawdata(arr,getcolor(len(arr),start,end,pIndex,i,)) 34 | time.sleep(speedy) 35 | arr[pIndex],arr[end] = arr[end],arr[pIndex] 36 | return (pIndex) 37 | 38 | # reference dennislovescoffee 39 | def getcolor(length,start,end,pIndex,current_index,iswapping=False): 40 | colorarr=[] 41 | for i in range(length): 42 | if i >= start and i <=end: 43 | colorarr.append("yellow") 44 | else: 45 | colorarr.append("white") 46 | if i == end: 47 | colorarr[i] = "blue" 48 | if i == pIndex: 49 | colorarr[i] = "green" 50 | 51 | if iswapping: 52 | if i==pIndex or i==current_index: 53 | colorarr[i] == "grey" 54 | return colorarr 55 | -------------------------------------------------------------------------------- /beginner/sorting_algorithm_visualizer/python/selectionsort.py: -------------------------------------------------------------------------------- 1 | import time 2 | def selectionsort(n,speed,drawdata): 3 | array_length = len(n) 4 | for i in range(0,len(n)): 5 | iMin = i 6 | for j in range(i+1,len(n)): 7 | if n[j] < n[iMin]: 8 | iMin = j 9 | k = ["pink" for i in range(len(n))] 10 | k[i],k[iMin]="yellow","yellow" 11 | n[i],n[iMin]=n[iMin],n[i] 12 | drawdata(n,k) 13 | time.sleep(speed) 14 | drawdata(n,["grey" for x in range(len(n))]) 15 | 16 | -------------------------------------------------------------------------------- /beginner/starfield_visualization/README.md: -------------------------------------------------------------------------------- 1 | # Progress 2 |

3 | 4 |

5 | 6 |

7 | 8 |

9 | 10 | **RANDOM HAPPY MISTAKES** 11 | 12 |

13 | 14 |

15 | 16 |

17 | 18 |

19 | 20 |

21 | 22 |

23 | 24 | 25 | # Project 26 | ## Starfield Visualization 27 | **Tier:** 1-Beginner 28 | 29 | [STAR GAZING](https://en.wikipedia.org/wiki/Glossary_of_astronomy) 30 | 31 | ## User Stories 32 | 33 | - [x] Starfield visualization 34 | - [x] Star-Cluster Visualization 35 | 36 | ## Bonus features 37 | 38 | - [ ] Spiral Galaxy Visualization 39 | 40 | ## Useful links, Resources and Example Projects 41 | 42 | The following project is inspired by the following [video](https://thecodingtrain.com/CodingChallenges/001-starfield.html) 43 | - [Star Cluster](https://codeboje.de/starfields-and-galaxies-python/) 44 | - [Ellipse Equations](https://mathopenref.com/coordparamellipse.html) 45 | - [Ellipse](https://en.wikipedia.org/wiki/Ellipse) 46 | - [Starfield Animation](https://github.com/jparise/pygame-starfield/blob/master/starfield.py) 47 | 48 | -------------------------------------------------------------------------------- /beginner/starfield_visualization/cloud.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import random 3 | import math 4 | # COLORS & CONSTANTS 5 | white = (255,255,255) 6 | black = (0,0,0) 7 | grey = (169,169,169) 8 | red = (255,0,0) 9 | color = [(255, 0, 0),(255, 165, 0) ,(255, 255, 0),(0, 128, 0),(0, 0, 255) ,(75, 0, 130) ,(238, 130, 238)] 10 | number_of_stars = 500 11 | 12 | pygame.init() 13 | clock = pygame.time.Clock() 14 | screen_size = (height,width) = (500,500) 15 | screen = pygame.display.set_mode(screen_size) 16 | pygame.display.set_caption("STARCLUSTER VISUALIZATION") 17 | 18 | 19 | class Star: 20 | def __init__(self,x,y): 21 | self.x = x 22 | self.y = y 23 | self.z = 1 24 | def draw(self): 25 | center = (int(self.x),int(self.y)) 26 | pygame.draw.circle(screen,color[random.randint(0,6)],center,0) 27 | 28 | def star_array(): 29 | global star_coordinates 30 | star_coordinates=[] 31 | for i in range(0,number_of_stars): 32 | degree = random.randint(0,360) 33 | degree = 2.0 * degree * math.pi / 360.0 #converting to rads 34 | #distribution = 0.001 35 | distribution = float(random.randint(0,10000)/10000) 36 | distribution = (distribution)**2 37 | xpos = (math.sin(degree)*distribution*200) #radius is 10 38 | ypos = (math.cos(degree)*distribution*350) 39 | star_coordinates.append([250+xpos,200+ypos]) 40 | 41 | def calculate(XY): 42 | star.x = XY[0] 43 | star.y = XY[1] 44 | 45 | running = True 46 | star = Star(0,0) 47 | star_array() 48 | print(star_coordinates) 49 | 50 | 51 | while running: 52 | for event in pygame.event.get(): 53 | if event.type == pygame.QUIT: 54 | running = False 55 | 56 | screen.fill(black) 57 | for i in star_coordinates: 58 | calculate(i) 59 | star.draw() 60 | 61 | pygame.display.flip() 62 | clock.tick(10) 63 | -------------------------------------------------------------------------------- /beginner/trueorfalse/.images/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/trueorfalse/.images/test.gif -------------------------------------------------------------------------------- /beginner/trueorfalse/README.md: -------------------------------------------------------------------------------- 1 | # TrueOrFalse 2 | 3 |

4 | 5 |

6 | 7 | **Tier:** 1-Beginner 8 | 9 | Something every developer needs to clearly understand is the result of 10 | conditional expressions like `x === y`. This is a bit more involved for 11 | Javascript developers who must also understand the concept of _truthiness_. 12 | 13 | TrueOrFalse helps by displaying the result when a conditional operator is 14 | applied to two values. Users can use this to test their knowledge and 15 | explore edge cases. 16 | 17 | The two values and the conditional operator are entered by the user and the 18 | result to be displayed will be TRUE or FALSE. The implementation must not use 19 | the `eval()` function to generate the result of the conditional. 20 | 21 | 22 | Since I will be using Python, I am going to imitate equality operators like `===` 23 | 24 | ## User Stories 25 | 26 | - [x] User can enter two strings to be compared 27 | - [x] User can enter a valid Javascript conditional operator to be used to compare the two strings 28 | - [x] User can see the result of the conditional as TRUE or FALSE 29 | - [ ] User can see a warning if the input strings or conditional operator that has been entered is not valid 30 | 31 | ## Bonus features 32 | 33 | - [ ] User can specify the type of each of the two strings so numbers can be compared to strings, strings to booleans, etc 34 | 35 | ## Useful links and resources 36 | 37 | - [Comparison Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators) 38 | - [Conditional Javascript for Experts](https://hackernoon.com/conditional-javascript-for-experts-d2aa456ef67c) 39 | - [Truthy and Falsy: When all is not equal in Javascript](https://www.sitepoint.com/javascript-truthy-falsy/) 40 | 41 | ## Example projects 42 | 43 | N/A 44 | -------------------------------------------------------------------------------- /beginner/trueorfalse/ui_main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'mainwDHaeH.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 5.15.2 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | 12 | from PyQt5.QtWidgets import * 13 | from PyQt5.QtGui import * 14 | from PyQt5.QtCore import * 15 | 16 | class Ui_Form(object): 17 | def setupUi(self, Form): 18 | if not Form.objectName(): 19 | Form.setObjectName(u"Form") 20 | Form.resize(625, 260) 21 | Form.setMinimumSize(QSize(625, 260)) 22 | Form.setMaximumSize(QSize(625, 260)) 23 | Form.setStyleSheet(u"background-color: rgb(0, 0, 0);") 24 | self.equalityoperator = QComboBox(Form) 25 | self.equalityoperator.setObjectName(u"equalityoperator") 26 | self.equalityoperator.setGeometry(QRect(230, 70, 161, 71)) 27 | self.equalityoperator.setStyleSheet(u"background-color: rgb(111, 111, 111);") 28 | self.text1 = QTextEdit(Form) 29 | self.text1.setObjectName(u"text1") 30 | self.text1.setGeometry(QRect(0, 10, 231, 221)) 31 | self.text1.setStyleSheet(u"background-color: rgb(111, 111, 111);") 32 | self.text2 = QTextEdit(Form) 33 | self.text2.setObjectName(u"text2") 34 | self.text2.setGeometry(QRect(390, 10, 231, 221)) 35 | self.text2.setStyleSheet(u"background-color: rgb(111, 111, 111);") 36 | self.trueorfalse = QLabel(Form) 37 | self.trueorfalse.setObjectName(u"trueorfalse") 38 | self.trueorfalse.setGeometry(QRect(0, 236, 621, 21)) 39 | self.trueorfalse.setStyleSheet(u"color: rgb(255, 255, 255);") 40 | self.trueorfalse.setAlignment(Qt.AlignCenter) 41 | 42 | self.retranslateUi(Form) 43 | 44 | QMetaObject.connectSlotsByName(Form) 45 | # setupUi 46 | 47 | def retranslateUi(self, Form): 48 | Form.setWindowTitle(QCoreApplication.translate("Form", u"True Or False", None)) 49 | self.trueorfalse.setText(QCoreApplication.translate("Form", u"True Or False", None)) 50 | # retranslateUi 51 | 52 | -------------------------------------------------------------------------------- /beginner/weatherapp/.images/desktoptest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/beginner/weatherapp/.images/desktoptest.png -------------------------------------------------------------------------------- /beginner/weatherapp/README.md: -------------------------------------------------------------------------------- 1 | # Weather App 2 | 3 | ### [Web Based](webbased) 4 | 5 | Make sure to replace the API key with your own API key from [openweathermaps](https://openweathermap.org/api). 6 | 7 | - [livepreview](https://codepen.io/kana800/pen/powLVXQ) 8 | 9 | ### [Desktop](desktopgui) 10 | 11 | Before running the programming makesure `PyQt5` and `requests` are installed. Also you need replace the API key with your own API key from [openweathermaps](https://openweathermap.org/api). 12 | 13 | To run the program 14 | ``` 15 | python3 weatherapp.py 16 | ``` 17 | 18 | #### Demo 19 | 20 | ![](.images/desktoptest.png) 21 | 22 | --- 23 | 24 | **Tier:** 1-Beginner 25 | 26 | A weather application to get the temperature, weather condition and whether it is day or night of a particular city using `accuweather`. A free weather api. 27 | 28 | ## User Stories 29 | 30 | - [x] Enter the name of a city into the `input` field. 31 | - [x] By pressing enter, the user submits the name of the city which updates the `DOM` with the temperature, weather condition, image of day or night and weather condition icon. 32 | 33 | ## Bonus features 34 | 35 | - [ ] By closing the browser window the city name will be stored in localStorage and when the user returns, the name will be retrieved to make an api call to update the `DOM`. 36 | 37 | ## Useful links and resources 38 | 39 | - [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) 40 | - [accuweather](https://developer.accuweather.com/) 41 | - [axios](https://github.com/axios/axios) 42 | - [bootstrap](https://getbootstrap.com/) 43 | 44 | ## Example projects 45 | 46 | - [Weather App on Codepen](https://codepen.io/tutsplus/pen/gObLaEP) by [George Martsoukos] 47 | - [Coding A Weather App In Pure JavaScipt](https://www.youtube.com/watch?v=ZPG2wGNj6J4) 48 | 49 | 50 | ## Image References 51 | 52 | - [clearsky](https://unsplash.com/photos/ROVBDer29PQ) 53 | - [cloudysky](https://unsplash.com/photos/UbDc3Mm7JP8) 54 | - [rainsky](https://unsplash.com/photos/gw023awV33A) 55 | - [snowsky](https://unsplash.com/s/photos/snow-sky) 56 | 57 | for the icons in the `desktop gui` you can download some random icons, the program will use `QPixmap` and **scale down** the image to the size of the `label`. 58 | -------------------------------------------------------------------------------- /beginner/weatherapp/webbased/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Weather App 4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 17 |

18 | 19 | 20 |
21 |
22 |

23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /beginner/weatherapp/webbased/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-size: cover; 3 | background-repeat: no-repeat; 4 | background-position: center center; 5 | } 6 | 7 | .container { 8 | height:200px; 9 | position: relative; 10 | border: 3px solid greenyellow; 11 | } 12 | 13 | .container-weather-input{ 14 | height:45px; 15 | position: relative; 16 | border: 3px solid greenyellow; 17 | } 18 | 19 | .weather-card { 20 | top:5%; 21 | left:50%; 22 | text-align: center; 23 | position: relative; 24 | box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); 25 | -ms-transform: translate(-50%,0%); 26 | transform: translate(-50%,0%); 27 | } 28 | 29 | 30 | 31 | .vertical-centered { 32 | margin:0; 33 | position: absolute; 34 | top:5%; 35 | left:50%; 36 | -ms-transform: translate(-50%,0%); 37 | transform: translate(-50%,0%); 38 | } -------------------------------------------------------------------------------- /beginner/windchill/desktopgui/Makefile: -------------------------------------------------------------------------------- 1 | P=ui_main 2 | CFLAGS=`pkg-config --cflags Qt5Widgets` 3 | LDLIBS=`pkg-config --libs Qt5Widgets` 4 | CC=g++ 5 | 6 | make main: 7 | $(CC) $(P).cpp -o $(P) $(LDLIBS) $(CFLAGS) -fPIC -------------------------------------------------------------------------------- /beginner/windchill/webbased/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Wind Chill 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 |
15 | 16 | 17 |
18 |
19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /beginner/windchill/webbased/main.js: -------------------------------------------------------------------------------- 1 | let calcbutton = document.getElementById("windchillcalc"); 2 | let windchillUnits = document.getElementById("answerUnits"); 3 | let airtempUnits = document.getElementById("airtempunits"); 4 | let windUnits = document.getElementById("windunits"); 5 | let SIunit = document.getElementById("units"); 6 | 7 | calcbutton.onclick = calculateWindChill; 8 | SIunit.onclick = changeUnits; 9 | 10 | function calculateWindChill(){ 11 | let windspeed = document.getElementById("wind").value; 12 | let airtemperature = document.getElementById("airtemperature").value; 13 | if ((windspeed == "") || (airtemperature == "")){ 14 | alert("Missing Values"); 15 | return; 16 | } 17 | let windchill = document.getElementById("windChill"); 18 | windchill.value=(0.0817*(3.71*(Math.pow(windspeed, 0.5))+5.81-0.25*windspeed)*(airtemperature-91.4)+91.4); 19 | } 20 | 21 | function changeUnits(){ 22 | if (SIunit.checked == true){ 23 | airtempUnits.innerHTML = "Air Temperature (C)" 24 | windchillUnits.innerHTML = "C" 25 | windUnits.innerHTML = "Wind Speed (KMPH)" 26 | }else{ 27 | airtempUnits.innerHTML = "Air Temperature (F)" 28 | windchillUnits.innerHTML = "F" 29 | windUnits.innerHTML = "Wind Speed (MPH)" 30 | } 31 | } -------------------------------------------------------------------------------- /beginner/windchill/webbased/style.css: -------------------------------------------------------------------------------- 1 | .windchill { 2 | top:5%; 3 | left:50%; 4 | text-align: center; 5 | position: relative; 6 | box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); 7 | -ms-transform: translate(-50%,0%); 8 | transform: translate(-50%,0%); 9 | } -------------------------------------------------------------------------------- /books/README.md: -------------------------------------------------------------------------------- 1 | ### Books 2 | 3 | This directory contains exercises from coding books; You can check my notes in my [garden](https://kannna.xyz/garden/) 4 | 5 | ### Map-Of-Content 6 | 7 | - [Exercises for Programming in C++](cpp_exercises) | [garden](https://kannna.xyz/garden/books/booksmoc) 8 | - [Digital Video and HD Algorithms and Interfaces](playingwithimages) | [garden](https://kannna.xyz/garden/books/booksmoc) 9 | -------------------------------------------------------------------------------- /books/cpp_exercises/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | 3 | 4 | basics: basics.cpp 5 | $(CC) basics.cpp -o basics.out 6 | 7 | classes: classes.cpp 8 | $(CC) classes.cpp -o classes.out 9 | -------------------------------------------------------------------------------- /books/cpp_exercises/README.md: -------------------------------------------------------------------------------- 1 | ### Exercises for Programming in C++ 2 | 3 | One of the books recommended by the `uni`. 4 | I thought it would be actually funny to atleast try few of the problems. *This is my attempt on it*, You can find more accurate answers in the book itself.[1] 5 | 6 | ### Map-Of-Content 7 | - [Basics](basics.cpp) 8 | - [Classes](classes.cpp) 9 | 10 | --- 11 | 12 | ### References 13 | - [Exercises for Programming in `C++`](https://www.ece.uvic.ca/~frodo/cppbook/downloads/exercises_for_programming_in_cpp-2021-04-01.pdf) 14 | 15 | 16 | [1]:https://www.ece.uvic.ca/~frodo/cppbook/downloads/exercises_for_programming_in_cpp-2021-04-01.pdf 17 | -------------------------------------------------------------------------------- /books/cpp_exercises/basics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using std::cout; 5 | 6 | #define multiply(x, y) x * y 7 | #define maximum(x,y) x > y ? x : y 8 | #define factorial(x) ((x) * factorial((x) - 1)) 9 | 10 | void swap(int &r1, int &r2){ 11 | /*summary: swap two numbers 12 | * question 2.19*/ 13 | int t = r1; 14 | r1 = r2; 15 | r2 = t; 16 | } 17 | 18 | void swap2(int* r1, int* r2){ 19 | /*summary: swap two numbers 20 | * question 2.19*/ 21 | int* temp = r1; 22 | r1 = r2; 23 | r2 = temp; 24 | } 25 | 26 | int main(int argc, char* argv[]){ 27 | /*question 11.1 : check what is wrong with code fragments 28 | * const char a = 'a'; 29 | * char *c = &a;*/ 30 | const char a = 'a'; 31 | const char *c = &a; 32 | /* 33 | * const int i = 42; 34 | * auto &j = i; 35 | * ++j; 36 | */ 37 | const int i = 42; 38 | auto &j = i; 39 | /*question 12 : check what is the size of the array*/ 40 | char s[] = "Hello"; 41 | /*question 13: state the type of each of the following objects*/ 42 | auto&& p = 0; 43 | /*question 16: print size and alignment of the variables*/ 44 | //std::cout << sizeof(int) << "\t" < 2 | 3 | 4 | /*exercise 3*/ 5 | class Counter { 6 | public: 7 | Counter(int c){ 8 | counter = c; 9 | counterExistence++; 10 | } 11 | 12 | ~Counter(){ 13 | counterExistence++; 14 | } 15 | 16 | int getValue() const { 17 | return counter; 18 | } 19 | 20 | Counter& operator++(int) { 21 | counter++; 22 | return *this; 23 | } 24 | 25 | Counter& operator--(int) { 26 | counter--; 27 | return *this; 28 | } 29 | 30 | int getCounterExistence() const { 31 | return counterExistence; 32 | } 33 | 34 | private: 35 | static int counterExistence; 36 | int counter = 0; 37 | }; 38 | 39 | int Counter::counterExistence = 0; 40 | 41 | int main(){ 42 | Counter c(1); 43 | Counter j(2); 44 | c++; 45 | j--; 46 | std::cout << c.getValue() << std::endl; 47 | std::cout << j.getValue() << std::endl; 48 | std::cout << c.getCounterExistence() << std::endl; 49 | } 50 | -------------------------------------------------------------------------------- /books/playingwithimages/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/books/playingwithimages/image.jpg -------------------------------------------------------------------------------- /codingproblem/README.md: -------------------------------------------------------------------------------- 1 | #### Table Of Content 2 | 3 | - [Daily Coding Problem](dcp) 4 | - [Project Euler](projecteuler) 5 | -------------------------------------------------------------------------------- /codingproblem/dcp/README.md: -------------------------------------------------------------------------------- 1 | #### Daily Coding Problems 2 | 3 | 1. [Problem #1](problem1.md) 4 | 2. [Problem #2](problem2.md) 5 | 3. [Problem #3](problem3.md) 6 | 4. [Problem #4](problem4.md) 7 | 5. [Problem #5](problem5.md) 8 | 6. [Problem #6](problem6.md) 9 | 7. [Problem #7](problem7.md) 10 | 8. [Problem #8](problem8.md) 11 | 9. [Problem #9](problem9.md) 12 | 10. [Problem #10](problem10.md) 13 | 11. [Problem #11](problem11.md) 14 | 12. [Problem #12](problem12.md) 15 | 13. [Problem #13](problem13.md) 16 | 14. [Problem #14](problem14.md) 17 | 15. [Problem #15](problem15.md) 18 | 16. [Problem #16](problem16.md) 19 | 17. [Problem #17](problem17.md) 20 | 18. [Problem #18](problem18.md) 21 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem11.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation of an autocomplete system 3 | */ 4 | #include 5 | #include "trie.h" 6 | #include "trie.c" 7 | 8 | // global head 9 | struct trie *HEAD; 10 | 11 | // loading words in the file into a array 12 | void readFile(char *filename){ 13 | // file pointer in read mode 14 | FILE *fp; 15 | 16 | // temp string to hold the word 17 | char string[20]; 18 | char ch; 19 | int i = 0; 20 | fp = fopen(filename, "r"); 21 | while ((ch = fgetc(fp)) != EOF){ 22 | if (ch == '\n'){ 23 | string[i] = '\0'; 24 | // inserting the node here 25 | insert(HEAD, string); 26 | i = 0; 27 | memset(string, 0 ,sizeof(string)); 28 | continue; 29 | } 30 | string[i++] = ch; 31 | } 32 | fclose(fp); 33 | return; 34 | } 35 | 36 | int main(){ 37 | HEAD = node(); 38 | char *filename = "words.txt"; 39 | readFile(filename); 40 | 41 | autocomplete(HEAD, "de"); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem12.py: -------------------------------------------------------------------------------- 1 | def getstaircount(numberofstairs, stepsize): 2 | # base case: 3 | # checking if the number of stairs is 4 | # one or less than one 5 | if numberofstairs < 0: 6 | return 0 7 | if numberofstairs == 0: 8 | # only takes one step to 9 | # reach one stair 10 | return 1 11 | elif numberofstairs in stepsize: 12 | # if we only need to take numberofstairs is X steps 13 | # f(n) = f(n-stepsize[0]) + f(n-stepsize[1]) ... + f(n-stepsize[N]) 14 | return 1 + sum(getstaircount(numberofstairs - stepstaken, stepsize) for 15 | stepstaken in stepsize if stepstaken < numberofstairs) 16 | else: 17 | return sum(getstaircount(numberofstairs - stepstaken, stepsize) for 18 | stepstaken in stepsize if stepstaken < numberofstairs) 19 | 20 | assert getstaircount(4,[1,2]) == 5 21 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem13.py: -------------------------------------------------------------------------------- 1 | import string as alphabet 2 | 3 | def substringWithKDistinctCharacters(string, k): 4 | """ 5 | Returns the substring with k distinct characters 6 | args: 7 | string -> str 8 | k -> int 9 | """ 10 | # store the maximum length of the substring 11 | length = 0 12 | 13 | # holds the length of the boundaries 14 | longeststart = 0 15 | longestend = 0 16 | 17 | # holds the pointer (window sliders) 18 | start = 0 19 | end = 0 20 | 21 | # data structure to distinct characters 22 | windowslider = set() 23 | 24 | # stores the times the character appeared in the string 25 | lowercase = alphabet.ascii_lowercase 26 | frequency = {} 27 | for letter in lowercase: 28 | frequency[letter] = 0 29 | 30 | while len(string) > end: 31 | # adding the number to the set 32 | windowslider.add(string[end]) 33 | # iterating the counter of the value 34 | frequency[string[end]] = frequency.get(string[end], 0) + 1 35 | 36 | # if pointer exceeds k characters, move to left 37 | while len(windowslider) > k: 38 | # iterating the counter of the value 39 | frequency[string[start]] = frequency.get(string[start], 0) - 1 40 | # removing the character from dictionary if its zero 41 | if frequency[string[start]] == 0: 42 | windowslider.remove(string[start]) 43 | # reduce the window slider (move to left) 44 | start += 1 45 | # calculate the maximum length 46 | length = max(length, end - start + 1) 47 | # updating the boundaries 48 | if length > longestend - longeststart + 1: 49 | longestend = end 50 | longeststart = start 51 | # increase the windowslider 52 | end += 1 53 | return string[longeststart: longestend + 1] 54 | 55 | 56 | 57 | if __name__ == "__main__": 58 | string = "abcbbbabbcbbadd" 59 | k = 2 60 | print(substringWithKDistinctCharacters(string, k)) 61 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem14.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def piMonteCarlo(numberofsamples, radius): 4 | """ 5 | Returns the pi value to 3 decimal places 6 | using montecarlomethod 7 | """ 8 | numberofpointsincircle = 0 9 | r = radius 10 | for n in range(0, numberofsamples): 11 | # selecting a random number of x^2 12 | # and y^2 13 | x = random.uniform(-1,1) * radius 14 | y = random.uniform(-1,1) * radius 15 | print(x,y) 16 | if (x**2) + (y**2) < (r**2): 17 | numberofpointsincircle += 1 18 | 19 | return round(4 * numberofpointsincircle/numberofsamples,3) 20 | 21 | print(piMonteCarlo(1000000,2)) 22 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Best DataStructure would be a BinaryTree 3 | */ 4 | 5 | #include 6 | #include 7 | #include "treeds.h" 8 | 9 | struct node* create_node(int num){ 10 | struct node *temp_node = malloc(sizeof(struct node)); 11 | 12 | temp_node->data = num; 13 | temp_node->leftptr = NULL; 14 | temp_node->rightptr = NULL; 15 | return temp_node; 16 | } 17 | 18 | struct node* addToTree(struct node *root, int num){ 19 | // root node not present 20 | if (root == NULL){ 21 | // creating a node 22 | struct node *temp_node = create_node(num); 23 | return temp_node; 24 | }else if(num <= root->data){ 25 | // recursion 26 | root->leftptr = addToTree(root->leftptr, num); 27 | }else { 28 | root->rightptr = addToTree(root->rightptr, num); 29 | } 30 | return root; 31 | } 32 | 33 | // prints the tree 34 | void printTree(struct node*root){ 35 | if (root == NULL){ 36 | return; 37 | } 38 | printTree(root->leftptr); 39 | printf("%c ",root->data); 40 | printTree(root->rightptr); 41 | } 42 | 43 | int main(int argc, char *argv[]){ 44 | char *c = "hello"; 45 | // EMPTY TREE 46 | struct node* root = NULL; 47 | root = addToTree(root, (int)(c[0])); 48 | root = addToTree(root, (int)(c[1])); 49 | root = addToTree(root, (int)(c[2])); 50 | root = addToTree(root, (int)(c[3])); 51 | 52 | printTree(root); 53 | printf("\n"); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GIVEN AN ARRAY OF INTEGERS FIND THE FIRST MISSING POSITIVE INTEGER 3 | */ 4 | #include 5 | #include 6 | 7 | // compare function for qsort 8 | int compare(const void *a, const void *b){ 9 | return *(int *)a - *(int *)b; 10 | } 11 | 12 | // returns the first positive index 13 | int positiveIndex(int *arr, int n){ 14 | for (int i = 0; i < n; i++){ 15 | if (arr[i] > 0){ 16 | return i; 17 | } 18 | } 19 | } 20 | 21 | // returns the missing positive integer 22 | int missingPostiveInteger(int *arr, int size, int positiveIdx){ 23 | // if the array starts from 24 | // a positive index 25 | int counter = 1; 26 | for (int i = positiveIdx; i < size; i++){ 27 | if (counter != arr[i]){ 28 | return counter; 29 | }else{ 30 | counter++; 31 | } 32 | } 33 | 34 | } 35 | 36 | int main(int argc, char **argv){ 37 | 38 | int arr[] = {3,4,-1,1}; 39 | int n = sizeof(arr)/sizeof(arr[0]); 40 | 41 | qsort(arr, n, sizeof(int), compare); 42 | 43 | for(int i = 0; i < n; i++){ 44 | printf("%d\n", arr[i]); 45 | } 46 | 47 | int p = positiveIndex(arr, n); 48 | 49 | int missingInteger = missingPostiveInteger(arr, n, p); 50 | printf("missing integer %d\n",missingInteger); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem5.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem #5 3 | """ 4 | 5 | # cons implementation 6 | def cons(a,b): 7 | return lambda f: f(a,b) 8 | 9 | 10 | def car(func): 11 | f1 = lambda a,b :a 12 | return func(f1) 13 | 14 | def cdr(func): 15 | f2 = lambda a,b:b 16 | return func(f2) 17 | 18 | 19 | if __name__ == "__main__": 20 | assert car(cons(3,4)) == 3 21 | assert cdr(cons(3,4)) == 4 22 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Problem 6: XOR Linked List 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | struct node *head = NULL; 9 | 10 | struct node { 11 | int data; 12 | struct node* xorNode; 13 | }; 14 | 15 | struct node* xorPointer(struct node* prev, struct node* next){ 16 | uintptr_t temp = (uintptr_t)prev^(uintptr_t)next; 17 | struct node * ptr = (struct node *)temp; 18 | return ptr; 19 | } 20 | 21 | // creates a node 22 | struct node* createNode(int num){ 23 | struct node *tempnode = malloc(sizeof(struct node)); 24 | 25 | tempnode->data = num; 26 | tempnode->xorNode = NULL; 27 | } 28 | 29 | // add a node to the tail 30 | void add(int element){ 31 | // if the list is empty 32 | struct node *tempnode = createNode(element); 33 | if (head == NULL){ 34 | head = tempnode; 35 | } else { 36 | // adding element to the list 37 | head->xorNode = xorPointer(tempnode, head); 38 | head = tempnode; 39 | } 40 | } 41 | 42 | void printList(){ 43 | 44 | struct node * temp = head; 45 | // next and prev pointer 46 | struct node * prev = NULL; 47 | struct node * next; 48 | 49 | while (temp != NULL){ 50 | printf("%d\n",temp->data); 51 | next = xorPointer(prev, temp->xorNode); 52 | 53 | // changing the previous and next pointer 54 | prev = temp; 55 | temp = next; 56 | } 57 | } 58 | 59 | 60 | int main(int argc, char ** argv){ 61 | 62 | head = NULL; 63 | add(5); 64 | add(3); 65 | 66 | printList(); 67 | 68 | return 0; 69 | } 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/problem7.py: -------------------------------------------------------------------------------- 1 | """ 2 | Number of possibilites of the decoded string 3 | """ 4 | 5 | def decodedPermutations(message): 6 | """ 7 | returns the number of possible 8 | decoded message 9 | """ 10 | # checking if the message arr is empty 11 | if len(message) == 0: 12 | return 1 13 | 14 | # stores the count 15 | count = 0 16 | 17 | for letter in range(1, 27): 18 | if message.startswith(str(letter)): 19 | count += decodedPermutations(message[len(str(letter)):]) 20 | return count 21 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/treeds.h: -------------------------------------------------------------------------------- 1 | #ifndef TREEDS_H 2 | #define TREEDS_H 3 | 4 | // node struct 5 | struct node { 6 | int data; 7 | struct node *leftptr; 8 | struct node *rightptr; 9 | }; 10 | 11 | // foward declaration of the functions 12 | struct node* create_node(int num); 13 | struct node* addToTree(struct node *root, int num); 14 | void printTree(struct node*root); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/trie.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIE_H 2 | #define TRIE_H 3 | 4 | // Each node has 26 (alphabet) possibilites of 5 | // characters 6 | #define POS 26 7 | 8 | struct trie{ 9 | struct trie* alphabetlinks[POS]; 10 | int leaf; // used to identify the end of the word 11 | }; 12 | 13 | struct trie *node(); 14 | void insert(struct trie *head, char *string); 15 | int search(struct trie *head, char *string); 16 | void autocomplete(struct trie *temp, char * string); 17 | void printTrie(struct trie * temp, char *string); 18 | char * concatString(char * string, int slice); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /codingproblem/dcp/codes/words.txt: -------------------------------------------------------------------------------- 1 | dog 2 | deer 3 | deal 4 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem1.md: -------------------------------------------------------------------------------- 1 | Problem 1 2 | --------- 3 | 4 | Given a list of numbers, return whether any two sums to k. For example, given `[10, 15, 3, 7]` and `k` of `17`, return true since `10 + 7` is `17`. 5 | 6 | Bonus: Can you do this in one pass? 7 | 8 | #### option #1 9 | 10 | we can calculate the value for each element of the array by adding it against every other element. For example: In the array `[10,5,3,7]`, if we take the first element of the array: `10`, we can add it against every other element, `10 + 5`, `10 + 3` and `10 + 7` and once we find the value `k`. we can return **true**. 11 | 12 | ##### counter examples? 13 | 14 | None 15 | 16 | We are doing **Exhaustive Search** and we need to iterate through the array two times!. Big Oh for the following scenario, would be `O(n ^ 2)`. 17 | 18 | ```python 19 | def checkKpresent(arr, k): 20 | for i in arr: 21 | for j in arr: 22 | if i+j == k: 23 | return True 24 | return False 25 | ``` 26 | 27 | #### option #2 28 | 29 | we can iterate through the array and substract value `k` from the array, for example: Lets take an empty array,`P`, we will iterate through the array `[10,15,3,7]` (`k = 17`), we will take the first index and substract `k` from `10` and add that value to the array`P` and once we move to `7`, we will check if that value is in `P`, if so, we have found the answer. 30 | 31 | ```python 32 | def checkKpresent(arr, k): 33 | P = set() 34 | # iterate through the array 35 | for num in arr: 36 | # check if the value is present 37 | if num in P: 38 | return True 39 | else: 40 | P.add(K - num) 41 | return False 42 | ``` 43 | 44 | why `P = set()`, because we need to makesure the same value is not added twice 45 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem10.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Apple. 2 | 3 | Implement a job scheduler which takes in a function f and an integer n, and calls f after n milliseconds. 4 | 5 | --- 6 | 7 | we can use the `sleep` from `time` module 8 | 9 | ```python 10 | from time import sleep 11 | 12 | def testFunction(): 13 | return "Hello World!" 14 | 15 | def jobScheduler(f, n): 16 | """ 17 | f -> function 18 | n -> time in milliseconds 19 | calls the function after n milliseconds 20 | """ 21 | sleep(n) 22 | testFunction() 23 | ``` 24 | 25 | 26 | References 27 | - [link](https://www.youtube.com/watch?v=Gs5jGDROx1M) 28 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem11.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Twitter. 2 | 3 | Implement an autocomplete system. That is, given a query string s and a set of all possible query strings, return all strings in the set that have s as a prefix. 4 | 5 | For example, given the query string de and the set of strings [dog, deer, deal], return [deer, deal]. 6 | 7 | Hint: Try preprocessing the dictionary into a more efficient data structure to speed up queries. 8 | 9 | --- 10 | 11 | [Answer](codes/problem11.c) 12 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem12.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Amazon. 2 | 3 | There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters. 4 | 5 | For example, if N is 4, then there are 5 unique ways: 6 | ``` 7 | 1, 1, 1, 1 8 | 2, 1, 1 9 | 1, 2, 1 10 | 1, 1, 2 11 | 2, 2 12 | ``` 13 | What if, instead of being able to climb 1 or 2 steps at a time, you could climb any number from a set of positive integers X? For example, if X = {1, 3, 5}, you could climb 1, 3, or 5 steps at a time. 14 | 15 | --- 16 | 17 | Find the number of possible ways that the sum of the generated numbers add up to `N`. we can use recursion to solve this problem. 18 | 19 | Example: 20 | ``` 21 | when n = 1 ---> [1] 22 | when n = 2 ---> [1,1] [2] 23 | when n = 3 ---> [1,1,1] [1,2] [2,1] 24 | when n = 4 ---> [1,1,1,1] [2,1,1] [1,2,1] [1,1,2] [2,2] 25 | ``` 26 | 27 | The pattern seems to be life the fibonacci sequence, whe ccan say to get the third step we have to go the first step and then go steps up and to go the fourth step you can go the third step and go one more step or go the second step and move two steps. 28 | ``` 29 | s(3) = s(2) + s(1) 30 | s(4) = s(3) + s(2) 31 | ``` 32 | 33 | [Implementation in Python](codes/problem12.py) 34 | 35 | Time complexity: `O(|stepsize|^N)` exponential growth, we can use dynamic programming to speed things up. 36 | 37 | [resources](https://www.dailycodingproblem.com/blog/staircase-problem/) 38 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem13.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Amazon. 2 | 3 | Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters. 4 | 5 | For example, given s = "abcba" and k = 2, the longest substring with k distinct characters is "bcb". 6 | 7 | --- 8 | 9 | #### method #1 10 | 11 | we can have a two pointer, 12 | ``` 13 | abcba 14 | ^ (start) 15 | ^ (end) 16 | ``` 17 | we will move the `end` pointer until we have k distinct characters and store the length of substring plus its index in a dictionary 18 | ``` 19 | length = end - start + 1 20 | ``` 21 | 22 | Time Complexity: `O(n)` 23 | 24 | [Solution to Problem #13](codes/problem13.py) 25 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem14.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Google. 2 | 3 | The area of a circle is defined as r^2. Estimate \pi to 3 decimal places using a Monte Carlo method. 4 | 5 | Hint: The basic equation of a circle is x^2 + y^2 = r^2. 6 | 7 | --- 8 | 9 | [Implementation using Python](codes/problem14.py) 10 | Time Complexity : `O(n)` 11 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem15.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Facebook. 2 | 3 | Given a stream of elements too large to store in memory, pick a random element from the stream with uniform probability. 4 | 5 | --- 6 | 7 | since the elements are too large to store in memory we are going to process the elements instead of storing them in a list. We can use a loop to select the random element 8 | 9 | 10 | if the length of stream is known, 11 | ```python 12 | from random import randint 13 | 14 | def pickrandomelement(stream): 15 | return stream[randint(0,len(stream))] 16 | ``` 17 | 18 | if the length of stream is unknown. 19 | 20 | ```python 21 | from random import randint 22 | 23 | global count 24 | 25 | def pickrandomelement(element): 26 | global count 27 | randomelement = None 28 | 29 | # number of elements encountered in the stream 30 | # can use enumerate instead 31 | count = 0 32 | 33 | # incremenet count 34 | count += 1 35 | 36 | if count == 1: 37 | randomelement = element 38 | else: 39 | i = randint(0, count - 1) 40 | if i == count - 1 41 | randomelement = element 42 | return randomelement 43 | 44 | for index, element in enumerate(stream): 45 | randomelement = pickrandomelement(element) 46 | print(f"{random element}") 47 | 48 | ``` 49 | 50 | #### Resources 51 | 52 | - [video abour reservoir sampling](https://www.youtube.com/watch?v=Ybra0uGEkpM) 53 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem17.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Google. 2 | 3 | Suppose we represent our file system by a string in the following manner: 4 | 5 | The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents: 6 | 7 | ``` 8 | dir 9 | subdir1 10 | subdir2 11 | file.ext 12 | ``` 13 | 14 | The directory dir contains an empty sub-directory subdir1 and a sub-directory subdir2 containing a file file.ext. 15 | 16 | The string "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext" represents: 17 | 18 | ``` 19 | dir 20 | subdir1 21 | file1.ext 22 | subsubdir1 23 | subdir2 24 | subsubdir2 25 | file2.ext 26 | ``` 27 | 28 | The directory dir contains two sub-directories subdir1 and subdir2. subdir1 contains a file file1.ext and an empty second-level sub-directory subsubdir1. subdir2 contains a second-level sub-directory subsubdir2 containing a file file2.ext. 29 | 30 | We are interested in finding the longest (number of characters) absolute path to a file within our file system. For example, in the second example above, the longest absolute path is "dir/subdir2/subsubdir2/file2.ext", and its length is 32 (not including the double quotes). 31 | 32 | Given a string representing the file system in the above format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0. 33 | 34 | --- 35 | 36 | We can split the string and put it in a tree and find the depth of the tree which would be O(h). 37 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem2.md: -------------------------------------------------------------------------------- 1 | Problem 2 2 | --------- 3 | This problem was asked by Uber. 4 | 5 | Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. 6 | 7 | For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6]. 8 | 9 | Follow-up: what if you can't use division? 10 | 11 | #### option #1 12 | 13 | we can get the product of all the elements in the array, using a for-loop and use division 14 | 15 | ##### counter examples? 16 | 17 | will not work with negative number because of the signs, for example `[-1, 2 ,-3 ,-4, 5]`. The product of every element would be `-1 * 2 * -3 * -4 * -5 = -120`. 18 | If we divide product of every element with the element at the index. `[-120/-1,-120/2,-120/-3,-120/-4,-120/5]` we will get `[120,-60,40,30,-24]` 19 | 20 | ```c 21 | int productofeveryelement(int *arr, int size){ 22 | int sum = 0; 23 | for( int i =0 ;i < n; i++){ 24 | sum *= arr[i]; 25 | } 26 | return sum; 27 | } 28 | 29 | int * newarray(int *arr, int size){ 30 | // finding the sum 31 | int sum = productofeveryelement(arr, size); 32 | // new array 33 | int narr[size]; 34 | // loop through the array 35 | for (int i = 0; i < n; i++){ 36 | narr[i] = sum / arr[i]; 37 | } 38 | return narr; 39 | } 40 | ``` 41 | 42 | Big Oh -> `O(n)` 43 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem3.md: -------------------------------------------------------------------------------- 1 | Problem 3 2 | --------- 3 | This problem was asked by Google. 4 | 5 | Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree. 6 | 7 | [code](codes/problem3.c) 8 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem4.md: -------------------------------------------------------------------------------- 1 | Problem 4 2 | --------- 3 | This problem was asked by Stripe. 4 | 5 | Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. 6 | 7 | For example, the input `[3, 4, -1, 1]` should give `2`. The input `[1, 2, 0]` should give 3. 8 | 9 | You can modify the input array in-place. 10 | 11 | 12 | #### Option #1 13 | 14 | We can use `set`, create a set in that range of the minimum number to maximum number and find the missing intersection values. 15 | 16 | ```python 17 | a = [3,4,-1,1] 18 | minnumber = min(a) 19 | maxnumber = max(a) 20 | b = [i for i in range(minnumber, maxnumber)] 21 | missing_numbers = b - a.intersection(b) 22 | ``` 23 | 24 | #### Option #2 25 | 26 | [code implementation](codes/problem4.c) 27 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem5.md: -------------------------------------------------------------------------------- 1 | Problem 5 2 | --------- 3 | This problem was asked by Jane Street. 4 | 5 | `cons(a, b)` constructs a pair, and `car(pair)` and `cdr(pair)` returns the first and last element of that pair. For example, `car(cons(3, 4))` returns `3`, and `cdr(cons(3, 4))` returns `4`. 6 | 7 | Given this implementation of cons: 8 | 9 | ```python 10 | def cons(a, b): 11 | return lambda f : f(a, b) 12 | ``` 13 | 14 | [Implement car and cdr](codes/problem5.py) 15 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem6.md: -------------------------------------------------------------------------------- 1 | Problem 6 2 | --------- 3 | 4 | This problem was asked by Google. 5 | 6 | An XOR linked list is a more memory efficient doubly linked list. Instead of each node holding next and prev fields, it holds a field named both, which is an XOR of the next node and the previous node. Implement an XOR linked list; it has an add(element) which adds the element to the end, and a get(index) which returns the node at index. 7 | 8 | [Implementaion of XOR Linked List](codes/problem6.c) 9 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem7.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Facebook. 2 | 3 | Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded. 4 | 5 | For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'. 6 | 7 | You can assume that the messages are decodable. For example, '001' is not allowed. 8 | 9 | --- 10 | 11 | This is recursive problem, check the number of ways you can spilt the message using a recursion tree. 12 | 13 | ``` 14 | message: 101 -> [10,1] 15 | message: 2626 -> [2,6,2,6] [26,26] 16 | message: 123 -> [1,2,3] [12,3] [1,23] 17 | message: 123456789 -> [1,2,3,4,5,6,7,8,9] [12,3,4,5,6,7,8,9] 18 | ``` 19 | 20 | [Implementation of problem #7(recursive)](codes/problem7.py) 21 | 22 | If we use memoization we can improve the speed of the algorithm. 23 | -------------------------------------------------------------------------------- /codingproblem/dcp/problem8.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Google. 2 | 3 | A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. 4 | 5 | Given the root to a binary tree, count the number of unival subtrees. 6 | 7 | For example, the following tree has 5 unival subtrees: 8 | ``` 9 | 0 10 | / \ 11 | 1 0 12 | / \ 13 | 1 0 14 | / \ 15 | 1 1 16 | ``` 17 | 18 | A unival tree is tree is a tree where all the nodes under it have the same values and empty nodes are compared as unival subtree 19 | ``` 20 | 3 21 | / \ 22 | 3 3 23 | ``` 24 | 25 | --- 26 | 27 | we can check the nodes: 28 | - left and right values are similar 29 | - number of empty nodes (leaf nodes) 30 | This would take `O(n)` time where `n` is the number of nodes. 31 | ```c 32 | // helperfunction: checks if the given tree is a unival tree 33 | // returns 1 if the tree is unival if not 0 34 | int univalTree(struct node * root){ 35 | if (root == NULL){ 36 | return 1; 37 | }else if ((root->rightptr != NULL) && (root->rightptr->data != NULL)){ 38 | // checking if the right tree is empty tree 39 | return 0; 40 | }else if ((root->leftptr != NULL) && (root->leftptr->data != NULL)){ 41 | return 0; 42 | }else if (univalTree(root->leftptr) && (univalTree(root->rightptr)){ 43 | // recursion until the end of the nodes 44 | return 1; 45 | }else{ 46 | return 0; 47 | } 48 | } 49 | ``` 50 | 51 | ```c 52 | int treeCount; // total number of trees 53 | 54 | // counts the number of unival trees 55 | int treeCounter(struct node * root){ 56 | // check if the tree is empty 57 | if (root == NULL){ 58 | return 0; 59 | } 60 | // recursion through the left subtree and the right subtrees 61 | treeCount = treeCounter(root.leftptr) + treeCounter(root.rightptr) ; 62 | // checking if the tree are unival 63 | if (univalTree(root) == 1){ 64 | treeCount += 1; 65 | } 66 | return treeCount; 67 | } 68 | ``` 69 | 70 | - [References](https://www.youtube.com/watch?v=7HgsS8bRvjo) -------------------------------------------------------------------------------- /codingproblem/dcp/problem9.md: -------------------------------------------------------------------------------- 1 | This problem was asked by Airbnb. 2 | 3 | Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. 4 | 5 | For example, [2, 4, 6, 8] should return 12, since we pick 4 and 8. [5, 1, 1, 5] should return 10, since we pick 5 and 5. 6 | 7 | --- 8 | 9 | ```python 10 | def largest_none_adjacent_sum(arr): 11 | prev = 0 # previous number 12 | larg = 0 # maximum number 13 | for i in arr: 14 | #tempLarg = max(prev, larg) 15 | #prev = larg + i 16 | #larg = tempLarg 17 | prev,larg = larg, max(larg, perv + i) 18 | #return max(larg, prev) 19 | return larg 20 | ``` 21 | 22 | Time complexity : `O(n)` because we are iterating through the array only once. -------------------------------------------------------------------------------- /codingproblem/projecteuler/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | ### Table Of Content 6 | 7 | - [Problem 1](problem1.c) 8 | - [Problem 2](problem2.c) 9 | -------------------------------------------------------------------------------- /codingproblem/projecteuler/problem1.c: -------------------------------------------------------------------------------- 1 | /* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. 2 | * The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000. 3 | */ 4 | #include 5 | 6 | 7 | int main(int argc, char *argv[]){ 8 | int sum = 0; 9 | 10 | for (int i = 0; i < 1000; i++){ 11 | if ((i % 3 == 0) || (i % 5 == 0)){ 12 | sum += i; 13 | } 14 | } 15 | printf("sum %d\n", sum); 16 | return 1; 17 | } 18 | -------------------------------------------------------------------------------- /codingproblem/projecteuler/problem2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]){ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /designpatterns/README.md: -------------------------------------------------------------------------------- 1 | This repo consist of notes/implementations of several design patterns. 2 | 3 | --- 4 | 5 | ### Table Of Content 6 | 7 | - [Visitor Design Pattern](visitor/README.md) -------------------------------------------------------------------------------- /designpatterns/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int, char**) { 4 | std::cout << "Hello, world!\n"; 5 | } 6 | -------------------------------------------------------------------------------- /designpatterns/visitor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0) 2 | project(visitor VERSION 0.1.0) 3 | 4 | include(CTest) 5 | enable_testing() 6 | 7 | 8 | add_subdirectory(card) 9 | 10 | add_executable(${PROJECT_NAME} main.cpp) 11 | 12 | set_target_properties(card PROPERTIES LINKER_LANGUAGE CXX) 13 | 14 | target_include_directories(${PROJECT_NAME} PUBLIC card) 15 | target_link_directories(${PROJECT_NAME} PRIVATE card) 16 | target_link_libraries(${PROJECT_NAME} card) 17 | 18 | set(CPACK_PROJECT_NAME ${PROJECT_NAME}) 19 | set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) 20 | include(CPack) 21 | -------------------------------------------------------------------------------- /designpatterns/visitor/README.md: -------------------------------------------------------------------------------- 1 | ### Visitor Design Pattern 2 | 3 | - Allows to add methods to classes of different types without much altering of those classes. 4 | - You can make completely different methods depending on the class used. 5 | - Allows you to define external classes that can exten other classes without majorly editing them 6 | 7 | 8 | > we will be using `shared_ptr` for automatic memory management 9 | 10 | --- 11 | 12 | In this [example](https://www.youtube.com/watch?v=TeZqKnC2gvA) we will implementing different types of credit cards and calculate the **cash back** you get according to the **offers** from different **credit cards** 13 | 14 | Amount of Cashback you get with different credit cards : 15 | 16 | | Offers | Gold | Silver | Bronze | 17 | |--------|------|--------|--------| 18 | | Gas | 10% | 2% | 5% | 19 | | Food | 20% | 3% | 10% | 20 | | Hotel | 10% | 2% | 3% | 21 | | Other | 1% | 5% | 20% | 22 | 23 | --- 24 | 25 | 26 | ### References 27 | 28 | - [visitor pattern explained](https://www.youtube.com/watch?v=pL4mOUDi54o) 29 | - [do factory visitor design pattern](https://www.dofactory.com/net/visitor-design-pattern) 30 | - [understanding visitor design pattern](https://www.youtube.com/watch?v=TeZqKnC2gvA) -------------------------------------------------------------------------------- /designpatterns/visitor/card/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CARD_SOURCE_FILE 2 | bronzecard.h 3 | creditcard.h 4 | goldcard.h 5 | silvercard.h 6 | offervisitor.h 7 | ) 8 | 9 | add_library(card ${CARD_SOURCE_FILE}) 10 | 11 | set_target_properties(card PROPERTIES LINKER_LANGUAGE CXX) -------------------------------------------------------------------------------- /designpatterns/visitor/card/bronzecard.h: -------------------------------------------------------------------------------- 1 | #ifndef BRONZECARD_H 2 | #define BRONZECARD_H 3 | 4 | #include "CreditCard.h" 5 | #include 6 | 7 | class BronzeCard: public CreditCard{ 8 | 9 | public: 10 | 11 | void accept(OfferVisitor* visitor)const override { 12 | visitor->visitBronzeCreditCard(this); 13 | }; 14 | }; 15 | 16 | #endif // BRONZECARD_H -------------------------------------------------------------------------------- /designpatterns/visitor/card/creditcard.h: -------------------------------------------------------------------------------- 1 | #ifndef CREDITCARD_H 2 | #define CREDITCARD_H 3 | 4 | 5 | #include "offervisitor.h" 6 | 7 | class CreditCard{ 8 | 9 | public: 10 | virtual ~CreditCard() = default; 11 | 12 | virtual void accept(OfferVisitor* visit) const = 0; 13 | 14 | }; 15 | 16 | #endif // CREDITCARD_H -------------------------------------------------------------------------------- /designpatterns/visitor/card/gasoffer.h: -------------------------------------------------------------------------------- 1 | #ifndef GASOFFER_H 2 | #define GASOFFER_H 3 | 4 | #include "offervisitor.h" 5 | #include 6 | 7 | class GasOffer: public OfferVisitor { 8 | 9 | public: 10 | virtual void visitGoldCreditCard(const GoldCard *goldcard) const override{ 11 | std::cout << "Gas Offer for Gold Cards" << std::endl; 12 | }; 13 | virtual void visitSilverCreditCard(const SilverCard *silvercard) const override { 14 | std::cout << "Gas Offer for Silver Cards" << std::endl; 15 | }; 16 | virtual void visitBronzeCreditCard(const BronzeCard *bronzecard) const override { 17 | std::cout << "Gas Offer for Bronze Cards" << std::endl; 18 | }; 19 | 20 | }; 21 | 22 | #endif // GASOFFER_H -------------------------------------------------------------------------------- /designpatterns/visitor/card/goldcard.h: -------------------------------------------------------------------------------- 1 | #ifndef GOLDCARD_H 2 | #define GOLDCARD_H 3 | 4 | #include "creditcard.h" 5 | #include "offervisitor.h" 6 | #include 7 | 8 | 9 | class GoldCard: public CreditCard{ 10 | 11 | public: 12 | 13 | void accept(OfferVisitor* visitor)const override { 14 | visitor->visitGoldCreditCard(this); 15 | }; 16 | }; 17 | 18 | #endif // GOLDCARD_H -------------------------------------------------------------------------------- /designpatterns/visitor/card/offervisitor.h: -------------------------------------------------------------------------------- 1 | /*VISITOR INTERFACE*/ 2 | #ifndef OFFERVISITOR_H 3 | #define OFFERVISITOR_H 4 | 5 | 6 | // forward declartion 7 | class BronzeCard; 8 | class SilverCard; 9 | class GoldCard; 10 | 11 | class OfferVisitor { 12 | 13 | public: 14 | virtual void visitGoldCreditCard( 15 | const GoldCard *goldcard) const = 0; 16 | virtual void visitSilverCreditCard( 17 | const SilverCard *silvercard) const = 0; 18 | virtual void visitBronzeCreditCard( 19 | const BronzeCard *bronzecard) const = 0; 20 | 21 | }; 22 | 23 | #endif //OFFER_H -------------------------------------------------------------------------------- /designpatterns/visitor/card/silvercard.h: -------------------------------------------------------------------------------- 1 | #ifndef SILVERCARD_H 2 | #define SILVERCARD_H 3 | 4 | #include "creditcard.h" 5 | #include "offervisitor.h" 6 | #include 7 | 8 | 9 | class SilverCard: public CreditCard{ 10 | 11 | public: 12 | 13 | void accept(OfferVisitor* visitor)const override { 14 | visitor->visitSilverCreditCard(this); 15 | }; 16 | }; 17 | 18 | #endif // SILVERCARD_H -------------------------------------------------------------------------------- /designpatterns/visitor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "bronzecard.h" 5 | #include "gasoffer.h" 6 | 7 | int main(int argc, char* argv[]){ 8 | 9 | BronzeCard *bronzeCard = new BronzeCard(); 10 | 11 | GasOffer *gasOffer = new GasOffer(); 12 | 13 | bronzeCard->accept(gasOffer); 14 | 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /games/tictactoe/README.md: -------------------------------------------------------------------------------- 1 | # Progress 2 | **Version #1** 3 |

4 | 5 |

6 | 7 | # TicTacToe 8 | 9 | **Tier:** 1-Beginner 10 | 11 | create a simple game of tictactoe 12 | 13 | ## User Stories 14 | 15 | - [x] Command Line Version of "tictactoe" 16 | 17 | - [x] GUI Version of "tictactoe" 18 | 19 | ## Bonus features 20 | 21 | - [ ] User can select the size of the "game" (cmd) 22 | - [x] Visual Aspects for the GUI version of "tictactoe" 23 | ## More ....! 24 | - [ ] User can select the size of the "game" (GUI) 25 | - [ ] User can select their own color, customization of the board 26 | ## Useful links and resources 27 | -------------------------------------------------------------------------------- /garden/README.md: -------------------------------------------------------------------------------- 1 | This directory contains *projects* and *implementations* from the *garden* notes, `curiosity` directory to be more specific ! 2 | 3 | ### Curiosity Projects 4 | 5 | - [`ELF` Analysis](elf_analysis) | [garden](https://kannna.xyz/garden/curiosity/ELF-Analysis) 6 | - [Socket Programming](socks) | [garden]() 7 | 8 | ### Courses Projects 9 | -------------------------------------------------------------------------------- /garden/elf_analysis/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | FLAGS=-Wall 3 | 4 | static: 5 | $(CC) -static -fno-pie -no-pie -g -o hellostatic.out hello.c 6 | dynamic: 7 | $(CC) -fno-pie -no-pie -g -o hellodynamic.out hello.c 8 | -------------------------------------------------------------------------------- /garden/elf_analysis/elf: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF64 4 | Data: 2's complement, little endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: DYN (Position-Independent Executable file) 9 | Machine: Advanced Micro Devices X86-64 10 | Version: 0x1 11 | Entry point address: 0x1060 12 | Start of program headers: 64 (bytes into file) 13 | Start of section headers: 13976 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 64 (bytes) 16 | Size of program headers: 56 (bytes) 17 | Number of program headers: 13 18 | Size of section headers: 64 (bytes) 19 | Number of section headers: 31 20 | Section header string table index: 30 21 | -------------------------------------------------------------------------------- /garden/elf_analysis/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | void newentrypoint(void){ 3 | printf("new entry point?\n"); 4 | return; 5 | } 6 | 7 | int main(){ 8 | printf("hello world\n"); 9 | newentrypoint(); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /karanprojects/Ciphers/decrypt.py: -------------------------------------------------------------------------------- 1 | # encryption 2 | 3 | from itertools import cycle 4 | 5 | def VigenereCipherDecrypt(letter,key_letter): 6 | return chr((((ord(letter) - ord(key_letter))+26) % 26)+ (ord('A') if letter.isupper() else ord('a'))) 7 | 8 | 9 | def VigenereCipher(text,key): 10 | encrypted_text = "" 11 | temp_text = list(text) 12 | iterkey = cycle(key) 13 | for i in temp_text: 14 | if i == " ": 15 | encrypted_text += " " 16 | pass 17 | else: 18 | p = next(iterkey) 19 | print(i,p) 20 | encrypted_text += VigenereCipherDecrypt(i,p) 21 | return encrypted_text 22 | 23 | def VernamCipher(text,key): 24 | if len(text) != len(key): 25 | raise NotImplementedError 26 | else: 27 | encrypted_text = "" 28 | for i in range(len(text)): 29 | keymessage= (ord(text[i]) -ord('A')) - (ord(key[i])-ord('A')) 30 | encrypted_text += chr((keymessage % 26 ) + ord('A')) 31 | return encrypted_text 32 | 33 | 34 | def CaesarCipher(text,shift): 35 | encrypted_text = "" 36 | for i in text: 37 | if i == " ": 38 | encrypted_text += " " 39 | pass 40 | else: 41 | encrypted_text += chr((((ord(i)-ord('A')) - shift)%26)+ord('A')) 42 | return encrypted_text 43 | -------------------------------------------------------------------------------- /karanprojects/Ciphers/encrypt.py: -------------------------------------------------------------------------------- 1 | # encryption 2 | 3 | from itertools import cycle 4 | 5 | def VigenereCipherDecrypt(letter,key_letter): 6 | return chr(((ord(letter) + ord(key_letter)) % 26)+ (ord('A') if letter.isupper() else ord('a'))) 7 | 8 | 9 | def VigenereCipher(text,key): 10 | encrypted_text = "" 11 | temp_text = list(text) 12 | iterkey = cycle(key) 13 | for i in temp_text: 14 | if i == " ": 15 | encrypted_text += " " 16 | pass 17 | else: 18 | p = next(iterkey) 19 | print(i,p) 20 | encrypted_text += VigenereCipherDecrypt(i,p) 21 | return encrypted_text 22 | 23 | def VernamCipher(text,key): 24 | if len(text) != len(key): 25 | raise NotImplementedError 26 | else: 27 | encrypted_text = "" 28 | for i in range(len(text)): 29 | keymessage= (ord(text[i]) -ord('A')) + (ord(key[i])-ord('A')) 30 | encrypted_text += chr((keymessage % 26 ) + ord('A')) 31 | return encrypted_text 32 | 33 | 34 | def CaesarCipher(text,shift): 35 | encrypted_text = "" 36 | for i in text: 37 | if i == " ": 38 | encrypted_text += " " 39 | pass 40 | else: 41 | encrypted_text += chr((((ord(i)-ord('A'))+shift)%26)+ord('A')) 42 | return encrypted_text 43 | -------------------------------------------------------------------------------- /karanprojects/alarm_clock/alarm.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import argparse 4 | from dateutil import parser 5 | import datetime 6 | 7 | p = argparse.ArgumentParser(description="Alarm Clock") 8 | p.add_argument('time',type=str , help ="Time To Sound the Alarm") 9 | args = p.parse_args() 10 | 11 | 12 | def alarm(): 13 | beep = lambda : os.system("echo -n '\a';sleep 0.2;" * 3) 14 | beep() 15 | 16 | if __name__ == "__main__": 17 | 18 | try: 19 | date = parser.parse(args.time) 20 | except Exception as e: 21 | print(f"Error {e}\n") 22 | raise NotImplementedError 23 | 24 | current_date = date - datetime.datetime.now().today() 25 | if current_date.total_seconds() <= 0: 26 | raise "Time Has Passed" 27 | else: 28 | while current_date: 29 | current_date = date - datetime.datetime.now().today() 30 | if int(current_date.total_seconds()) == 0: 31 | alarm() 32 | break 33 | -------------------------------------------------------------------------------- /karanprojects/alarm_clock/requirements.txt: -------------------------------------------------------------------------------- 1 | Package Version 2 | --------------- ------- 3 | pip 20.1.1 4 | python-dateutil 2.8.1 5 | setuptools 41.2.0 6 | six 1.15.0 7 | -------------------------------------------------------------------------------- /karanprojects/bank_manager/cpp/account.h: -------------------------------------------------------------------------------- 1 | #ifndef ACCOUNT_H 2 | #define ACCOUNT_H 3 | 4 | class Account { 5 | protected: 6 | double balance; 7 | 8 | public: 9 | bool deposit(double amount); 10 | const double display() const; 11 | bool withdraw(double amount); 12 | }; 13 | 14 | #endif // ACCOUNT_H -------------------------------------------------------------------------------- /karanprojects/bank_manager/cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "savingaccount.h" 3 | 4 | int main(int argc, char *argv[]){ 5 | SavingAccount ryan; 6 | ryan.deposit(500); 7 | ryan.display(); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /karanprojects/bank_manager/cpp/savingaccount.h: -------------------------------------------------------------------------------- 1 | #ifndef SAVINGACCOUNT_H 2 | #define SAVINGACCOUNT_H 3 | 4 | #include "account.h" 5 | 6 | class SavingAccount: public Account { 7 | public: 8 | SavingAccount(){ 9 | this->balance = 0.00; 10 | } 11 | ~SavingAccount(); 12 | void deposit(double amount){ 13 | this->balance += amount; 14 | } 15 | const double display() const { 16 | std::cout << "current balance: " << this->balance; 17 | return this->balance; 18 | } 19 | void withdraw(double amount) { 20 | this->balance -= amount; 21 | } 22 | }; 23 | 24 | #endif // SAVINGACC_H -------------------------------------------------------------------------------- /karanprojects/bank_manager/python/bankmanager.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Bank Account Consist: 3 | Deposit 4 | Cash Withdrawal 5 | ''' 6 | 7 | from abc import ABC,abstractmethod 8 | 9 | class Account(ABC): 10 | 11 | @abstractmethod 12 | def Deposit(self): 13 | pass 14 | 15 | @abstractmethod 16 | def Withdraw(self): 17 | pass 18 | 19 | @abstractmethod 20 | def Display(self): 21 | pass 22 | 23 | 24 | class SavingAccount(Account): 25 | 26 | def __init__(self): 27 | self.balance = 0 28 | 29 | @property 30 | def Display(self): 31 | ''' 32 | Balance in the account (instance of the account) 33 | ''' 34 | return self.balance 35 | 36 | def Deposit(self,amount): 37 | ''' 38 | Calculates the Deposited 39 | ''' 40 | self.balance += int(amount) 41 | print(self.Display) 42 | 43 | def Withdraw(self,amount): 44 | ''' 45 | Withdraws the Amount 46 | ''' 47 | if self.balance >= amount: 48 | self.balance -= amount 49 | print(self.Display) 50 | else: 51 | print("Insufficient Funds") 52 | -------------------------------------------------------------------------------- /karanprojects/coin_flip_simulation/C/cmd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int n = 0; 8 | int tails = 0; // [0] number of times tails come up 9 | int heads = 0; // [1] number of times heads come up 10 | 11 | printf("Enter the Number of Turns\n"); 12 | scanf("%d",&n); 13 | 14 | while (n > 0) 15 | { 16 | int r = rand() % 2; 17 | if (r == 0) 18 | { 19 | tails += 1; 20 | } 21 | else if (r == 1) 22 | { 23 | heads += 1; 24 | } 25 | n -= 1; 26 | } 27 | 28 | printf("Heads = %d \nTails = %d \n",heads,tails); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /karanprojects/coin_flip_simulation/README.md: -------------------------------------------------------------------------------- 1 | ## Project: Coin Flip Simulation 2 | 3 | **Tier:** 1-Beginner 4 | 5 | Write some code that simulates flipping a single coin however many times the user decides. 6 | The code should record the outcomes and count the number of tails and heads. 7 | -------------------------------------------------------------------------------- /karanprojects/coin_flip_simulation/python/cmd.py: -------------------------------------------------------------------------------- 1 | # coin flip 2 | import random 3 | 4 | def counter(n): 5 | head = 0 6 | tails = 0 7 | while n > 0: 8 | choice = random.randint(1,2) 9 | if choice == 1: 10 | head += 1 11 | if choice == 2: 12 | tails += 1 13 | n -= 1 14 | print("Head",head) 15 | print("Tail",tails) 16 | return head,tails 17 | 18 | try: 19 | number_of_rotations = int(input("ENTER THE NUMBER_OF_ROTATION\n")) 20 | print(counter(number_of_rotations)) 21 | except ValueError or NameError: 22 | print("Wrong Value!\nRestart") 23 | 24 | 25 | -------------------------------------------------------------------------------- /karanprojects/company_manager/README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | 4 | :office: 5 | 6 |

Company-Manager

7 |

8 |
9 | Project List 10 | · 11 | Report Bug 12 | · 13 | Request Feature 14 |

15 |

16 | 17 | The code in the `cpp` and `python` files are used to practice the concepts of objected oriented and classes. The code might contains bugs and memory leaks. If you find any please raise and issue :smile: 18 | -------------------------------------------------------------------------------- /karanprojects/company_manager/cpp/company.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "employee.h" 4 | 5 | int main(int argc, char **argv){ 6 | // creating an hourly employee 7 | HourlyEmployee hourlyemployee1 = HourlyEmployee("Jake", "Tame","Hourly", 5); 8 | std::cout << hourlyemployee1.getFullName(); 9 | std::cout << hourlyemployee1.getPay(); 10 | } -------------------------------------------------------------------------------- /karanprojects/distance_between_two_cities/distance.py: -------------------------------------------------------------------------------- 1 | from geopy.geocoders import Nominatim 2 | from geopy.distance import geodesic 3 | from geopy.distance import lonlat, distance 4 | import argparse 5 | 6 | 7 | geolocator = Nominatim(user_agent="test") 8 | 9 | # setting up arg parse 10 | parser = argparse.ArgumentParser(description="Returns the distance between two cities") 11 | parser.add_argument('city1',type=str,help="Name of first city") 12 | parser.add_argument('city2',type=str,help="Name of second city") 13 | parser.add_argument('units',type=str,help="Enter the Units (km,m,miles)") 14 | args = parser.parse_args() 15 | 16 | 17 | def Locator(loc1,loc2): 18 | location1 = geolocator.geocode(loc1) 19 | location2 = geolocator.geocode(loc2) 20 | return [(location1.latitude,location1.longitude),(location2.latitude,location2.longitude)] 21 | 22 | 23 | def Distance(loc1,loc2,unit): 24 | if unit == "km": 25 | return distance(lonlat(*loc1),lonlat(*loc2)).km 26 | elif unit == "mi": 27 | return distance(lonlat(*loc1),lonlat(*loc2)).mi 28 | elif unit == "m": 29 | return distance(lonlat(*loc1),lonlat(*loc2)).m 30 | else: 31 | raise NotImplementedError 32 | 33 | if __name__ == "__main__": 34 | loc1 = args.city1 35 | loc2 = args.city2 36 | unit = args.units 37 | x = Locator(loc1,loc2) 38 | print(Distance(x[0],x[1],unit)) 39 | -------------------------------------------------------------------------------- /karanprojects/expense_tracker/.images/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/karanprojects/expense_tracker/.images/test.gif -------------------------------------------------------------------------------- /karanprojects/expense_tracker/README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | 4 | :volcano: 5 | 6 |

Expense Tracker

7 |

8 |
9 | Project List 10 | · 11 | Report Bug 12 | · 13 | Request Feature 14 |

15 |

16 | 17 | ### Desktop Based (Python) 18 | 19 | This project is designed to keep in track of products and items for a small local business. 20 | 21 | #### Preview 22 | 23 |

24 | 25 |

26 | 27 | #### Usage 28 | 29 | * Clone the repository 30 | * Make sure that the **all** the packages in the `requirements.txt` are installed 31 | 32 | ``` 33 | python run.py 34 | ``` 35 | -------------------------------------------------------------------------------- /karanprojects/expense_tracker/items.csv: -------------------------------------------------------------------------------- 1 | item_name 2 | 3 | -------------------------------------------------------------------------------- /karanprojects/expense_tracker/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.18.5 2 | pandas==1.0.4 3 | PyQt5==5.15.0 4 | PyQt5-sip==12.8.0 5 | PyQtChart==5.15.0 6 | python-dateutil==2.8.1 7 | pytz==2020.1 8 | six==1.15.0 9 | -------------------------------------------------------------------------------- /karanprojects/expense_tracker/run.py: -------------------------------------------------------------------------------- 1 | from sample.__main__ import main 2 | 3 | 4 | 5 | main() 6 | -------------------------------------------------------------------------------- /karanprojects/expense_tracker/sample/__main__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtWidgets as qtw 3 | from PyQt5 import QtGui as qtg 4 | from PyQt5 import QtCore as qtc 5 | from .mainwindow import MainWindow 6 | 7 | def main(): 8 | app = qtw.QApplication(sys.argv) 9 | window = MainWindow() 10 | style = qtw.QStyleFactory.create('Fusion') 11 | app.setStyle(style) 12 | sys.exit(app.exec()) 13 | 14 | if __name__ == "__main__": 15 | main() 16 | -------------------------------------------------------------------------------- /karanprojects/expense_tracker/test.csv: -------------------------------------------------------------------------------- 1 | Transaction Type,Date,Name, Product , Amount (kg) , Price (per Kg) ,Total Price 2 | 3 | -------------------------------------------------------------------------------- /karanprojects/fastexpo/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ask the user to enter 2 integers a and b and 3 | * output a^b 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // a -> base and b -> exponent 11 | int forpow(int a, int b){ 12 | // simple iteration using for loop 13 | int p = a; 14 | for (int i = 1; i < b; i++){ 15 | p *= a; 16 | } 17 | return p; 18 | } 19 | 20 | int main(int argc, char *argv[]){ 21 | 22 | //mystring is used to store the content 23 | //inputted by the user 24 | std::string mystr; 25 | int a,b; 26 | 27 | std::cout << "Enter A: "; 28 | //getline(stream, variable) 29 | getline(std::cin, mystr); 30 | //stringstream convert str into num 31 | std::stringstream(mystr) >> a; 32 | std::cout << "Enter B: "; 33 | //getline(stream, variable) 34 | getline(std::cin, mystr); 35 | //stringstream convert str into num 36 | std::stringstream(mystr) >> b; 37 | 38 | int answer = pow(a,b); 39 | printf("The power of %d^%d=%d \n",a,b, answer); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /karanprojects/fibonacci_sequence/C/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * fibonacci sequence 5 | */ 6 | 7 | 8 | int fibonacci(int n) 9 | { 10 | if (n <= 0) 11 | { 12 | return 0; 13 | } 14 | else if (n == 1) 15 | { 16 | return 1; 17 | } 18 | else 19 | { 20 | return fibonacci(n - 1) + fibonacci(n - 2); 21 | } 22 | } 23 | 24 | int main() 25 | { 26 | printf(" %d th element is %d\n",7,fibonacci(7)); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /karanprojects/flowershops/README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | 4 | :sunflower: 5 | 6 |

Flower Shop

7 |

8 |
9 | Project List 10 | · 11 | Report Bug 12 | · 13 | Request Feature 14 |

15 |

16 | 17 | The code in the `cpp` and `python` files are used to practice the concepts of objected oriented and classes. The code might contains bugs and memory leaks. If you find any please raise and issue :smile: 18 | -------------------------------------------------------------------------------- /karanprojects/flowershops/python/flowers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Create a flower shop application which deals in flower objects and 3 | use those flower objects in a bouquet object which can then be sold. 4 | Keep track of the number of objects and when you may need to order more. 5 | ''' 6 | 7 | flower_type = ['Rose','Carnation','Tulip','Lily','Orchid'] 8 | 9 | 10 | 11 | class flower: 12 | 13 | def __init__(self,name,price): 14 | self.name = name 15 | self.price = price 16 | 17 | def __str__(self): 18 | return self.name 19 | 20 | class Bouquet: 21 | 22 | def __init__(self,name,flower): 23 | self.name = name 24 | self.flower = flower 25 | 26 | @property 27 | def price(self): 28 | p = 0 # price of the bouquet 29 | for i,x in self.flower.items(): 30 | p += i.price * x 31 | return p 32 | 33 | class Shop: 34 | 35 | def __init__(self,name,items): 36 | self.name = name 37 | self.items = items 38 | self.income = 0 39 | 40 | def sell(self,bouquet_name,quantity): 41 | q = self.items[bouquet_name] 42 | if quantity > q: 43 | return "Item Not Available" 44 | else: 45 | quantity -= 1 46 | self.items[bouquet_name] = quantity 47 | self.income += bouquet_name.price 48 | 49 | 50 | @property 51 | def availablestuff(self): 52 | print("ITEMS\n") 53 | for i,j in self.items.items(): 54 | print(f"\tname: {i.name}\tquantity: {j}\tprice: ${i.price}") 55 | 56 | if __name__ == '__main__': 57 | # flowers 58 | rose = flower('rose',4.50) 59 | tulip = flower('tulip',9.99) 60 | orchid = flower('orchid',4.33) 61 | 62 | justfriends=Bouquet('Just Friends',{rose:5,tulip:2}) 63 | justmarried=Bouquet('Just Married',{rose:200,tulip:400}) 64 | s = Bouquet('Sorry for forgetting your bday',{rose:50,tulip:40,orchid:40}) 65 | 66 | shop = Shop('flower hub',{justfriends:40,justmarried:30,s:1}) 67 | print("income @ start\n",shop.income) 68 | shop.sell(justfriends,4) 69 | print("income after first sale\n",shop.income) 70 | shop.sell(s,25) # over ordering! 71 | shop.availablestuff 72 | -------------------------------------------------------------------------------- /karanprojects/image_gallery/gallery.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtWidgets as qtw 3 | from PyQt5 import QtGui as qtg 4 | from PyQt5 import QtCore as qtc 5 | from abc import ABC 6 | 7 | class Image(ABC): 8 | 9 | def imagetype(self): 10 | pass 11 | 12 | class jpg(Image): 13 | 14 | def __init__(self,file_name): 15 | self.file_name = file_name 16 | 17 | @property 18 | def imagetype(self): 19 | return qtg.QPixmap(self.file_name) 20 | 21 | class png(Image): 22 | 23 | def __init__(self,file_name): 24 | self.file_name = file_name 25 | 26 | @property 27 | def imagetype(self): 28 | return qtg.QPixmap(self.file_name) 29 | 30 | class MainWindow(qtw.QWidget): 31 | 32 | def __init__(self): 33 | super().__init__() 34 | 35 | self.fname,other = qtw.QFileDialog.getOpenFileName(self,"Open File","/home","Images (*.png *.jpg)") 36 | 37 | if self.fname.split(".")[-1] == 'png': 38 | i = png(self.fname) 39 | image = i.imagetype 40 | elif self.fname.split(".")[-1] == 'jpg': 41 | i = jpg(self.fname) 42 | image = i.imagetype 43 | 44 | label = qtw.QLabel() 45 | label.setPixmap(image) 46 | 47 | self.setLayout(qtw.QHBoxLayout()) 48 | self.layout().addWidget(label) 49 | self.show() 50 | 51 | 52 | if __name__ == "__main__": 53 | 54 | app = qtw.QApplication(sys.argv) 55 | window = MainWindow() 56 | style = qtw.QStyleFactory.create('Fusion') 57 | app.setStyle(style) 58 | sys.exit(app.exec()) 59 | -------------------------------------------------------------------------------- /karanprojects/mortgage_calculator/mortage.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def mortgage_payment(principal,r,N): 4 | r = (r * 0.01) / 12 5 | N = N * 12 6 | fraction = (r*((1+r)**N))/(((1+r)**N)-1) 7 | return principal * fraction 8 | 9 | 10 | if __name__ == "__main__": 11 | print(mortgage_payment(100000,6.5,30)) 12 | -------------------------------------------------------------------------------- /karanprojects/patient_doctor_scheduler/schedule.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from datetime import datetime 3 | 4 | 5 | class Person: 6 | def __init__(self,f_name,l_name): 7 | self.f_name = f_name 8 | self.l_name = l_name 9 | self.full_name = f_name + l_name 10 | self.calendar = Calendar() 11 | 12 | def is_available(self,slot): 13 | return self.calendar.is_available(slot) 14 | 15 | def make_appointment(self,slot,record): 16 | return self.calendar.add_entry(slot,record) 17 | 18 | class Patient(Person): 19 | 20 | def __init__(self,f_name,l_name): 21 | super().__init__(f_name,l_name) 22 | self.app_id = self.f_name[0]+self.l_name #appointment id 23 | 24 | class Doctor(Person): 25 | 26 | def __init__(self,f_name,l_name,speciality): 27 | super().__init__(f_name,l_name) 28 | self.speciality = speciality 29 | 30 | class Calendar(object): 31 | 32 | def __init__(self): 33 | self.entries = {} 34 | 35 | def is_available(self,slot): 36 | return slot not in self.entries 37 | 38 | def add_entry(self,slot,record): 39 | self.entries[slot] = record 40 | 41 | def schedule(doctor,patient,slot): 42 | 43 | if doctor.is_available(slot) == False: 44 | return f"Doctor {doctor.full_name} not available at {slot}" 45 | 46 | doctor.make_appointment(slot,patient.app_id) 47 | patient.make_appointment(slot,doctor.full_name) 48 | -------------------------------------------------------------------------------- /karanprojects/recipe_creator_manager/receipe.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This program can create recipes and the user can sort them out 'event' or 'ingredients' 3 | ''' 4 | 5 | 6 | 7 | class Recipe: 8 | ''' 9 | ''' 10 | recipe = {} 11 | def __init__(self,name,category,ingredient_list): 12 | self.name = name 13 | self.category = category 14 | self.ingredient_list = ingredient_list 15 | self.recipe[name] = [category,ingredient_list] 16 | 17 | def __str__(self): 18 | string ="name = {}\n \tcategory = {}\n\tingredients = {}".format(self.name,self.category,self.ingredients) 19 | return string 20 | 21 | @property 22 | def ingredients(self): 23 | a = "" 24 | for i in self.ingredient_list: 25 | a += f"{i[0]} of {i[1]} ," 26 | return a[:-1] 27 | 28 | class Recipe_Manager: 29 | 30 | by_category = {} 31 | def __init__(self): 32 | self.by_category['dessert'] = [] 33 | self.by_category['main dishes'] = [] 34 | self.by_category['beef recipes'] = [] 35 | 36 | def add_recipe(self,recipe): 37 | try: 38 | self.by_category[recipe.category].append(recipe) 39 | except KeyError: 40 | self.by_category[recipe.category] = [recipe] 41 | 42 | def categories(self,category): 43 | try: 44 | for r in self.by_category[category]: 45 | print(r) 46 | except: 47 | raise NotImplementedError 48 | 49 | if __name__ == "__main__": 50 | 51 | # created some random recipes 52 | r1 = Recipe('pie','dessert',[[1,'pumpkin puree'],[250,'sugar'],[100,'cream']]) 53 | r2 = Recipe('cake','dessert',[[1,'chocolate'],[250,'sugar'],[100,'cream']]) 54 | r3 = Recipe('brownies','dessert',[[10,'oreos'],[250,'sugar'],[100,'cream']]) 55 | 56 | # created a recipe manager 57 | r = Recipe_Manager() 58 | 59 | # adding recipes 60 | r.add_recipe(r1) 61 | r.add_recipe(r2) 62 | r.add_recipe(r3) 63 | 64 | # displaying the recipes by_category 65 | 66 | r.categories('dessert') 67 | -------------------------------------------------------------------------------- /karanprojects/regex_query_tool/README.md: -------------------------------------------------------------------------------- 1 | # Regex-Query-Tool 2 | A tool that allows the user to enter a text string and then in a separate control enter a regex pattern. It will run the regular expression against the source text and return any matches or flag errors in the regular expression. 3 | 4 | # Demo 5 | 6 |

7 | 8 |

9 | 10 | # Usage 11 | 12 | * Clone the Repo 13 | * Run `__main__.py` 14 | 15 | # Contributions 16 | 17 | * Submit an Issue 18 | * Create a Pull Request 19 | 20 | -------------------------------------------------------------------------------- /karanprojects/regex_query_tool/src/__main__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtWidgets as qtw 3 | from PyQt5 import QtGui as qtg 4 | from PyQt5 import QtCore as qtc 5 | from mainwindow import MainWindow 6 | 7 | def main(): 8 | app = qtw.QApplication(sys.argv) 9 | window = MainWindow() 10 | style = qtw.QStyleFactory.create('Fusion') 11 | app.setStyle(style) 12 | sys.exit(app.exec()) 13 | 14 | if __name__ == "__main__": 15 | main() 16 | -------------------------------------------------------------------------------- /karanprojects/regex_query_tool/src/dialogbox.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtWidgets as qtw 3 | from PyQt5 import QtGui as qtg 4 | from PyQt5 import QtCore as qtc 5 | 6 | 7 | class DialogBox(qtw.QMessageBox): 8 | 9 | def __init__(self,words): 10 | super().__init__() 11 | self.setText("Results from your RegEx Search") 12 | 13 | word = "" 14 | for i in words: 15 | word += f"{i} \n" 16 | print(word) 17 | self.setDetailedText(word) 18 | 19 | self.show() 20 | 21 | 22 | if __name__ == "__main__": 23 | app = qtw.QApplication(sys.argv) 24 | window = DialogBox() 25 | style = qtw.QStyleFactory.create('Fusion') 26 | app.setStyle(style) 27 | sys.exit(app.exec()) 28 | -------------------------------------------------------------------------------- /karanprojects/shapes/shape.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Shape Area and Perimeter Classes - Create an abstract class called Shape and then inherit from it other shapes like diamond, rectangle, circle, triangle etc. 3 | Then have each class override the area and perimeter functionality to handle each shape type. 4 | ''' 5 | 6 | from abc import ABC, abstractmethod 7 | from math import pi 8 | 9 | class Shape(ABC): 10 | 11 | @abstractmethod 12 | def area(self): 13 | pass 14 | 15 | @abstractmethod 16 | def perimeter(self): 17 | pass 18 | 19 | 20 | 21 | class Circle(Shape): 22 | 23 | def __init__(self,radius): 24 | self.radius = radius 25 | 26 | def area(self): 27 | return float(pi*(self.radius)**2) 28 | 29 | def perimeter(self): 30 | return float(2*pi*self.radius) 31 | 32 | 33 | class Square(Shape): 34 | 35 | def __init__(self,length): 36 | self.length = length 37 | 38 | def area(self): 39 | return float(self.length * self.length) 40 | 41 | def perimeter(self): 42 | return float(4 * self.length) 43 | 44 | 45 | class Rectangle(Shape): 46 | 47 | def __init__(self,length,width): 48 | self.length = length 49 | self.width = width 50 | 51 | 52 | 53 | def area(self): 54 | return float(2 * self.length * self.width) 55 | 56 | def perimeter(self): 57 | return float(2*(self.length+self.width)) 58 | 59 | 60 | class Triangle(Shape): 61 | 62 | def __init__(self,a,b,c): 63 | self.a = a 64 | self.b = b 65 | self.c = c 66 | 67 | def area(self): 68 | pass 69 | 70 | def perimeter(self): 71 | pass 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /karanprojects/sieve_of_Eratosthenes/C/cmd.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | 7 | int n = 10; 8 | int prime[n]; 9 | int sum = 0; 10 | // creating an array with True Values 11 | for (int i =0; i < n+1;i++) 12 | { 13 | prime[i] = 0; 14 | } 15 | 16 | for (int p = 2; p *p <=n;p++) 17 | { 18 | if (prime[p] == 0) 19 | { 20 | for (int i = p*p;i<=n;i+=p) 21 | { 22 | prime[i] = p; 23 | } 24 | } 25 | } 26 | 27 | for (int p = 2;p <= n;p++) 28 | { 29 | if (prime[p]== 0) 30 | { 31 | printf("%d\n",p); 32 | sum += p; 33 | } 34 | } 35 | 36 | 37 | printf("sum = %d\n",sum); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /karanprojects/sieve_of_Eratosthenes/README.md: -------------------------------------------------------------------------------- 1 | # Project 2 | ## Sieve of Eratosthenes 3 | **Tier:** 1-Beginner 4 | 5 | The sieve of Eratosthenes is one of the most efficient ways to find all of the smaller primes (below 10 million or so). 6 | 7 | ## User Stories 8 | 9 | - [x] CMD version 10 | 11 | 12 | -------------------------------------------------------------------------------- /karanprojects/sieve_of_Eratosthenes/python/cmd.py: -------------------------------------------------------------------------------- 1 | def obtaining_prime_list(n): 2 | 3 | prime = [True for i in range(n+1)] 4 | prime_number = [] 5 | p = 2 #the first prime number 6 | sum = 0 7 | while (p*p <= n ): 8 | 9 | # If prime[p] is not changed, then it is a prime xD 10 | if (prime[p]==True): 11 | #updating the multiples of p 12 | for i in range(p*p,n+1,p): 13 | prime[i]= False 14 | p += 1 15 | 16 | for p in range(2,n): 17 | if prime[p]: 18 | prime_number.append(p); 19 | sum += p 20 | return sum 21 | 22 | #print("10",obtaining_prime_list(10002)) 23 | print("2mil",obtaining_prime_list(2000000)) 24 | print("sec",obtaining_prime_list(2000001)) 25 | print("asdas",obtaining_prime_list(2000002)) 26 | -------------------------------------------------------------------------------- /karanprojects/text/C/fizzbuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | for (int i = 1; i < 101;i++) 6 | { 7 | 8 | if ((i % 5 == 0)&& (i %3 == 0)){ 9 | printf("FizzBuzz\n"); 10 | } 11 | else if (i % 5 == 0){ 12 | printf("Buzz\n"); 13 | } 14 | else if(i % 3 ==0) { 15 | printf("Fizz\n"); 16 | } 17 | else{ 18 | printf("%d\n",i); 19 | } 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /karanprojects/text/C/palindrome.c: -------------------------------------------------------------------------------- 1 | /* 2 | * palindrome(racecar) --> True 3 | */ 4 | #include 5 | #include 6 | 7 | void reverse(char *str1,char *str2) 8 | { 9 | int len1 = strlen(str1); 10 | int i,j; 11 | for (j = 0,i=len1 - 1; i >= 0; i--,j++) 12 | { 13 | str2[j] = str1[i]; 14 | } 15 | str2[j] = '\0'; 16 | 17 | } 18 | 19 | int palindrome(char str1[],char str2[]) 20 | { 21 | for (int i = 0; i < strlen(str1);i++) 22 | { 23 | if (str1[i] != str2[i]) 24 | return 1; 25 | } 26 | return 0; 27 | } 28 | 29 | int main() 30 | { 31 | char anotherword[] = "somebody once told me"; 32 | char p_word[strlen(anotherword)+1]; 33 | 34 | reverse(anotherword,p_word); 35 | if (palindrome(anotherword,p_word) == 1) 36 | { 37 | printf("%s is not a palindrome \n",anotherword); 38 | } 39 | else 40 | { 41 | printf("%s is a palindrome \n",anotherword); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /karanprojects/text/C/reverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void string_reverse(char *s,int *p) 5 | { 6 | int x = *p; 7 | while (x >= 0) 8 | { 9 | printf("%c",s[x]); 10 | x--; 11 | } 12 | printf("\n"); 13 | } 14 | 15 | void string_reverse_m2(char *str) 16 | { 17 | char *end = str + strlen(str) - 1; 18 | 19 | while (str < end) 20 | { 21 | char temp = *str; 22 | *str = *end; 23 | *end = temp; 24 | str++; 25 | end--; 26 | } 27 | } 28 | 29 | int main() 30 | { 31 | char s[] = "racecar"; 32 | char p[] = "That"; 33 | int x = sizeof(s) / sizeof(s[0]); 34 | 35 | printf("Length of String is %d\n",s[x]); 36 | string_reverse(s,&x); 37 | string_reverse_m2(p); 38 | printf("%s\n",p); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /karanprojects/text/C/vowels.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char *test_string = "the quick brown fox jumped over the fence"; // test string 6 | // vowel counters 7 | int a_counter = 0; 8 | int e_counter = 0; 9 | int i_counter = 0; 10 | int o_counter = 0; 11 | int u_counter = 0; 12 | 13 | for (int i = 0; test_string[i] != '\0';i++) 14 | { 15 | char letter = test_string[i]; 16 | switch (letter) 17 | { 18 | case 'a': 19 | case 'A': 20 | a_counter+=1; 21 | break; 22 | case 'e': 23 | case 'E': 24 | e_counter+=1; 25 | break; 26 | case 'o': 27 | case 'O': 28 | o_counter+=1; 29 | break; 30 | case 'i': 31 | case 'I': 32 | i_counter+=1; 33 | break; 34 | case 'u': 35 | case 'U': 36 | u_counter+=1; 37 | break; 38 | } 39 | } 40 | printf("String = %s\n\tconsists of a = %d , e = %d, i = %d, o = %d, u = %d\n",test_string,a_counter,e_counter,i_counter,o_counter,u_counter); 41 | return 0; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /karanprojects/text/C/words.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int word_counter(char * str1) 5 | { 6 | int space_counter = 0; 7 | for (int i =0;i < strlen(str1);i++) 8 | { 9 | if (str1[i] == ' ') 10 | { 11 | space_counter += 1; 12 | } 13 | } 14 | return space_counter + 1; 15 | } 16 | 17 | 18 | int main() 19 | { 20 | char *str1 = "This is a test string lets add another word"; 21 | 22 | int word = word_counter(str1); 23 | printf("%s \n %d words\n", str1,word); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /karanprojects/text/python/fizzbuzz.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz 3 | ''' 4 | 5 | def fizzbuzz(): 6 | for i in range(1,101): 7 | if i % 3 == 0 and i % 5 == 0: print("FizzBuzz") 8 | elif i % 5 == 0: print("Buzz") 9 | elif i % 3 == 0: print("Fizz") 10 | else: 11 | print(i) 12 | fizzbuzz() 13 | -------------------------------------------------------------------------------- /karanprojects/text/python/palindrome.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Checks if the string entered by the user is a palindrome. That is that it reads the same forwards as backwards like “racecar” 3 | ''' 4 | 5 | 6 | def palindrome(n): 7 | if n == n[::-1]: 8 | return True 9 | else: return False 10 | 11 | 12 | print(palindrome("racecar")) 13 | print(palindrome("sure")) 14 | -------------------------------------------------------------------------------- /karanprojects/text/python/reverse.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Enter a string and the program will reverse it and print it out. 3 | ''' 4 | 5 | 6 | def reverse(n): 7 | return n[::-1] 8 | 9 | 10 | 11 | try: 12 | print(reverse(str(input("Enter Word\n")))) 13 | except ValueError: 14 | print("Shame \n") 15 | -------------------------------------------------------------------------------- /karanprojects/text/python/vowels.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Enter a string and the program counts the number of vowels in the text. For added complexity have it report a sum of each vowel found. 3 | ''' 4 | 5 | def vowels(n): 6 | v = ["a","e","i","o","u"] 7 | summer = 0 8 | store_letters = [] 9 | for i in n: 10 | if i in v: 11 | store_letters.append((i,n.count(i))) 12 | summer += 1 13 | return summer,sorted(list(set(store_letters))) 14 | 15 | 16 | 17 | 18 | print(vowels("the quick brown fox jumped over a fence")) 19 | -------------------------------------------------------------------------------- /karanprojects/text/python/words.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Counts the number of individual words in a string. For added complexity read these strings in from a text file and generate a summary. 3 | ''' 4 | 5 | 6 | 7 | def words(n): 8 | print(n.split()) 9 | return len(n.split()) 10 | 11 | 12 | print(words("Counts the number of individual words in a string. For added complexity read these strings in from a text file and generate a summary.")) 13 | -------------------------------------------------------------------------------- /karanprojects/text_editor/README.md: -------------------------------------------------------------------------------- 1 | # Progress 2 | 3 |

4 | 5 |

6 | 7 | 8 | # Text Editor 9 | 10 | **Tier:** 2-Intermediate 11 | 12 | Notepad style application that can open, edit, and save text documents. Optional: Add syntax highlighting and other features. 13 | 14 | **PyQt5 is used as the GUI Framework** 15 | 16 | ## User Stories 17 | 18 | - [x] GUI Version 19 | - [x] User can save or open text files 20 | 21 | -------------------------------------------------------------------------------- /karanprojects/tiles/C/tiles.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float length_of_tile; 6 | float width_of_tile; 7 | float length_of_floor; 8 | float width_of_floor; 9 | float price_per_tile; 10 | float area; 11 | float price; 12 | 13 | printf("Enter the Length of Tile(cm)\n"); 14 | scanf("%f",&length_of_tile); 15 | printf("Enter the Width of Tile(cm)\n"); 16 | scanf("%f",&width_of_tile); 17 | printf("Enter the Length of floor(cm)\n"); 18 | scanf("%f",&length_of_floor); 19 | printf("Enter the Width of floor(cm)\n"); 20 | scanf("%f",&width_of_floor); 21 | printf("Enter the Price Per Tile\n"); 22 | scanf("%f",&price_per_tile); 23 | 24 | area = (length_of_floor * width_of_floor)/(length_of_tile*width_of_tile); 25 | price = area * price_per_tile; 26 | 27 | printf("Your Price is $%f\n",price); 28 | 29 | 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /karanprojects/tiles/README.md: -------------------------------------------------------------------------------- 1 | # Progress 2 | 3 |

4 | 5 |

6 | 7 | # Tile Calculator 8 | 9 | **Tier:** 1-Beginner 10 | 11 | Calculate the total cost of tile it would take to cover a floor plan of width and height, using a cost entered by the user. 12 | **PyQt5 is used as the GUI Framework** 13 | 14 | ## User Stories 15 | 16 | - [x] Command Line Version 17 | - [x] GUI Version 18 | - [x] User should be able to select different types of measurements (example: Inches, Feet, Centimeters) 19 | - [x] Should Display the Total cost in a user-friendly way 20 | 21 | 22 | ## Useful links and resources 23 | 24 | - [Tile Calculator / Inpiration](https://www.calculator.net/tile-calculator.html) 25 | -------------------------------------------------------------------------------- /karanprojects/unit_converter/README.md: -------------------------------------------------------------------------------- 1 | # Progress 2 | **Version 1** 3 |

4 | 5 |

6 | 7 | # Project 8 | ## Unit Converter 9 | 10 | **Tier:** 1-Beginner 11 | 12 | Converts Degrees to Radians, Kilograms to Grams 13 | 14 | -------------------------------------------------------------------------------- /projectC/README.md: -------------------------------------------------------------------------------- 1 | #### Operating Systems 2 | 3 | - [Re-Writing Shell Commands](shellcommands) 4 | 5 | #### Programming Languages 6 | 7 | - [Implementation of Datastructures](datastructures) 8 | 9 | 10 | #### Game Development 11 | 12 | - [Simple Tic Tac Toe in C](tictactoe) 13 | -------------------------------------------------------------------------------- /projectC/datastructures/README.md: -------------------------------------------------------------------------------- 1 | > contains [implementation of several datastructures](https://github.com/jwasham/coding-interview-university#data-structures) 2 | 3 | ### Table Of Content 4 | 5 | - [Arrays](arrays) 6 | - [Linked List](linkedlist) 7 | - [Stack](arrays) 8 | - [Queue](queue) 9 | - Hash table 10 | - Trees 11 | - Graphs 12 | -------------------------------------------------------------------------------- /projectC/datastructures/arrays/C++/list.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class List { 4 | private: 5 | // variables 6 | int var_capacity; // stores the capacity of the array 7 | int var_len; // stores the length of the array 8 | int *data; // pointer to array of data 9 | public: 10 | // methods 11 | List(int capacity);// constructor 12 | ~List(); // destructor 13 | void printlist(); // prints the list 14 | int size(); // return the number of items 15 | int capacity(); // return the capacity of the list 16 | bool is_empty(); // return True if the list is empty else False 17 | int at(int index); // return item at the given index 18 | void push(int data); // insert a item 19 | void insert(int index, int data); // insert item at a given index 20 | void prepend(int item); // insert item at index 0 21 | void deleteindex(int index); // remove item at the given index 22 | void removeitem(int item); // looks for value and removes item hold the value 23 | int find(int item);// returns the first index with that value -1 if not found 24 | }; 25 | -------------------------------------------------------------------------------- /projectC/datastructures/arrays/C/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H_ 2 | #define LIST_H_ 3 | 4 | // capacity for an empty list 5 | // emptylist() -> returns an pointer to 6 | // empty list 7 | int EMPTYCAPACITY=5; 8 | 9 | // struct to hold the important information 10 | // about the array like len 11 | typedef struct listinfo{ 12 | // stores the current length of list 13 | int len; 14 | // stores the maximum capacity of the list 15 | int maxCapacity; 16 | // stores the pointer to the list 17 | int *data; 18 | } listinfo; 19 | 20 | // forward declartion of the functions 21 | // creates an empty list 22 | listinfo * createEmptyList(); 23 | // create an list with given data 24 | listinfo * createList(int size); 25 | // appends data to the list 26 | void appendData(listinfo * templist, int data); 27 | // prints the list 28 | void printlist(listinfo * templist); 29 | // return size of the list 30 | int size(listinfo *templist); 31 | // return capacity of the list 32 | int capacity(listinfo *templist); 33 | // return if the list empty or not 34 | int is_empty(listinfo *templist); 35 | // insert item at index, shifts that index's value 36 | // and trailing elements to the right 37 | void insert(listinfo *templist, int data, int index); 38 | // return end value from the list 39 | int pop(listinfo *templist); 40 | // delete item at the index, shift all trailing elements 41 | // left 42 | void deleteitem(listinfo *templist, int index); 43 | // looks for value and removes index holding it (even if in multiple places) 44 | void removeitem(listinfo *templist, int data); 45 | //looks for value and returns first index with that value, -1 if not found 46 | int finditem(listinfo *templist, int item); 47 | 48 | #endif // LIST_H_ 49 | -------------------------------------------------------------------------------- /projectC/datastructures/arrays/C/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "list.c" 5 | 6 | 7 | int main(int argc, char *argv[]){ 8 | 9 | int n = 5; 10 | time_t t; 11 | srand((unsigned) time(&t)); 12 | 13 | // creating a list with argc values 14 | listinfo * list = createList(n); 15 | 16 | printf("----------------------------\n"); 17 | printf("checking if the list is empty\n"); 18 | // checking if the list is empty 19 | if (is_empty(list)){ 20 | printf("List is Not Empty\n"); 21 | }else{ 22 | printf("List is Empty\n"); 23 | } 24 | 25 | printf("----------------------------\n"); 26 | printf("allocating random numbers to the list\n"); 27 | // allocating random numbers 28 | for (int i = 0; i < n; i++){ 29 | int randomnumber = rand() % 50; 30 | allocateData(list,randomnumber,i); 31 | } 32 | 33 | // checking the capacity of list, this should be n 34 | printf("----------------------------\n"); 35 | printf("checking capacity of the list\n"); 36 | printf("capacity of the list is %d; n = %d\n", capacity(list), n); 37 | 38 | // appending an element to the list and checking its 39 | // capacity, now it should be n + 1 40 | appendData(list, 75); 41 | printf("----------------------------\n"); 42 | printf("checking capacity of the list\n"); 43 | printf("capacity of the list is %d; n + 1 = %d\n", capacity(list), n + 1); 44 | 45 | // checking the length of the list, this should be n + 1 46 | printf("----------------------------\n"); 47 | printf("checking length of the list\n"); 48 | printf("length of the list is %d; n + 1 = %d\n", size(list), n + 1); 49 | 50 | // removing the appended item 51 | printf("----------------------------\n"); 52 | printf("remove an appended item\n"); 53 | // finding the index of the 75 54 | deleteitem(list, n); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /projectC/datastructures/arrays/README.md: -------------------------------------------------------------------------------- 1 | Idea is from [jwasham's](https://github.com/jwasham/coding-interview-university#arrays) coding uni repository. 2 | 3 | --- 4 | #### Implementation of a list using [C](C) & [C++](C++) 5 | 6 | - [x] Implement a vector (mutable array with automatic resizing): 7 | - [x] `size()` - number of items 8 | - [x] `capacity()` - number of items it can hold 9 | - [x] `is_empty()` 10 | - [x] `at(index)` - returns item at given index, blows up if index out of bounds 11 | - [x] `push(item)` 12 | - [x] `insert(index, item)` - inserts item at index, shifts that index's value and trailing elements to the right 13 | - [x] `prepend(item)` - can use insert above at index 0 14 | - [x] `pop()` - remove from end, return value 15 | - [x] `delete(index)` - delete item at index, shifting all trailing elements left 16 | - [x] `remove(item)` - looks for value and removes index holding it (even if in multiple places) 17 | - [x] `find(item)` - looks for value and returns first index with that value, -1 if not found 18 | -------------------------------------------------------------------------------- /projectC/datastructures/linkedlist/C++/linkedlist.h: -------------------------------------------------------------------------------- 1 | #ifndef LINKEDLIST_H_ 2 | #define LINKEDLIST_H_ 3 | 4 | 5 | class node{ 6 | public: // variables 7 | int index; 8 | int data; 9 | node * next; // points to the next node 10 | public: // method 11 | node(int data, int index); // create a node 12 | }; 13 | 14 | class LinkedList{ 15 | public: // variables 16 | node * headptr; 17 | node * tailptr; 18 | public: // methods 19 | LinkedList(); 20 | //~LinkedList(); 21 | int size(); // returns the number of elements in the array 22 | int isEmpty(); // return 1 if the List is empty else return -1 23 | int value_at(int index); // returns the value of the nth item (starting at 0 for first) 24 | void push_front(LinkedList list, int value);// adds an item to the front of the list 25 | int pop_front();// remove front item and return its value 26 | void push_back(int value);// adds an item at the end 27 | int pop_back();// removes end item and returns its value 28 | int front(); // get value of front item 29 | int back(); // get value of end item 30 | void insert(int index, int value); //insert value at index 31 | void erase(int index); // removes node at given index 32 | void value_n_from_end(int n);// returns the value of the node at nth position from the end of the list 33 | void reverse(); // reverses the list 34 | void remove_value(int value); // removes the first item in the list with this value 35 | void print(LinkedList list); // prints the list 36 | }; 37 | #endif //LINKEDLIST_H_ -------------------------------------------------------------------------------- /projectC/datastructures/linkedlist/C/linkedlist.h: -------------------------------------------------------------------------------- 1 | #ifndef LINKEDLIST_H_ 2 | #define LINKEDLIST_H_ 3 | 4 | // struct for a node in a 5 | // linked list 6 | typedef struct node { 7 | int index; 8 | int data; 9 | struct node * next; 10 | } node; 11 | 12 | 13 | node * createnode(int data, int index); // returns a structure 14 | int size(node* head); // returns the number of elements in the array 15 | int isEmpty(node* head); // return 1 if the List is empty else return -1 16 | int value_at(node* head, int index); // returns the value of the nth item (starting at 0 for first) 17 | void push_front(int value);// adds an item to the front of the list 18 | int pop_front();// remove front item and return its value 19 | void push_back(int value);// adds an item at the end 20 | int pop_back();// removes end item and returns its value 21 | int front(); // get value of front item 22 | int back(); // get value of end item 23 | void insert(int index, int value); //insert value at index 24 | void erase(int index); // removes node at given index 25 | void value_n_from_end(int n);// returns the value of the node at nth position from the end of the list 26 | void reverse(); // reverses the list 27 | void remove_value(int value); // removes the first item in the list with this value 28 | void print(); // prints the list 29 | 30 | 31 | #endif //LINKEDLIST_H_ 32 | -------------------------------------------------------------------------------- /projectC/datastructures/linkedlist/C/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "linkedlist.c" 4 | 5 | int main(){ 6 | puts("---------------------------------"); 7 | puts("creating an linked list"); 8 | for (int i = 23; i < 35; i++){ 9 | push_front(i); 10 | } 11 | // printing the linked list 12 | print(); 13 | puts("---------------------------------"); 14 | puts("testing pop_front & pop_back"); 15 | int front = pop_front(); 16 | printf("Output from pop_front() -> %d\n", front); 17 | printf("Output should be -> %d\n", 34); 18 | int back = pop_back(); 19 | printf("Output from pop_back() -> %d\n", back); 20 | printf("Output should be -> %d\n", 23); 21 | puts("---------------------------------"); 22 | return 0; 23 | } 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /projectC/datastructures/linkedlist/README.md: -------------------------------------------------------------------------------- 1 | Idea is from [jwasham's](https://github.com/jwasham/coding-interview-university#linked-lists) coding uni repository. 2 | 3 | --- 4 | 5 | Implementation using [C Implementation](C) and [C++ implementation](C++) 6 | 7 | for C++, I will be using classes to implement the node. 8 | 9 | - [x] `size()` - returns number of data elements in list 10 | - [x] `empty()` - bool returns true if empty 11 | - [x] `value_at(index)` - returns the value of the nth item (starting at 0 for first) 12 | - [x] `push_front(value)` - adds an item to the front of the list 13 | - [x] `pop_front()` - remove front item and return its value 14 | - [x] `push_back(value)` - adds an item at the end 15 | - [x] `pop_back()` - removes end item and returns its value 16 | - [x] `front()` - get value of front item 17 | - [x] `back()` - get value of end item 18 | - [x] `insert(index, value)` - insert value at index, so current item at that index is pointed to by new item at index 19 | - [x] `erase(index)` - removes node at given index 20 | - [x] `value_n_from_end(n)` - returns the value of the node at nth position from the end of the list 21 | - [x] `reverse()` - reverses the list 22 | - [x] `remove_value(value)` - removes the first item in the list with this value 23 | -------------------------------------------------------------------------------- /projectC/datastructures/queue/C_ARRAYS/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_H 2 | #define QUEUE_H 3 | 4 | 5 | void intializeArray(int ***arr, int size); // returns double int pointer to an array with pre-allocated size 6 | void enqueue(int **arr, int value, int size); // add data to the rear of the array 7 | 8 | 9 | 10 | 11 | #endif //QUEUE_H 12 | -------------------------------------------------------------------------------- /projectC/datastructures/queue/C_LL/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_H 2 | #define QUEUE_H 3 | 4 | // struct for a node in a 5 | // linked list 6 | typedef struct node { 7 | int index; 8 | int data; 9 | struct node * next; 10 | } node; 11 | 12 | node * createnode(int data, int index); // returns a structure 13 | int empty(); // return 1 if the List is empty else return -1 14 | int dequeue();// remove front item and return its value 15 | void enqueue(int value);// adds an item at the end 16 | 17 | #endif //QUEUE_H 18 | -------------------------------------------------------------------------------- /projectC/datastructures/queue/Cplus_LL/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_H 2 | #define QUEUE_H 3 | 4 | class node { 5 | public: // variables 6 | int index; 7 | int data; 8 | node * next; 9 | public: // methods 10 | // creates a node object 11 | node(int data, int index); 12 | }; 13 | 14 | class LinkedList{ 15 | public: // variables 16 | node * headptr; 17 | node * tailptr; 18 | public: // methods 19 | // constructor 20 | LinkedList(); 21 | // destructor 22 | // ~LinkedList(); 23 | int empty(); // return 1 if the list is empty else -1 24 | int dequeue(); // remove front item and returns its value 25 | void enqueue(LinkedList list,int value); // add an item at the end 26 | void print(LinkedList list); // prints the linked list 27 | }; 28 | 29 | #endif // QUEUE_H -------------------------------------------------------------------------------- /projectC/datastructures/queue/README.md: -------------------------------------------------------------------------------- 1 | Idea is from [jwasham's](https://github.com/jwasham/coding-interview-university#queue) coding uni repository. 2 | 3 | --- 4 | #### Implementation of a queue using Linked List: [C](C_LL) & [C++](Cplus_LL) 5 | 6 | - [x] Implement using linked-list, with tail pointer: 7 | - [x] enqueue(value) - adds value at position at tail 8 | - [x] dequeue() - returns value and removes least recently added element (front) 9 | - [x] empty() 10 | 11 | #### Implementation of a queue using Arrays: [C](C_ARRAY) 12 | 13 | - [x] Implement using fixed-sized array: 14 | - [x] enqueue(value) - adds item at end of available storage 15 | - [x] dequeue() - returns value and removes least recently added element 16 | - [ ] empty() 17 | -------------------------------------------------------------------------------- /projectC/shellcommands/README.md: -------------------------------------------------------------------------------- 1 | This folder contains implementation of several shell commands found in linux. 2 | 3 | #### Shell Commands 4 | - [cat](cat.c) 5 | - [echo](echo.c) 6 | - [ls](ls.c) 7 | -------------------------------------------------------------------------------- /projectC/shellcommands/cat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation of Cat shell command 3 | * 4 | * Display content inside a given file 5 | */ 6 | #include 7 | #include 8 | 9 | #define BUFFER 1024 10 | 11 | int main(int argc, char **argv){ 12 | 13 | // if no files names are given 14 | // exit the program 15 | if (argc != 2){ 16 | exit(0); 17 | } 18 | 19 | FILE *fp; // file pointer 20 | char buffer[BUFFER]; 21 | size_t read; 22 | 23 | // opening the file using fopen() 24 | fp = fopen(argv[1],"r"); 25 | // check if the file exists 26 | if (fp == NULL){ 27 | fprintf(stderr, "File Not Found"); 28 | exit(-1); 29 | }else { 30 | char c; 31 | while ((read = fread(buffer, 1 , sizeof(buffer), fp)) > 0){ 32 | fwrite(buffer, 1 , read, stdout); 33 | } 34 | fclose(fp); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projectC/shellcommands/echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation of Echo shell command 3 | * 4 | * Display a line of text 5 | */ 6 | #include 7 | #include 8 | 9 | 10 | int main(int argc, char **argv){ 11 | 12 | int count = argc - 1; 13 | int i = 1; 14 | while (count >= i){ 15 | printf("%s",argv[i]); 16 | i++; 17 | } 18 | printf("\n"); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /projectC/shellcommands/ls.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation of ls command 3 | */ 4 | #include 5 | #include 6 | 7 | 8 | int main() { 9 | 10 | // pointer to store the file 11 | // return 0 if success , -1 if there 12 | // is an error 13 | DIR *folder; 14 | 15 | struct dirent *directoryContent; 16 | 17 | folder = opendir("."); 18 | 19 | if (folder == NULL){ 20 | printf("cannot open directory\n"); 21 | return 1; 22 | } 23 | 24 | while (directoryContent = readdir(folder)) { 25 | printf("%s ",directoryContent->d_name); 26 | } 27 | printf("\n"); 28 | // closing the directory 29 | closedir(folder); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /projectC/tictactoe/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-g -Wall -O3 2 | LDLIBS=-lSDL2 3 | CC=c99 4 | SRC=src 5 | 6 | make main: 7 | $(CC) $(SRC)/$@.c -o $@ $(LDLIBS) $(CFLAGS) 8 | -------------------------------------------------------------------------------- /projectC/tictactoe/README.md: -------------------------------------------------------------------------------- 1 | >a simple tic tac toe game, the project is done with the help of the following [youtube video](https://www.youtube.com/watch?v=gCVMkKgs3uQ). The goal of the project is to be familiar with SDL. The goal of the above video is to understand the difference between procedural programming and functional programming. 2 | 3 | --- 4 | 5 | ### Usage 6 | 7 | 8 | 9 | 10 | 11 | ### Resources 12 | 13 | - [my notes](notes.md) 14 | - [video #1](https://www.youtube.com/watch?v=gCVMkKgs3uQ) 15 | - [video #2](https://www.youtube.com/watch?v=VxLvaHpAK-U) 16 | -------------------------------------------------------------------------------- /projectC/tictactoe/src/game.h: -------------------------------------------------------------------------------- 1 | #ifndef GAME_H_ 2 | #define GAME_H_ 3 | 4 | // board size 5 | #define N 3 6 | // screen width and height 7 | #define SCREEN_WIDTH 640 8 | #define SCREEN_HEIGHT 480 9 | 10 | // players 11 | #define EMPTY 0 12 | #define PLAYER_X 1 13 | #define PLAYER_O 2 14 | 15 | // game states 16 | #define RUNNING_STATE 0 17 | #define PLAYER_X_WON_STATE 1 18 | #define PLAYER_O_WON_STATE 2 19 | #define TIE_STATE 3 20 | #define QUIT_STATE 4 21 | 22 | // state of the game 23 | typedef struct { 24 | int board[N * N]; 25 | int player; 26 | int state; 27 | } game_t; 28 | 29 | #endif //GAME_H_ 30 | -------------------------------------------------------------------------------- /projectC/tictactoe/src/logic.c: -------------------------------------------------------------------------------- 1 | #include "logic.h" 2 | #include "game.h" 3 | 4 | void click_on_cell(game_t *game, int row, int column){ 5 | 6 | } 7 | -------------------------------------------------------------------------------- /projectC/tictactoe/src/logic.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGIC_H_ 2 | #define LOGIC_H_ 3 | 4 | void click_on_cell(game_t *game, int row, int column); 5 | 6 | #endif // LOGIC_H_ 7 | -------------------------------------------------------------------------------- /projectC/tictactoe/src/rendering.c: -------------------------------------------------------------------------------- 1 | #include "rendering.h" 2 | #include "game.h" 3 | #include "SDL2/SDL.h" 4 | 5 | void render_game(SDL_Renderer *renderer, const game_t *game){ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /projectC/tictactoe/src/rendering.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERING_H_ 2 | #define RENDERING_H_ 3 | 4 | void render_game(SDL_Renderer *renderer, const game_t *game); 5 | 6 | #endif // RENDERING_H_ 7 | -------------------------------------------------------------------------------- /researchpapers/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/Makefile -------------------------------------------------------------------------------- /researchpapers/code/BTree/btree.c: -------------------------------------------------------------------------------- 1 | #include "btree.h" -------------------------------------------------------------------------------- /researchpapers/code/MakingDataStructuresPersistent/fatnode.c: -------------------------------------------------------------------------------- 1 | #include "fatnode.h" -------------------------------------------------------------------------------- /researchpapers/code/MakingDataStructuresPersistent/nodecopying.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file contains an implementation of node-copying 3 | from the paper making data structures persistent; This 4 | is an implementation of partial persistent of data structures 5 | */ 6 | #ifndef NODECOPYING_H 7 | #define NODECOPYING_H 8 | 9 | int d = 5; // maximum number of pointers in an ephemeral node 10 | int p = 5; // maximum number of predecessors of an ephemeral node 11 | 12 | 13 | typedef struct ephnode { 14 | // information fields 15 | float data; // data point 16 | int version; // version of structure 17 | } ephemeralnode; 18 | 19 | typedef struct pernode { 20 | // information fields 21 | float data; 22 | int eph_version; 23 | int per_version; 24 | // pointer information 25 | ephemeralnode* orgpointer[d]; // contains original pointers 26 | ephemeralnode* prepointer[p]; // contains predecessor pointers 27 | } persistentnode; 28 | 29 | typedef struct perstruct { 30 | persistentnode* node; 31 | persistentnode* nextnode; 32 | } persistentstruct; 33 | 34 | typedef struct ephstruct { 35 | ephemeralnode* node; 36 | persistentstruct* family; 37 | } ephemeralstruct; 38 | 39 | #endif // !NODECOPYING_H 40 | -------------------------------------------------------------------------------- /researchpapers/code/RTree/rtree.c: -------------------------------------------------------------------------------- 1 | #include "rtree.h" -------------------------------------------------------------------------------- /researchpapers/other/.images/btree/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/other/.images/btree/tree.png -------------------------------------------------------------------------------- /researchpapers/other/.images/rtree/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/other/.images/rtree/img1.png -------------------------------------------------------------------------------- /researchpapers/other/.images/rtree/img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/other/.images/rtree/img2.png -------------------------------------------------------------------------------- /researchpapers/other/.images/rtree/scene1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/other/.images/rtree/scene1.png -------------------------------------------------------------------------------- /researchpapers/other/.images/rtree/scene2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/other/.images/rtree/scene2.png -------------------------------------------------------------------------------- /researchpapers/other/.images/rtree/scene3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/other/.images/rtree/scene3.png -------------------------------------------------------------------------------- /researchpapers/other/smarteratomicsmartpointers.md: -------------------------------------------------------------------------------- 1 | This file contains is a summary on the video on [**Smarter `Cpp` Atomic Smart Pointers** by Daniel Anderson `cppcon`](https://www.youtube.com/watch?v=OS7Asaa6zmY) 2 | 3 | --- 4 | 5 | ### The Concurrent Memory Management Problem 6 | 7 | **A thread might want to delete something that another thread is still reading**; We 8 | -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/definition1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/definition1.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/definition1_mindist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/definition1_mindist.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/edeqn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/edeqn.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/edsamplecalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/edsamplecalc.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/examplepoints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/examplepoints.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/manhattan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/manhattan.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/regressiongraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/regressiongraph.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/regressiongraph2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/regressiongraph2.png -------------------------------------------------------------------------------- /researchpapers/papers/.images/nearestneighbours/samplegraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/.images/nearestneighbours/samplegraph.png -------------------------------------------------------------------------------- /researchpapers/papers/nearestneighbor.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kana800/playground/72d654809810b6f35023f07599f32ce98ef83402/researchpapers/papers/nearestneighbor.md -------------------------------------------------------------------------------- /researchpapers/tests/README.md: -------------------------------------------------------------------------------- 1 | ### Testing 2 | 3 | - [btree]() 4 | - [persistent data structures]() 5 | - [rtree]() 6 | --------------------------------------------------------------------------------