Skip to content

Instantly share code, notes, and snippets.

@stassats
stassats / gist:741780
Created December 15, 2010 08:41
lisp file analyzer
;;; Usage (percentage (analyze-systems '(a b c d))) => 42.23
(eval-when (:compile-toplevel :load-toplevel :execute)
(when (asdf:find-system :named-readtables nil)
(asdf:load-system :named-readtables)))
(defun analyze-form (form)
(typecase form
(symbol
(when (eql (symbol-package form) (find-package 'cl))
@stassats
stassats / post.lisp
Created August 17, 2011 04:06
Postage tracking
(eval-when (:compile-toplevel :load-toplevel :execute)
(:asd :drakma)
(:asd :babel)
(:asd :cl-json))
(defpackage post
(:use :cl))
(in-package :post)
@stassats
stassats / key-stats.el
Created August 18, 2011 12:08
Statistics of Emacs commands
(defvar key-stats-commands ())
(defun key-stats-record-command ()
(when (and (stringp (this-command-keys))
(not (eql this-command 'self-insert-command)))
(let* ((keys (this-command-keys))
(keys-list (assoc major-mode key-stats-commands))
(command (assoc keys (cdr keys-list))))
(cond (command
(incf (cdr command)))
@stassats
stassats / radiolab.lisp
Last active September 26, 2015 22:07
parse radiolab episodes from wikipedia
(eval-when (:compile-toplevel :load-toplevel :execute)
(:asd :cxml-stp)
(:asd :closure-html))
(defun parse-html (file)
(with-open-file (stream file
:element-type 'unsigned-byte)
(chtml:parse stream (stp:make-builder))))
(defun elementp (x)
#!/bin/sh
# /etc/udev/rules.d/garmin-edge.rules:
# SUBSYSTEM=="usb", ATTR{idVendor}=="091e", ATTR{idProduct}=="2491", ACTION=="add", RUN="/bin/su stas -c 'screen -d -m -S garmin ~/c/bin/upload-garmin'"
while ! mount /mnt/garmin; do
sleep 2
done
export PATH=$PATH:/usr/bin:/usr/local/bin
export DISPLAY=:0.0
#include <dbus/dbus.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef LOG_ERRORS
#include <syslog.h>
#endif
@stassats
stassats / core-disas.lisp
Last active September 15, 2015 01:50
cold-core disassembly
(defconstant +core-magic+ (logior (ash (char-code #\S) 24)
(ash (char-code #\B) 16)
(ash (char-code #\C) 8)
(char-code #\L)))
(defconstant +build-id-core-entry-type-code+ 3860)
(defconstant +new-directory-core-entry-type-code+ 3861)
(defconstant +initial-fun-core-entry-type-code+ 3863)
(defconstant +page-table-core-entry-type-code+ 3880)
(defconstant +end-core-entry-type-code+ 3840)
@stassats
stassats / gist:2b06d6142b1e110b0686
Created September 25, 2015 15:20
cold-map.lisp
(defun %find-in-map (x &optional (map "/home/stas/sbcl-arm64/output/cold-sbcl.map"))
(when (symbolp x)
(setf x
(parse-integer (string x) :radix 16 :start 2)))
(with-open-file (stream map)
(loop until (char= (read-char stream) #\Page))
(read-line stream)
(read-line stream)
(read-line stream)
(loop with address
(defparameter *funs* '(FLOOR FFLOOR CEILING FCEILING TRUNCATE FTRUNCATE ROUND FROUND))
(defparameter *types*
'((double-float 10d0)
(single-float 30f0)
(integer 31)
(ratio 1/2 3/2 1/255)))
(defun make-test-case (fun number-type divisor-type)
(let ((inputs (cdr (assoc number-type *types*)))
@stassats
stassats / colors.el
Created November 28, 2015 15:31
fix-emacs-osx-colors
(defvar *x-colors*
'(("black" "#000000")
("DimGrey" "#696969")
("DimGray" "#696969")
("dim grey" "#696969")
("dim gray" "#696969")
("DarkGrey" "#a9a9a9")
("DarkGray" "#a9a9a9")
("dark grey" "#a9a9a9")
("dark gray" "#a9a9a9")