Skip to content

Instantly share code, notes, and snippets.

@mishoo
mishoo / gist:911261
Created April 9, 2011 09:13
amb in javascript
// following https://gist.github.com/911094
function amb_run(program, failure_value) {
var index = 0, steps = [];
while (true) try {
return program(amb, fail);
} catch(ex) {
if (ex !== fail) throw ex;
for (var i = steps.length; --i >= 0;) {
var a = steps[i];
@mishoo
mishoo / ucs.js
Created October 14, 2011 12:09
Uniform-cost-search implementation (problem discussed in ai-class.com 2.6)
// run with NodeJS, or load in a browser with console.log
////// test
with_graph([
["oradea" , "zerind" , 71],
["oradea" , "sibiu" , 151],
["zerind" , "arad" , 75],
["arad" , "sibiu" , 140],
["arad" , "timisoara" , 118],
@mishoo
mishoo / drop-debug.js
Created November 11, 2011 07:45
Drop debug(...) calls using PatternJS
var U = require("uglify-js");
var fs = require("fs");
var sys = require("sys");
var code = fs.readFileSync("/tmp/test.js", "utf8");
// 1. parse
var ast = U.parser.parse(code);
// 2. UglifyJS compress
@mishoo
mishoo / value-iteration.lisp
Created November 20, 2011 15:35
Unit 12.3 — value iteration
(defpackage :value-iteration
(:use :cl))
(in-package :value-iteration)
(defun value-iteration (&key grid is-term actions next-state cost gamma)
(loop :with changed = nil
:for i :from 0 :to (1- (array-dimension grid 0))
:finally (return changed)
:do (loop :for j :from 0 :to (1- (array-dimension grid 1))
// Explaining https://twitter.com/mcbazon/status/236504096868286464
// I have a simple output stream implementation that keeps track
// of current line/col numbers. It accumulates text in the OUTPUT
// variable, and at times I needed to know the last character
// that was added. I had this function:
function last_char() {
return OUTPUT.charAt(OUTPUT.length - 1);
};
@mishoo
mishoo / ugly-diff.sh
Created September 8, 2012 20:01
ugly-diff
#! /bin/sh
uglifyjs -v -b -nm -ns -nc $1 > /tmp/ugly-diff-1
uglifyjs -v -b -nm -ns -nc $2 > /tmp/ugly-diff-2
diff /tmp/ugly-diff-1 /tmp/ugly-diff-2 | colordiff | less -R
#! /usr/local/bin/node
var esprima = require("esprima");
var acorn = require("acorn");
var u2 = require("uglify-js2");
var fs = require("fs");
var file = process.argv[2];
var code = fs.readFileSync(file, "utf8");
@mishoo
mishoo / prefixes.css
Created March 4, 2013 10:45
Extremely useful LESS/CSS utilities
.pf1(@prop, @value) {
we: ~`"suck; " +
" -webkit-@{prop}: @{value};" +
" -moz-@{prop}: @{value};" +
" -o-@{prop}: @{value};" +
" -ms-@{prop}: @{value};" +
" @{prop}: @{value}"`;
}
.pf2(@prop, @value) {
;;; -*- lexical-binding: t -*-
;;; qq-highlight.el
;;; Provides a function that temporarily highlights Lisp code
;;; templates (quasi-quotations) to make them easier to follow.
;;;
;;; Author: Mihai Bazon <mihai.bazon@gmail.com>, 2013.
;;; This file is public domain.
;;;
;;; stupid-indent-mode.el --- Plain stupid indentation minor mode
;; Copyright (C) 2013 Mihai Bazon
;; Author: Mihai Bazon <mihai.bazon@gmail.com>
;; 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