Skip to content

Instantly share code, notes, and snippets.

#+BEGIN_SRC lisp :results
(defun square (x)
(* x x))
(macro-expand '(loop
:for num :from 3 upto 6
:collect (square num)))
#+END_SRC
What I get
(defun helm-venv-workon ()
"Like venv-work, for helm."
(interactive)
(helm :sources 'helm-source-venv
:helm-buffer "*Virtual Environments*"))
(defun helm-venv-workon (candidate)
nil)
(defvar helm-source-venv
(defun to-auth-header (user &optional (date (http-date (now))))
"Encode a user's email, password and a timestamp with hmac."
(let* ((hmac (make-hmac *hmac-secret* :sha256))
(message (string-to-octets (format nil "~S ~S" (password user) date)))
(digest (progn
(update-hmac hmac message)
(hmac-digest hmac)))
(b64-digest (usb8-array-to-base64-string digest)))
(values (format nil "NOQ ~A:~A" (email user) b64-digest)
(format nil "Date: ~A" date))))
(ql:quickload :optima)
(ql:quickload :split-sequence)
(defun process-auth-header (auth-header)
"Validate that is the correct 'scheme' (NOQ) and return the id and the
digest."
(match (split-sequence #\: auth-header)
((list first digest) (cons digest . first))))
;; Error
for item in collection:
do_stuff(item)
#becomes:
iterator = iter(collection)
while True:
try:
item = iterator.next()
# The code from the for indent block goes here. (No lambdas :/)
function repeat(x,n) { var a=[]; for (;n>0;n--) a.push(x); return a; }
// returns an array of the first `n` natural numbers
function range(n) {
return repeat('10', n+2).map(parseInt).slice(2).map(function(x) {
return x-2;
});
}
[0, 1, 2, 3, 4, 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, NaN, NaN, NaN, NaN, NaN]
@PuercoPop
PuercoPop / regexp.lisp
Created March 15, 2014 07:39
Friday Night Coding with @ivoscc and @marsam
(defpackage regexp
(:use :cl :fsm))
(in-package :regexp)
(match-sequence "Hello")
;; fsm
(deffsm regexp ()
())
@PuercoPop
PuercoPop / fsm-bdecode-integer.lisp
Last active January 3, 2016 23:49
Use the fsm from hinge, used to parse http, and parse a torrent.file (starting with bstrings)
(deffsm bdecode-int ()
())
(defstate bdecode-int :initial (fsm c)
(if (char= c #\i)
:read-number
:error))
(defstate bdecode-int :read-number (fsm c)
(if (char= c #\e)
(ql:quickload :ironclad)
(ql:quickload :flexi-streams)
(defgeneric authenticate (user secret)
(:documentation "Authentication user with secret. Secret may be a
password or a token."))
(defclass user ()
((email :initarg :email :accessor email)
(password :initarg :password)
;; This works
(defun read-until (character stream)
"Read the stream until it matches the character. all the characters
read."
(coerce (loop
for char = (read-char stream)
until (char= char character)
until (char= char #\>)
collect char)
'string))