Skip to content

Instantly share code, notes, and snippets.

@mishoo
mishoo / binary-stream.lisp
Last active October 12, 2023 12:24
binary-stream.lisp
(deftype rawdata () '(array (unsigned-byte 8) 1))
(defclass memstream (fundamental-binary-input-stream fundamental-binary-output-stream)
((data :initarg :data
:type rawdata
:initform (make-array 0 :adjustable t
:fill-pointer 0
:element-type '(unsigned-byte 8))
:accessor memstream-data)
(size :initarg :size
@mishoo
mishoo / image-size.lisp
Last active August 31, 2023 07:14
Get image dimensions by parsing file headers
(defgeneric image-size (input)
(:method ((input pathname))
(with-open-file (input input :element-type 'unsigned-byte)
(image-size input)))
(:method ((input string))
(with-open-file (input input :element-type 'unsigned-byte)
(image-size input)))
(:method ((input stream))
<?php
$x = [ '5' => 1, '6' => 2, '7' => 3 ];
echo json_encode($x); // outputs {"5":1,"6":2,"7":3}
$y = array_merge($x, [ '8' => 4 ]);
echo json_encode($y); // outputs [1,2,3,4]
(defun unfill-paragraph ()
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
<!DOCTYPE html>
<html>
<head>
<style>
.counters {
counter-reset: xxx;
}
.counters > p {
counter-increment: xxx;
}
@mishoo
mishoo / Diagram-pdf
Last active August 29, 2015 14:07 — forked from Orbifold/Diagram-pdf
<!DOCTYPE html>
<html>
<head>
<title>Kendo Diagramming</title>
<link rel="stylesheet/less" type="text/css" href="../../styles/web/kendo.common.less"/>
<link rel="stylesheet/less" type="text/css" href="../../styles/web/kendo.default.less"/>
<link rel="stylesheet/less" type="text/css" href="../../styles/dataviz/kendo.dataviz.less"/>
<link rel="stylesheet/less" type="text/css" href="../../styles/dataviz/kendo.dataviz.default.less"/>
<script type="text/javascript" src="../../demos/mvc/content/shared/js/less.js"></script>
// -*- js -*-
xkb_keymap "mishoo" {
xkb_keycodes { include "evdev+aliases(qwertz)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols {
include "pc+us+inet(evdev)"
//// Safari parser bug
//// derived from: https://github.com/mishoo/UglifyJS2/issues/313
// fails with SyntaxError: Expected token ')'
( function(){ return this || eval('this'); }().x = "y" );
// fails with SyntaxError: Unexpected token '='
1, function(){ return this || eval('this'); }().x = "y";
//// weird that we get different error messages
@mishoo
mishoo / gist:6769144
Created September 30, 2013 19:47
catch/throw in terms of call/cc
(define throw (lambda (tag val)
(error "Uncaught throw " tag)))
(define (catch* needle thunk)
(call/cc (lambda (k)
(define prev throw)
(fluid-let ((throw (lambda (try val)
(if (eq try needle)
(k val)
(prev try val)))))
;;; stupid-indent-mode.el --- Plain stupid indentation minor mode
;; Copyright (C) 2013 Mihai Bazon
;; Author: Mihai Bazon <[email protected]>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or