This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun partition (pred list) | |
"Split LIST into elements for which PRED returns true and false." | |
(let (true false) | |
(dolist (elt list) | |
(if (funcall pred elt) | |
(push elt true) | |
(push elt false))) | |
(cons (nreverse true) (nreverse false)))) | |
(defun connected-components (vertices adjacentp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun py-docstring () | |
"Primitive Python docstring generator." | |
(interactive) | |
(save-excursion | |
(beginning-of-defun) | |
(down-list) | |
(let* ((all-args | |
(mapcar | |
(lambda (s) (split-string s "\\s-*=\\s-*")) | |
(split-string (buffer-substring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
end | |
end | |
function syntax.form_p(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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#))) | |
...)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package smartparens | |
:diminish smartparens-mode | |
:init | |
(smartparens-global-mode) | |
:config | |
(require 'smartparens-config) | |
(add-hook 'eval-expression-minibuffer-setup-hook #'smartparens-mode) | |
(custom-set-variables | |
'(sp-base-key-bindings 'sp) | |
'(sp-override-key-bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder