Skip to content

Instantly share code, notes, and snippets.

@dfuenzalida
dfuenzalida / core.clj
Created Jun 29, 2021
Sort strings numerically in Clojure
View core.clj
(defn digits-in-str [s]
(->> (re-seq #"\d+" s) first))
(def items ["item_20" "item_11" "item_1" "item_120"])
(comment
(sort-by (comp clojure.edn/read-string digits-in-str) items)
;; => ("item_1" "item_11" "item_20" "item_120")
@dfuenzalida
dfuenzalida / clojure-webapp-azure-quickstart.md
Created Feb 21, 2021
Quick guide to deploy a Clojure web app to Azure
View clojure-webapp-azure-quickstart.md

Quick guide to deploy a Clojure web app to Azure

Prerequisites

@dfuenzalida
dfuenzalida / instructions.md
Last active Feb 18, 2021
Using jdb on bytecode compiled from clojure.core/compile
View instructions.md

Software versions:

$ clj
Clojure 1.10.1

$ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
@dfuenzalida
dfuenzalida / camel.pl
Last active Dec 15, 2020 — forked from cgoldberg/camel.pl
Perl Camel code - render 4 ascii camels from camel-styled source code.
View camel.pl
#!/usr/bin/perl -w # camel code
use strict;
$_='ev
al("seek\040D
ATA,0, 0;");foreach(1..3)
{<DATA>;}my @camel1hump;my$camel;
my$Camel ;while( <DATA>){$_=sprintf("%-6
9s",$_);my@dromedary 1=split(//);if(defined($
_=<DATA>)){@camel1hum p=split(//);}while(@dromeda
@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)))