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
## based on airbnb proto interview
def rev(s):
return s[::-1]
# a .. b
# (a,b) .. (b,a)
def mir(a,b):
i = a
j = b
@agumonkey
agumonkey / fmt.el
Created March 14, 2019 21:44
fmt.el - ala python string formatting
;;; ala python string formatting
;;;
;;; (let ((some "Object") (i 1)) (f "<{some}... [{i}:{i}>")) => "<Object... [1:1]>
;;;
;;; todo: {...} parser
;;; todo: wrapping defmacro
;;; todo: wrapping defun
;;;
;;; state: alpha²
(cl-flet ((fun (x) (1+ x)))
(fun 0))
(let ((fun (lambda (x) (1+ x))))
(fun 0))
(defmacro lem (bs &rest body)
(cl-flet ((fun? (form)
(and (listp form)
(eq (length form) 3)
@agumonkey
agumonkey / fun.py
Last active March 9, 2019 02:27
pipes in python
import urllib.request as rq
class ConfusedThreader(Exception):
pass
class Fun:
def __getattr__(self,attribute):
def aux(o):
return getattr(o,attribute)()
return aux
(defmacro progm (body)
(if (null body)
'()
`(cons ,(car body)
(progm ,(cdr body)))))
(defmacro progb (&rest pair)
(let ((a (car pair))
(b (cadr pair)))
`(cons ,a (cons ,b nil))))
@agumonkey
agumonkey / hn-async.el
Last active March 6, 2019 17:13
HN async: port of a port of a script from a reddit that turns an HN article into an org-mode file
"
HN async: port of a port of a script from a reddit that turns an HN article into an org-mode file
@TODO: full eager graph walk of the json sub-structures
@TODO: full lazy walk at depth d
@TODO: org-mode overlay to intercept subtree unfolding as async GET
"
(setq lexical-binding t)
@agumonkey
agumonkey / fan.kt
Last active March 6, 2019 17:12
fantom type-ish in kotlin
// fantom type-ish in kotlin
// class res
// class open:res
// class close:res
// class file<res>
// fun open file<close> -> file<open>
// fun close file<open> -> file<close>
// fun read file<open> -> file<open> list<string>
@agumonkey
agumonkey / kotlin-mode-overlay.el
Last active March 6, 2019 17:12
kotlin-mode-overlay.el --- Missing bits for kotlin-mode
;;; kotlin-mode-overlay.el --- Missing bits for kotlin -*- lexical-binding: t; -*-
(defvar *kotlin-linter* "ktlint")
(defvar *kotlin-interpreter* "kotlin")
(defvar *kotlin-build-dir* "build")
(defvar *kotlin-main-args* "gest.xml")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN.
(defun kotlin/test ()
@agumonkey
agumonkey / mp.py
Last active March 6, 2019 17:11
metaprogramming (inspired by dave beazley)
def dec(*a, **k):
print(a,k)
return a[0] if a else lambda self: self
def debug(f, pre='[debug]', indent='.', inc=1):
depth = 0
def _(*a,**k):
nonlocal indent
nonlocal depth
@agumonkey
agumonkey / cur.py
Created March 5, 2019 01:10
for when functools.partial is not enough (and you want to reinvent the sauce)
# function:defaults code:argcount code:varnames can be used for precise curry
def vars(fun):
defaults = fun.__defaults__
argcount = fun.__code__.co_argcount
varnames = fun.__code__.co_varnames
return defaults, argcount, varnames
def cu(f):