Skip to content

Instantly share code, notes, and snippets.

View nahuel's full-sized avatar

Nahuel Greco nahuel

  • Software Developer
  • Argentina
View GitHub Profile
@nahuel
nahuel / gist:a07db3003ad22bda17a0
Created October 7, 2014 20:38
taking care on macroexpansion order when using *ns* in macros
(ns c)
(defmacro print-ns [] (println [:c *ns*]))
(ns b)
(defmacro print-ns [] (c/print-ns))
;;=> prints [:c #<Namespace b>] when c/print-ns is expanded
(b/print-ns)
;;=> nothing printed, c/print-ns already macroexpanded (and println executed) on the b/print-ns defmacro
(ns a)
(c/print-ns)
;;=> prints [:c #<Namespace a>]
BIND_DN = "cn=read-only-admin,dc=example,dc=com"
BIND_PASSWORD = 'password'
import simpleldap
conn = simpleldap.Connection('ldap.forumsys.com',dn=BIND_DN, password=BIND_PASSWORD)
user = conn.get("uid=euler")
@nahuel
nahuel / gist:6e821c93a8f829b3db01
Created September 15, 2014 17:58
functools.partial
import functools
class A:
def __init__(s):
s.a = 1
def c(s,b,c,d):
print s.a,b,c,d
a = A()
a.c(2,3,4)
#=> 1 2 3 4
(defn remove-first [e [x & rest :as col]]
(lazy-seq
(cond (empty? col) []
(= x e) rest
:default (cons x (remove-first e rest))
)))
@nahuel
nahuel / improving as->.clj
Created May 9, 2014 07:09
improving as-> macro by supporting destructuring
;; The as-> macro doesn't work with destructuring. This is invalid code:
(-> [1 2]
(as-> [a & b]
[a (inc b)]
[(inc a) b]))
;; because it is expanded to:
(let [[a & b] [1 2]