Skip to content

Instantly share code, notes, and snippets.

;;;; Copyright (c) 2010 Olexiy Zamkoviy <[email protected]>
;;;;
;;;; Permission is hereby granted, free of charge, to any person obtaining
;;;; a copy of this software and associated documentation files (the
;;;; "Software"), to deal in the Software without restriction, including
;;;; without limitation the rights to use, copy, modify, merge, publish,
;;;; distribute, sublicense, and/or sell copies of the Software, and to
;;;; permit persons to whom the Software is furnished to do so, subject to
;;;; the following conditions:
;;;;
(defvar *files-modification-stamps* (make-hash-table :test #'equal))
(defun load-modified-files()
(dolist (i (directory "src/**/*.lisp"))
(let* ((mtime-unix (sb-posix:stat-mtime (sb-posix:stat i)))
(cell (or (gethash i *files-modification-stamps*) (setf (gethash i *files-modification-stamps*) mtime-unix)))
(any-file-modified nil))
(when (< cell mtime-unix)
(format t "Updated file ~A with last-modified time ~A~%" i mtime-unix)
(load (compile-file i))
(setf (gethash i *files-modification-stamps*) mtime-unix)
@html
html / swank-reset-weblocks-sessions.lisp
Created August 22, 2011 18:52
Reset weblocks sessions on swank code evaluation
(in-package :swank)
(defun my-repl-eval (string)
(format t "; Reseting weblocks sessions~%")
(weblocks:reset-sessions)
(repl-eval string))
(setq *listener-eval-function* #'my-repl-eval)
@html
html / gist:1698060
Created January 29, 2012 09:45
Sequential scripts loading with jQuery
// This snippet depends on https://gist.github.com/ccbeea00dd952bbe7eb4
function getScripts(collection, endcallback){
if(collection.length == 0){
return endcallback && endcallback();
}
jQuery.getScript(collection[0], function(){
getScripts(collection.slice(1), endcallback);
});
@html
html / gist:1698093
Created January 29, 2012 09:56
Sequential images loading with jquery
function eachStep(collection, callback, endcallback){
if(collection.length == 0){
return endcallback && endcallback();
}
jQuery.when(callback(collection[0])).always(function(){
eachStep(collection.slice(1), callback, endcallback);
});
}
@html
html / gist:1698119
Created January 29, 2012 10:08
Sequential files loading with jQuery
function getFiles(collection, callback){
eachStep(collection,
function(source){
return jQuery.get(source);
}, callback);
}
@html
html / enable-disable-selection.js
Created July 7, 2012 11:36
Enable/disable selection in jQuery
// Stolen from jquery-ui and customized
(function($){
$.fn.disableSelection = function(){
return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
".disableSelection", function( event ) {
event.preventDefault();
});
};
$.fn.enableSelection = function(){
@html
html / cyr-to-lat-russian-transliteration.lisp
Created November 3, 2012 12:08
Transliteration from Cyrillic to Latin in Common Lisp of Russian symbols/Транслитерация с кирилицы в латиницу на Common Lisp русских символов
(defun transliterate-cyr-to-lat-russian (text)
; Taken from http://cl-cookbook.sourceforge.net/strings.html
(defun replace-all (string part replacement &key (test #'char=))
"Returns a new string in which all the occurences of the part
is replaced with replacement."
(with-output-to-string (out)
(loop with part-length = (length part)
for old-pos = 0 then (+ pos part-length)
for pos = (search part string
:start2 old-pos
@html
html / with-yaclml.lisp
Created November 15, 2012 08:16
yaclml macro that I use with weblocks
(defmacro with-yaclml (&body body)
"A wrapper around cl-yaclml with-yaclml-stream macro."
`(yaclml:with-yaclml-stream *weblocks-output-stream*
,@body))
@html
html / normalize-newlines.lisp
Created November 16, 2012 09:18
Normalize newlines for Common Lisp
(defun normalize-newlines (string)
(ppcre:regex-replace-all (format nil "~C(\n)?" #\return) string "\n"))
(assert (string= (normalize-newlines "as\ndf") "as\ndf"))
(assert (string= (normalize-newlines (format nil "as~C\ndf" #\return)) "as\ndf"))
(assert (string= (normalize-newlines (format nil "as~Cdf" #\return)) "as\ndf"))