Skip to content

Instantly share code, notes, and snippets.

View juan-reynoso's full-sized avatar
🏠
Working from home

Juan Reynoso juan-reynoso

🏠
Working from home
View GitHub Profile
@juan-reynoso
juan-reynoso / apply
Last active October 6, 2020 14:56
Common lisp apply
;;Example:
;; 2 + 2 + 2
(apply '+ '(2 2 2))
6
(defparameter *spam* "million")
(defparameter *emails* '("Reset your password"
"Happy birthday"
"Collect your million dollars now!"))
(defun spam-filter (emails spam)
"Filter emails and returns a list with good-emails and spam-emails"
(let ((spam-emails nil)
(good-emails nil))
(defentry-point "form.html" (:application *ucw-hello-world-app*)
()
;; display the window component
(call-as-window 'main-window
:title "Bootstrap form"
:body (make-instance 'bootstrap-form)))
(defcomponent bootstrap-form ()
())
# Programación orientada a objetos
# Definimos la clase llamada Dog con dos atributos y un método
class Dog:
# __init__ funcion que inicializa los valores de las propiedades del objeto
def __init__ (self, name, age):
# definimos los atributos
# se define la propiedad llamada name y se inicializa con el valor del parámetro
# propiedad parámetro
@juan-reynoso
juan-reynoso / Restarts in Common Lisp
Last active July 7, 2021 21:43
Restarts, interactive choices in the debugger
(define-condition odd-number-error (error)
((message :initarg :message :reader message))
(:report (lambda (condition stream)
(format stream "Ups! we have an error. ~%~a" (message condition))))
(:documentation "Custom error when we encounter a odd number error."))
(defun filter-oddp (sequence)
"Iterates over the elememets of the sequence and display
the odd number, and otherwise invoke a condition."
(dolist (x sequence)
@juan-reynoso
juan-reynoso / Common Lisp local-time
Created July 7, 2021 21:49
Some examples: local-time
(in-package #:local-time)
(defun get-previous-day (&key (timestamp (now)))
"Returns the timestamp of the previous day of the timestamp"
(adjust-timestamp timestamp (offset :day -1)))
(defun get-next-day (&key (timestamp (now)))
"Returns the timestamp of the next day of the timestamp"
(adjust-timestamp timestamp (offset :day 1)))
@juan-reynoso
juan-reynoso / get-timestamp-data.lisp
Created September 27, 2021 16:10
Returns a list with weekday, day, month, year and total days of the month of local-time object
(defun get-timestamp-data (timestamp)
"Returns a list with weekday, day, month, year and total days of the month.
*ISO compatible weekday number (monday=1, sunday=7)
*day of month
*numeric month
*year
*numeric total-days-of-month"
(let ((day-of-week nil)
(day nil)
(month nil)
@juan-reynoso
juan-reynoso / get-long-weekday-from-timestamp.lisp
Created September 28, 2021 15:10
Returns a string which is the weekday
(defun get-long-weekday-from-timestamp (&key (timestamp (now)))
"Returns a string which is the weekday."
(let ((long-weekday (format-timestring nil
timestamp
:format '(:long-weekday))))
long-weekday))
@juan-reynoso
juan-reynoso / date-compare.lisp
Created September 29, 2021 15:00
Compare dates
(defun date-compare (time-a time-b)
"Returns the symbols <, >, or =, describing the relationship between TIME-A and TIME-B."
(declare (type timestamp time-a time-b))
(cond
((< (day-of time-a) (day-of time-b)) '<)
((> (day-of time-a) (day-of time-b)) '>)
(t '=)))
(defun date= (time-a time-b)
"Return T if date of TIME-A is equal to date of TIME-B, NIL otherwise."
@juan-reynoso
juan-reynoso / lisps-sql.lisp
Last active June 22, 2022 22:55
Lisp s-sql with postmodern
(in-package #:pomo)
(defvar *db-spec* '("my_database" "my_user" "ultra-secret-password" "localhost" :POOLED-P T)
"Information about the connection of the database.")
(defmacro with-database-connection (&body query)
"The connection pooler.
This macro establish the connection with specified database in *db-parameter* variable and execute the QUERY.
IN: query that representing the users' query
OUT: result of the query"