From c395899009b26ac54f581fa5485689fa8bacd457 Mon Sep 17 00:00:00 2001 From: sweatshirt0 Date: Thu, 23 Feb 2023 15:23:38 -0500 Subject: [PATCH] first push --- assoc.lisp | 7 +++ bubblesort.lisp | 28 +++++++++++ convo.lisp | 23 +++++++++ lisp.lisp | 18 +++++++ loginv1.lisp | 18 +++++++ loginv2.lisp | 20 ++++++++ loginv3.lisp | 33 +++++++++++++ loop-practice.lisp | 13 +++++ pe1.lisp | 8 ++++ pe3.lisp | 10 ++++ tes.lisp | 13 +++++ text-gamev1.lisp | 39 +++++++++++++++ webserver.lisp | 116 +++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 346 insertions(+) create mode 100644 assoc.lisp create mode 100644 bubblesort.lisp create mode 100644 convo.lisp create mode 100644 lisp.lisp create mode 100644 loginv1.lisp create mode 100644 loginv2.lisp create mode 100644 loginv3.lisp create mode 100644 loop-practice.lisp create mode 100644 pe1.lisp create mode 100644 pe3.lisp create mode 100644 tes.lisp create mode 100644 text-gamev1.lisp create mode 100644 webserver.lisp diff --git a/assoc.lisp b/assoc.lisp new file mode 100644 index 0000000..bbb5a73 --- /dev/null +++ b/assoc.lisp @@ -0,0 +1,7 @@ +(setq *print-case* :downcase) + +(defparameter *accounts* + '((Admin (sweatshirt)) + (User1 (samsepi0l)))) + +(format t "Admin data: ~a ~%" (assoc 'admin *accounts*)) diff --git a/bubblesort.lisp b/bubblesort.lisp new file mode 100644 index 0000000..f1c97ef --- /dev/null +++ b/bubblesort.lisp @@ -0,0 +1,28 @@ +(setq *print-case* :downcase) + +(defvar li (list 4 8 9 2 1)) + +(defvar array nil) + +(push li array) + +(defparameter inc 1) + +(defvar next (nth inc li)) + +(dolist (el li) + (if (> el next) + (progn + (defparameter tmp el) + (setq el next) + (setq next tmp) + (setq inc (+ inc 1)) + (if (< (nth (- inc 2) li) el)) + (push el array)) + (progn + (setq inc (+ inc 1)) + (push next array))) + (format t "~a~%" array)) + + +(format t "~a" li) diff --git a/convo.lisp b/convo.lisp new file mode 100644 index 0000000..3e5248e --- /dev/null +++ b/convo.lisp @@ -0,0 +1,23 @@ +(setq *print-case* :downcase) + +(format t "Hello there, what is your name? ~%") +(defvar *name* (read)) + +(defun greetings (name) + (format t "Nice to meet you ~a, i'm emacs. ! ~%" name) + (format t "How is your day? ~%") + (defvar how (read)) + (defparameter good 'good) + (defparameter bad 'bad) + + (if (eq how good) + (progn + (format t "I'm glad to hear that your day was ~a, ~a! ~%" how name) + (format t "I hope you continue to have a ~a day! Till next time! ~%" how))) + (if (eq how bad) + (progn + (format t "I'm sorry to hear that your day was ~a, ~a... ~%" how name) + (format t "I hope your day is better next time, ~a. ~%" name))) + (format t "That's interesting to hear, ~a. Let's aim for a good day next time! ~%" name)) + +(greetings *name*) diff --git a/lisp.lisp b/lisp.lisp new file mode 100644 index 0000000..6fcbb89 --- /dev/null +++ b/lisp.lisp @@ -0,0 +1,18 @@ +(setq *print-case* :downcase) + +(format t "Whats your name? ~%") + +(defvar *name* (read)) + +(defun greetings (name) + (format t "It's nice to meet you, ~a, I'm emacs. ~%" name) + (format t "How are you, ~a? ~%" name) + (defparameter good 'good) + (defvar how (read)) + (if (eq how good) + (progn + (format t "I'm glad to hear you are ~a! ~%" how) + (format t "Have a great rest of your day, ~a!" name)) + (format t "just because your day was ~a now doesn't mean it will be ~a forever! ~%" how how))) + +(greetings *name*) diff --git a/loginv1.lisp b/loginv1.lisp new file mode 100644 index 0000000..34baaee --- /dev/null +++ b/loginv1.lisp @@ -0,0 +1,18 @@ +(setq *print-case* :downcase) + +(format t "Enter your username: ") +(defvar *username* (read)) +(format t "Enter your password: ") +(defvar *password* (read)) + +(setq use 'sweatshirt) +(setq pass 'Daemons0!) + +(defun varify (username password) + (if (and (eq username use) (eq password pass)) + (progn + (format t "Thank you for logging in, ~a! ~%" username) + (format t "Will check again soon! ~%")) + (format t "You are not authorized to use this device, ~a." username))) + +(varify *username* *password*) diff --git a/loginv2.lisp b/loginv2.lisp new file mode 100644 index 0000000..cb092fe --- /dev/null +++ b/loginv2.lisp @@ -0,0 +1,20 @@ +(setq *print-case* :downcase) + +(format t "Username: ") +(defvar *username* (read)) +(format t "Password: ") +(defvar *password* (read)) + +(defvar *user* "sweatshirt") +(defvar *pass* "Daemons0!") + +(defparameter *accounts* (list :key 1 :username 'sweatshirt :password 'Daemons0!)) + +(defparameter user (getf *accounts* :username)) +(defparameter pass (getf *accounts* :password)) + + +(if (and (eq *username* user) (eq *password* pass)) + (progn + (format t "You are now logged in as, ~a" *username*)) + (format t "Something went wrong.")) diff --git a/loginv3.lisp b/loginv3.lisp new file mode 100644 index 0000000..9bd2a41 --- /dev/null +++ b/loginv3.lisp @@ -0,0 +1,33 @@ +(setq *print-case* :downcase) + +(format t "Username: ") +(defvar *username* (read)) +(format t "Password: ") +(defvar *password* (read)) + + +(defparameter *accounts* nil) + +(defvar admin1 (list :username 'sweatshirt :password 'Daemons0!)) +(defvar user1 (list :username 'samsepi0l :password 'Daemons)) +(defvar user2 (list :username 'mogad0n :password 'something)) + +(push admin1 *accounts*) +(push user1 *accounts*) +(push user2 *accounts*) + +(defparameter varify 'false) +(defparameter inc 0) + +(dolist (acc *accounts*) + (defparameter check1 (getf (nth inc *accounts*) :username)) + (defparameter check2 (getf (nth inc *accounts*) :password)) + (if (and (equalp *username* check1) (equalp *password* check2)) + (setq varify 'true) + (progn + (setq inc (+ inc 1))))) + +(if (equalp varify 'true) + (progn + (format t "Thank you so much for logging in, ~a~%" *username*)) + (format t "try again~%")) diff --git a/loop-practice.lisp b/loop-practice.lisp new file mode 100644 index 0000000..e2d013c --- /dev/null +++ b/loop-practice.lisp @@ -0,0 +1,13 @@ +(defvar *print-case* :downcase) + +(defvar admin (list :username "sweatshirt" :password "Daemons0!")) + +(defvar *accounts* nil) + +(push admin *accounts*) + +(dolist (account *accounts*) + (format t "~{ ~a : ~a ~}~%" account) + (if (and (member "sweatshirt" account) (member "Daemons0!" account)) + (progn + (format t "Fact.~%")))) diff --git a/pe1.lisp b/pe1.lisp new file mode 100644 index 0000000..504cd40 --- /dev/null +++ b/pe1.lisp @@ -0,0 +1,8 @@ + +(defvar *sum* 0) + +(loop for x from 1 to 999 do + (if (or (zerop(mod x 3)) (zerop (mod x 5))) + (progn + (setq *sum* (+ *sum* x))))) +(format t "~d ~%" *sum*) diff --git a/pe3.lisp b/pe3.lisp new file mode 100644 index 0000000..405a134 --- /dev/null +++ b/pe3.lisp @@ -0,0 +1,10 @@ +(defvar div 2) +(defvar num 317584931803) + +(loop + (if (zerop(mod num div)) + (progn + (setq num (/ num div)) + (setq div (- div 1))) + (setq div (+ div 1))) + (when (< num 1) (return div))) diff --git a/tes.lisp b/tes.lisp new file mode 100644 index 0000000..37bfd80 --- /dev/null +++ b/tes.lisp @@ -0,0 +1,13 @@ +(setq *print-case* :downcase) + +(format t "Username: ") +(defvar *username* (read)) +(format t "Password: ") +(defvar *password* (read)) + +(defparameter tes1 'sweatshirt) +(defparameter tes2 'Daemons0!) + +(terpri) + +(format t "~a~%" (equalp tes1 *username*)) diff --git a/text-gamev1.lisp b/text-gamev1.lisp new file mode 100644 index 0000000..29a9c6c --- /dev/null +++ b/text-gamev1.lisp @@ -0,0 +1,39 @@ +(setq *print-case* :downcase) + +(defvar *username* nil) +(defvar *password* nil) +(defvar *new-username* nil) +(defvar *new-password* nil) + +(defparameter *accounts* nil) + +(defvar inc 0) + + +(loop (setq cm (read)) + (if (eq cm 'q) + (return)) + + (if (eq cm 'create) + (progn + (format t "New Username: ") + (setq *new-username* (read)) + (format t "New password: ") + (setq *new-password* (read)) + (push (list :username *new-username* :password *new-password*) *accounts*) + )) + + (if (eq cm 'login) + (progn + (format t "Username: ") + (setq *username* (read)) + (format t "Password: ") + (setq *password* (read)) + (dolist (acc *accounts*) + (defparameter check1 (getf (nth inc *accounts*) :username)) + (defparameter check2 (getf (nth inc *accounts*) :password)) + (if (and (equalp *username* check1) (equalp *password* check2)) + (progn + (format t "Thank you for logging in, ~a~%" *username*) + (format t "~a is now ready to play!~%" *username*)) + (format t "please type to create an account. Otherwise, enter some valid information.")))))) diff --git a/webserver.lisp b/webserver.lisp new file mode 100644 index 0000000..905d512 --- /dev/null +++ b/webserver.lisp @@ -0,0 +1,116 @@ +(defparameter *server* (make-instance 'tbnl:easy-acceptor + :port 33333 + :address "0.0.0.0")) +(defun start () + (tbnl:start *server*)) + +(defun stop() + (tbnl:stop *server*)) + +(defparameter *css* + "body { + background: #f0f2f5; + font-family: monospace; + } + .nav-wrapper { + background-color: blue; + padding: 15px; + } + .form-wrapper { + position: relative; + top: 55px; + padding: 15px 10px; + background-color: #fff; + width: 400px; + border-radius: 5px; + box-shadow: 8px 8px 8px lightgrey; + } + .username { + position: relative; + display: flex; + margin-left: auto; + margin-right: auto; + border: 1px solid lightgrey; + border-radius: 5px; + padding: 15px; + font-size: 1.2rem; + width: 95%; + } + .password { + position: relative; + display: flex; + margin-left: auto; + margin-right: auto; + border: 1px solid lightgrey; + border-radius: 5px; + padding: 15px; + font-size: 1.2rem; + width: 95%; +} + .nav-wrapper a { + margin-left: 15px; + margin-right: 15px; + text-decoration: none; + font-size: 1rem; + color: #fff; + } + .nav-wrapper a:hover { + cursor: pointer; + text-decoration: underline; + } + .title-wrapper { + display: flex; + justify-content: center; + } + .content { + font-size: 1.1rem; + }") + +(tbnl:define-easy-handler (main :uri "/") + () + (spinneret:with-html-string + (:html + (:head + (:style + *css*)) + (:body + (:div :class "whole-wrapper" + (:div :class "nav-wrapper" + (:a :class "home-link" :href "/" + "Home") + (:a :class "about-link" :href "/about" + "About")) + (:div :class "title-wrapper" + (:h1 :class "title" + "Welcome to my CL server!")) + (:div :class "form-wrapper" + (:form :class "login" :action "/members" :method "POST" + (:input :type "text" :class "username" :name "username" :placeholder "Username") + (:br)(:br) + (:input :type "password" :class "password" :name "password" :placeholder "Password")))))))) + +(tbnl:define-easy-handler (about :uri "/about") + () + (spinneret:with-html-string + (:html + (:head + (:style + *css*)) + (:body + (:div :class "whole-wrapper" + (:div :class "nav-wrapper" + (:a :class "home-link" :href "/" + "Home") + (:a :class "about-link" :href "/about" + "About")) + (:div :class "content-wrapper" + (:div :clsas "about-title-wrapper" + (:h1 "About this site")) + (:div :class "content-wrapper" + (:p :class "content" + "I am an intermediate programmer who is new-ish to common assoc.lisp + and am loving it so far! So much so that I have decided to practice + making a webserver; though i usually do this with node js, handling + request with response, i decided to do the same with common lisp! + I will be using hunchentoot, spinneret and lass(maybe?) to create + this site; I hope you enjoy :)"))))))))