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 python/find-relative-indentation () | |
"find the previous defun indent level" | |
(with-current-buffer (current-buffer) | |
(save-excursion | |
(let* ((previous-def (progn (search-backward "def ") (point))) | |
(previous-bol (progn (beginning-of-line) (point))) | |
(indent (- previous-def previous-bol))) | |
indent)))) | |
;; def foo(): |
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
(setq lexical-binding t) | |
(defun make-struct (fields) | |
(lambda (values) | |
(let ((map (-zip fields values))) | |
(lambda (field) | |
(assoc field map))))) | |
;;; generic | |
(setq s (make-struct '(:a :b :c))) |
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
def load(c): | |
d = {} | |
with open(c) as cnf: | |
for l in cnf.readlines(): | |
if not l.startswith('#'): | |
k,v = l.split('=',1) | |
d[k] = v.strip() | |
else: | |
if l.startswith('##'): | |
instr = l[2:] |
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
(require 'dash) | |
(setq lexical-binding t) | |
(defun is-dot-p (dir) | |
(or (equal dir ".") | |
(equal dir ".."))) | |
(defun get-package-from-dirname (dn) | |
(mapconcat #'identity (-butlast (split-string dn "-")) "-")) |
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
#!/usr/bin/env sh | |
case $(curl -sLI $1 | grep -i content-type) in | |
*text*) echo "curl $1" | |
;; | |
*) echo "curl $1 > $(basename $1)" | |
;; | |
esac |
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
(defn pick [m & ks] | |
"map ks vs -> [ks'] -> map ks' vs'" | |
(reduce (fn [a k] (assoc a k (m k))) {} ks)) | |
;;; test | |
(let [m {:trace-redirects ["http://html5test.com"], | |
:request-time 126, | |
:status 200, | |
:headers {"content-encoding" "gzip", |
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 -iterate-while (fn pred &optional limit) | |
(let ((limit (or limit 128)) | |
(r (funcall fn))) | |
(if (or (not (funcall pred r)) (= 0 limit)) | |
r | |
(-iterate-while fn pred (1- limit))))) | |
;; (funcall (-flip #'<) 2 1) | |
;; (funcall (-partial (-flip #'<) 10) 0) |
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
;; Like everything else posted to kragen-hacks without any notice to the | |
;; contrary, this program is in the public domain; I abandon any | |
;; copyright in it. | |
;;; Toggling of argument lists between horizontal and vertical. | |
;; For example, turn this: memset(bigstring, '\xe3', bigstringsize-1); | |
;; into this: memset(bigstring, | |
;; '\xe3', | |
;; bigstringsize-1); | |
;; or vice versa. |
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
# @>>> Pipe() | ['echo', 'foo bar baz'] | ['grep', 'a'] | None | |
# b'foo bar baz\n' | |
# @>>> Pipe() | ['echo', 'foo\nbar\nbaz'] | ['grep', 'a'] | None | |
# b'bar\nbaz\n' |
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
def coca_cola(): | |
while True: | |
yield True | |
head, *tail = coca_cola() | |
>>> head = True, tail = <generator....> |