Skip to content

Instantly share code, notes, and snippets.

@dfuenzalida
dfuenzalida / WtfCreator.java
Created December 14, 2022 07:05 — forked from nikialeksey/WtfCreator.java
Joshua Bloch Wtf.java break-in
import org.apache.commons.math3.analysis.interpolation.NevilleInterpolator;
public class WtfCreator {
public static void main(String[] args) {
var text = "Hello, world!\n";
double[] x = new double[text.length() + 1];
double[] y = new double[text.length() + 1];
for(var i = 0; i < text.length(); i++) {
x[i] = i;
@dfuenzalida
dfuenzalida / core.clj
Created June 29, 2021 06:39
Sort strings numerically in Clojure
(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 February 21, 2021 06:05
Quick guide to deploy a Clojure web app to Azure

Quick guide to deploy a Clojure web app to Azure

Prerequisites

@dfuenzalida
dfuenzalida / instructions.md
Last active February 18, 2021 03:09
Using jdb on bytecode compiled from clojure.core/compile

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 December 15, 2020 05:15 — forked from cgoldberg/camel.pl
Perl Camel code - render 4 ascii camels from camel-styled source code.
#!/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 August 4, 2020 06:34
ClojureScript defrecord and keyword lookups?
(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)
(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 04:11
Sample run of funapp.clj - interop of Clojure and Python with libpython-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 March 7, 2020 21:36
InputStream to Base64 stream
;; 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="