Skip to content

Instantly share code, notes, and snippets.

View aarkerio's full-sized avatar
🐵
Echando rostro en Ixtapa.

Manuel Montoya aarkerio

🐵
Echando rostro en Ixtapa.
View GitHub Profile
{"type":"charge.succeeded",
"event_date":"2019-03-06T12:54:01-06:00",
"transaction":{"id":"trnvybx9sdu6yfd3o4pn",
"authorization":"305180",
"operation_type":"in",
"method":"store",
"transaction_type":"charge",
"status":"completed",
"conciliated":false,
"creation_date":"2019-03-06T12:54:01-06:00",
{
"Records": [
{
"eventSource": "aws:ses",
"eventVersion": "1.0",
"ses": {
"mail": {
"timestamp": "2019-03-27T21:58:29.360Z",
"source": "mmontoya@gmail.com",
"messageId": "ujuocr76opqg7nbrjanfj78792kvpcig4i8g6f81",
(defn flat?
"true if there is no sequences"
[seq]
(not-any? (fn [x] (isa? (type x) java.util.List)) seq))
(defn my-flatten
"Returns flat sequence"
[seq]
(if (isa? (type seq) java.util.List)
(if (flat? seq)
(defn index-by-id
"Get index from a vector of maps using id field"
[v id]
(first (filter #(= (:id (v %)) id) (range (count v)))))
@aarkerio
aarkerio / gist:bb978c34c2f7b702530584293cf8db56
Last active December 20, 2019 21:19
Calling ClojureScript from Hiccup
;; Clojure hiccup file
[:button {:class "btn btn-success" :onClick (str "zentaur.core.deletetest("id")")} "Borrar resgistro"]
;; file: src/cljs/zentaur/core.cljs
(defn ^:export deletetest [test-id]
(when (js/confirm (str "Delete test?"))
(set! js/window.location.href (str "/admin/tests/deletetest/" test-id))))
;; Clojure hiccup file
[:button {:class "btn btn-success" :onClick (str "zentaur.core.deletetest("id")")} "Löschen"]
;; file: src/cljs/zentaur/core.cljs
(ns zentaur.core
(:require [ajax.core :refer [GET POST DELETE]]))
(defn delete-test [test-id]
@aarkerio
aarkerio / anagram.rb
Created January 20, 2020 19:41
Remove duplicated anagrams from Array
class Anagram
def initialize
@unique_anagrams = nil
end
def my_array
@unique_anagrams ||= ["perro", "algo", "qwer","uuu", "lujo", "peorr","lago","edfr", "sadasd", "uljo", "erpro", "perro", "jolu"]
end
@aarkerio
aarkerio / posts.clj
Created January 22, 2020 22:31
Clojure. Format an Instant
(:require [java-time :as jt]))
(defn format-date
"Format a Java instant"
[date]
(let [formatter (jt/format "dd-MM-yyyy HH:mm")]
(jt/format formatter (.atZone date (jt/zone-id)))))
;; clj-time is now deprecated
@aarkerio
aarkerio / clj-odf.clj
Created January 28, 2020 20:16
Create a LibreOffice text ODF file
(ns clj-odf.core
(:import java.net.URI
org.odftoolkit.simple.TextDocument
org.odftoolkit.simple.table.Cell
org.odftoolkit.simple.table.Table
org.odftoolkit.simple.text.list.List))
(defn generate-odf [filename]
(let [outputOdt (TextDocument/newTextDocument)
uri (URI. "/home/manuel/Documents/lisplogo_fancy_256.png")
@aarkerio
aarkerio / libs.clj
Created February 7, 2020 21:16
Clojure. Update some keys in a map.
(defn str-to-int
"Convert some string keys in a map to integer"
[coll & int-keys]
(let [listed (set int-keys)]
(reduce-kv #(assoc %1 %2 (if (contains? listed %2 ) (Integer/parseInt %3) %3)) {} coll)))
(str-to-int {:qt "56" :kl "Some String" :wer "22" :jj "This is ok" :aa "456" :ll "Address"} :aa :qt :wer)
;; => {:qt 56, :kl "Some String", :wer 22, :jj "This is ok", :aa 456, :ll "Address"}