Skip to content

Instantly share code, notes, and snippets.

Pavel Penev pvlpenev

View GitHub Profile
View podcast.zsh
pactl load-module module-loopback latency_msec=1 # monitor microphone in headphones
# Since you stop recording with avconv usincg Ctrl-C, trap the interupt and disable microphone monitoring
myrecord () {
setopt local_traps local_options
trap : INT;
View include.lisp
(defun include (routes &key (name-prefix nil) (template nil))
"Add a prefix to route template and route name to routes."
(loop for route in routes
collect (destructuring-bind (route-name route-template route-handler &key (method nil) (conditions nil) (additional-parameters nil))
(route (intern (concatenate 'string
(symbol-name name-prefix)
(symbol-name route-name))
(symbol-package name-prefix)) ;; Make a new name for the route for reverse lookup.
(concatenate 'string
View add-routes.lisp
(defmethod add-routes ((site site) route-specs)
(setf *routes* nil)
(routes:reset-mapper (site-route-map site))
(mapcar #'(lambda (route-spec)
(if (equal :include (first route-spec)) ;; route-spec is of form (:include *urls1* :name-prefix foo :template "/foo")
(mapcar #'(lambda (route)
(push route *routes*)
(routes:connect (site-route-map site)
(apply 'include (symbol-value (second route-spec)) (cddr route-spec)))
View nethil-routes-example.lisp
(defun index (&key name)
(format nil "Hello ~a" name))
(defparameter *urls1*
'((index "/:name" index)
(foo "/foo/:name" index)))
;; name-prefix changes the name of the route, from fo to bar-foo so you will eventually be able to do (redirect 'bar-foo) and get the correct url.
(defparameter *urls*
View nethil-example.lisp
(defun index ()
"This is the inxed")
(defun hello (&key name)
(format nil "Hello ~A" name))
(defparameter *urls*
'((index "/" :get index)
(hello "/hello/:name" :get hello)))
View nethil.lisp
(in-package #:nethil)
;;; "nethil" goes here. Hacks and glory await!
(defvar *request* nil "Current request")
(defvar *env* nil "Current clack environment")
(defvar *bindings* nil "Current route bindings")
View nethil-demo.lisp
(defpackage #:nethil-example
(:use #:cl #:nethil))
(in-package #:nethil-example)
(define-route hello "/"
(define-route hello-you "/:you"
(format nil "hello ~a" (cdr (assoc :you *bindings*))))
View nethil-example.lisp
(setf *site* (make-instance 'site
:hostname "localhost"
:name :mysite
:port 8080))
(define-app :test-app)
(in-app :test-app)
(define-route root ("/foo")
View login.lisp
(defun logged-in-p ()
(gethash :username *session*))
(defmacro must-be-logged-out (&body body)
`(if (logged-in-p)
(render #P "error.html" (list :username (logged-in-p)
:messages '("You are already logged in. Please log out first")))
(progn ,@body)))
(defmacro must-be-logged-in (&body body)
pvlpenev / authenticate.lisp
Created May 30, 2016
User authentication example
View authenticate.lisp
(defun authenticate-user (username-or-email password)
"Lookup user record and validate password. Returns two values:
1st value, was password correct T or NIL
2nd value, was user found, T or NIL
(VALUES NIL NIL) -> user not found
(VALUES NIL T) -> user found, but wrong password
(VALUES T T) -> password correct"
(let ((password-hash (getf (find-user username-or-email) :password)))
(if password-hash
You can’t perform that action at this time.