Skip to content

Instantly share code, notes, and snippets.


Omar Antolín Camarena oantolin

View GitHub Profile
View standalone-eshell.el
;; -*- lexical-binding: t; -*-
;; to use run: emacs --batch -l standalone-eshell.el
(require 'em-prompt)
(let ((dir default-directory))
(add-hook 'eshell-directory-change-hook
(lambda () (setq dir default-directory)))
(while t
oantolin / py-docstring.el
Last active Mar 31, 2021
Primitive python docstring generator in Emacs Lisp
View py-docstring.el
(defun py-docstring ()
"Primitive Python docstring generator."
(let* ((all-args
(lambda (s) (split-string s "\\s-*=\\s-*"))
(split-string (buffer-substring
oantolin / cicio.lua
Created Jan 17, 2021
Lisp dialect that compiles to Lua: no documentation, no error reporting
View cicio.lua
syntax = {}
for _, kind in ipairs {"vector", "table"} do
local mt = {}
syntax[kind] = function (x) return setmetatable(x, mt) end
syntax[kind .. "_p"] = function (x) return type(x)=="table" and getmetatable(x)==mt
function syntax.form_p(x)
View comprehension.fnl
(fn comprehend [init update ...]
(let [clauses [...] n (length clauses) result (gensym)]
(tset clauses n (update result (. clauses n)))
(for [i (- n 1) 1 -1] (table.insert (. clauses i) (. clauses (+ i 1))))
`(do (var ,result ,init) ,(. clauses 1) ,result)))
(fn tbl [...]
(comprehend {}
(fn [result expr] `(match ,expr (k# v#) (tset ,result k# v#)))
oantolin / contrast.c
Last active May 11, 2020
Find most luminous contrasting color
View contrast.c
#include <math.h>
#include <stdio.h>
double f(int c) {
double x = c / 255.0;
return x<=0.03928 ? x/12.92 : pow((x + 0.055)/1.055, 2.4);
double rellum(int r, int g, int b) {
return 0.2126*f(r) + 0.7152*f(g) + 0.0722*f(b);
oantolin / my-smartparens-config.el
Created Jun 25, 2017
My smartparens configuration
View my-smartparens-config.el
(use-package smartparens
:diminish smartparens-mode
(require 'smartparens-config)
(add-hook 'eval-expression-minibuffer-setup-hook #'smartparens-mode)
'(sp-base-key-bindings 'sp)
oantolin / turn-off-openwith-mode.el
Created Dec 3, 2014
Turn off openwith-mode for certain commands
View turn-off-openwith-mode.el
(defun turn-off-openwith-mode (orig-fun &rest args)
"Ensure openwtih-mode is off when running dired-mark-files-containing-regexp"
(let ((openwith-mode-on? openwith-mode))
(when openwith-mode-on? (openwith-mode -1))
(apply orig-fun args)
(when openwith-mode-on? (openwith-mode 1))))
(dolist (cmd '(dired-mark-files-containing-regexp message-send-and-exit))
(advice-add cmd :around #'turn-off-openwith-mode))
oantolin /
Created Mar 28, 2014
Help me make this Clojure code about as fast as Java, please!
public class T {
static int f(int x, int y, int z, int n) {
return 2*(x*y+y*z+x*z) + 4*(x+y+z+n-2)*(n-1);
static int[] g(int n) {
int[] count = new int[n+1];
for (int x=1; f(x,x,x,1)<=n; x++)
for (int y=x; f(x,y,y,1)<=n; y++)
for (int z=y; f(x,y,z,1)<=n; z++)
oantolin /
Created Mar 25, 2014
ds = set(range(2,10))
for t in ds:
e = 11-t
for n in ds - {t,e}:
for x in [0,1]:
k = 10*x+e-n-1
if k in ds - {t,e,n}:
for o in ds - {t,e,n,k}:
for y in [0,1]:
a = 10*y+n-o-x
View layer-loop.lisp
(declaim (optimize (speed 3) (safety 0)))
(defmacro with-type (type expr)
(if (atom expr)
(let ((op (car expr)))
(lambda (x y)
`(the ,type
(,op ,@(if x (list x) '())