Skip to content

Instantly share code, notes, and snippets.

View agumonkey's full-sized avatar

gum agumonkey

  • NONE
  • Dark side of the moon @ ['tkf8-2-1', 'ay21-3', '3263-827']
View GitHub Profile
@agumonkey
agumonkey / python-mode-newdef.el
Created August 3, 2014 13:12
Fast function addition: Jumps below the current defun, from anywhere inside it, at the same indentation level
(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():
@agumonkey
agumonkey / functor.el
Created August 10, 2014 07:31
Everything is a function ? even structs and types ?
(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)))
@agumonkey
agumonkey / config.py
Created September 27, 2014 10:03
attempt to recreate config [key = value] file loader with comments and more
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:]
@agumonkey
agumonkey / regenerate-elpa-autoloads.el
Created October 28, 2014 12:01
Trying to batch rebuild elpa packages autoloads
(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 "-")) "-"))
@agumonkey
agumonkey / kurl
Created November 17, 2014 13:45
curl wrapper to only pipe text mime type to stdout, the rest to the filesystem
#!/usr/bin/env sh
case $(curl -sLI $1 | grep -i content-type) in
*text*) echo "curl $1"
;;
*) echo "curl $1 > $(basename $1)"
;;
esac
@agumonkey
agumonkey / pick.clj
Created November 25, 2014 16:50
clojure implementation of javascript pick operator on maps
(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",
@agumonkey
agumonkey / tmp-bang.el
Created December 4, 2014 12:58
A function to generate new temporary buffers with suffixed names. Needed to have an `-iterate-while` combinator. Leveraging dash.el many times.
(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)
@agumonkey
agumonkey / toggle-list-orientation.el
Created March 21, 2015 07:01
Reupload and ~patch of Kragen toggle-list-orientation code
;; 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.
@agumonkey
agumonkey / pype_tests.py
Created May 4, 2015 12:42
python3 shell pipe emulator
# @>>> 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'
@agumonkey
agumonkey / generator_unpacking.py
Created May 6, 2015 16:10
generator unpacking for python ?
def coca_cola():
while True:
yield True
head, *tail = coca_cola()
>>> head = True, tail = <generator....>