Skip to content

Instantly share code, notes, and snippets.

Avatar

Denis Fuenzalida dfuenzalida

View GitHub Profile
@dfuenzalida
dfuenzalida / repl.clj
Created Aug 4, 2020
ClojureScript defrecord and keyword lookups?
View repl.clj
(defrecord Attr [has-default default])
cljs.user/Attr
cljs.user=> (def attr (->Attr true 1))
#'cljs.user/attr
cljs.user=> attr
#cljs.user.Attr{:has-default true, :default 1}
cljs.user=> (map? attr)
true
cljs.user=> (keys attr)
(:has-default :default)
View how_does_day03_clj_work.md
View core.clj
(ns datomic-shortcut.core
(:require [datomic.api :as d]))
(def db-uri "datomic:mem://foo")
(comment
(d/create-database db-uri)
(def conn (d/connect db-uri))
)
@dfuenzalida
dfuenzalida / funapp.clj
Created May 24, 2020
Sample run of funapp.clj - interop of Clojure and Python with libpython-clj
View funapp.clj
(ns appcompany.funapp
(:require [libpython-clj.python :as py :refer [py. py.- py.. py* py**]]
appcompany.python
[libpython-clj.require :refer [require-python import-python]]))
(import-python)
(require-python '[builtins :as python])
(require-python '[base64 :as pybase64])
(require-python '[funniest :as pyfunniest])
@dfuenzalida
dfuenzalida / demo.clj
Last active Mar 7, 2020
InputStream to Base64 stream
View demo.clj
;; An example InputStream made of 128 bytes:
(defn bytes-is []
(java.io.ByteArrayInputStream. (into-array Byte/TYPE (range 128))))
(defn b64encode [s]
(String. (.encode (java.util.Base64/getEncoder) (.getBytes s))))
;; Now we read the input stream *in memory* (with slurp) and encode as base64:
(-> (bytes-is) slurp b64encode)
;; => "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJC...n8="
@dfuenzalida
dfuenzalida / core.clj
Created Feb 7, 2020
Solución en Clojure al Desafío de la Gran Capicuá (Programando.org)
View core.clj
(ns grancapicua.core)
(defn reverso [res n]
(if (zero? n)
res
(recur (+ (* 10 res) (rem n 10)) (quot n 10))))
(defn capicua? [n]
(= n (reverso 0 n)))
@dfuenzalida
dfuenzalida / part2.clj
Last active Jan 27, 2020
Solución Calculando Capicuas de Programando.org en Clojure
View part2.clj
(ns capicuas.part2)
(defn reverso [res n]
(if (zero? n)
res
(recur (+' (* 10 res) (rem n 10)) (quot n 10))))
(defn not-palin? [n]
(not= n (reverso 0 n)))
@dfuenzalida
dfuenzalida / capicuas.py
Last active Jan 20, 2020
Desafio Capicuas en Python3
View capicuas.py
def reverso(n):
res = 0
while (n > 0):
res = (res * 10) + (n % 10)
n = n//10
return res
def palin(n):
return n == reverso(n)
@dfuenzalida
dfuenzalida / core.clj
Last active Jan 20, 2020
Desafio Capicuas de Programando.org en Clojure
View core.clj
(ns capicuas.core)
(defn reverso [res n]
(if (zero? n)
res
(recur (+ (* 10 res) (rem n 10)) (quot n 10))))
(defn palin? [n]
(= n (reverso 0 n)))
@dfuenzalida
dfuenzalida / compilation-output.txt
Created Jan 14, 2020
janet littleserver + json responses
View compilation-output.txt
denis@carbon:~/Projects/janet/littleserver$ janet -v
1.6.1-dev-0457966
denis@carbon:~/Projects/janet/littleserver$ jpm --verbose build
generating executable c source...
found native /usr/local/lib/janet/circlet.so...
found native /usr/local/lib/janet/json.so...
compiling and linking build/lserve...
cc -std=c99 -Wall -Wextra -I/usr/local/include/janet -O2 -o build/lserve build/lserve.c /usr/local/lib/janet/circlet.a /usr/local/lib/janet/json.a /usr/local/bin/../lib/libjanet.a -lm -ldl -lrt -lpthread
/usr/local/lib/janet/json.a(json.static.o): In function `_janet_mod_config':
You can’t perform that action at this time.