Skip to content

Instantly share code, notes, and snippets.

View danlentz's full-sized avatar

Dan Lentz danlentz

View GitHub Profile
@html
html / weblocks-tinymce-textarea-presentation.lisp
Created January 8, 2013 14:25
Tinymce textarea presentation for weblocks. Uses cl-config (https://github.com/html/cl-config) and jquery-seq (https://github.com/html/jquery-seq) and tinymce itself.
(cl-config:set-value :weblocks.tinymce-textarea-presentation.tinymce-settings "({
debug: true,
script_url : '/pub/scripts/tiny_mce/tiny_mce.js',
theme : 'advanced',
plugins : 'pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template',
theme_advanced_buttons1: 'save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect',
theme_advanced_buttons2: 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor',
theme_advanced_bu
@danlentz
danlentz / MMAP-FILE.lisp
Last active December 11, 2015 16:58
Paul khong's mmap file as array
;; Abuse SBCL's runtime as a portability layer. None of this is portable
;; anyway.
(define-alien-routine os-allocate (* t) (size unsigned-long))
(define-alien-routine os-map (* t)
(fd int) (offset int) (addr (* t)) (size unsigned-long))
(define-alien-routine os-invalidate void (addr (* t)) (size unsigned-long))
(defun map-file (path address size &optional offset)
(with-open-file (s path)
@danlentz
danlentz / FLET-dynamic.lisp
Created January 27, 2013 03:01
Dynamically bound functions
;;; Dynamically bound functions.
;;; DEFUN-DYNAMIC defines a function which may be dynamically bound
;;; with FLET-DYNAMIC.
(defconstant +dynamic-fun-tag+ 'dynamic-fun-tag)
(defmacro defun-dynamic (name params &body body)
(let ((args (gensym))
# git bash auto-completion
source `brew --prefix git`/etc/bash_completion.d/git-completion.bash
# latest versions of git has the prompt stuff on an extra file
__git_prompt_file=`brew --prefix git`/etc/bash_completion.d/git-prompt.sh
if [ -f "$__git_prompt_file" ]
then
source $__git_prompt_file
fi
@danlentz
danlentz / restas-daemon.lisp
Created February 1, 2013 19:10 — forked from irmpow/restas-daemon.lisp
/etc/restas/
;;;; restas-daemon.lisp
;;;;
;;;; Usage:
;;;; sbcl --noinform --no-userinit --no-sysinit --load /path/to/restas-daemon.lisp /path/to/daemon.conf COMMAND
;;;; where COMMAND one of: start stop zap kill restart nodaemon
;;;;
;;;; If successful, the exit code is 0, otherwise 1
;;;;
;;;; Error messages look in /var/log/messages (usually, depend on syslog configuration)
;;;;
@danlentz
danlentz / define-lazy-singleton.lisp
Created February 3, 2013 01:33
A nice macro from cl-nlp
(defmacro define-lazy-singleton (name init &optional docstring)
"Define a function NAME, that will return a singleton object,
initialized lazily with INIT on first call.
Also define a symbol macro <NAME> that will expand to (NAME)."
(with-gensyms (singleton)
`(let (,singleton)
(defun ,name ()
,docstring
(or ,singleton
(setf ,singleton ,init)))
@lukego
lukego / gist:4706097
Last active December 12, 2015 03:19
Table data structure that "garbage collects" not-recently-used items in O(1) time

I use this data structure all the time. Can someone leave a comment and tell me what it's called?

  1. insert(k,v): add a new value
  2. lookup(k): lookup an existing value
  3. age(): delete old entries (that have not been used since previous call to age())
# Initialize 'old' and 'new' to empty tables
local old, new = {}, {}
(in-package :trie)
(export '(make-trie
trie-get
trie-set
trie-prefix-p))
(defun make-trie ()
(make-hash-table))
(defun %trie-get (trie path)
(deftype octet () '(unsigned-byte 8))
(defun read-le-uint (size in)
(loop FOR i FROM 0 BELOW size
SUM (ash (read-byte in) (* i 8))))
(defun read-bytes (size in)
(let ((ary (make-array size :element-type 'octet)))
(read-sequence ary in)
ary))
;;; THIS IS A PROOF OF CONCEPT. This has been "released" in case someone
;;; actually wants to develop it into a usable tool. Don't even think
;;; about using this version for any sort of production use.
;;; Author: Juho Snellman
;;; http://jsnell.iki.fi/blog/archive/2005-07-06.html
(defparameter *retain* (make-hash-table :test 'eq))
(defparameter *ignore* (make-hash-table :test 'eq))
(defparameter *classes* nil)