Skip to content

Instantly share code, notes, and snippets.

View jplaza's full-sized avatar

Juan Antonio Plaza jplaza

View GitHub Profile

Se dice que la programación funcional es declarativa, permite expresar la solución a un problema en términos del qué en lugar del cómo. A lo largo de este módulo de Front-end Programming con React utilizaremos preferentemente este estilo de programación.

Estos ejercicios tiene el objetivo de ayudarlos a familiarce un poco más con las funciones para arreglos de JS que ya aprendieron.

Aquí la documentación a las funciones y una característica del lenguaje que necesitarán para resolver los siguientes ejercicios

@jplaza
jplaza / data.clj
Created October 21, 2023 02:52
Aggregate data in the form of a list of hash maps in Clojure. Inspired by SQL GROUP BY and aggregate functions like SUM and MAX
(defn aggregate-data
"data - collection of hash-maps to aggregate
group-key - vector of keys to group hash-maps
aggregates - vector of vectors of key, aggregate fn and optionally a new
name for this key e.g.
[[+ :amount :stock]
[max :date :latest-tx-date]]
Aggregate functions receive variable arguments"
[data group-keys aggregates]
const data = [
{ category: "Fruits", price: "$1", stocked: true, name: "Apple" },
{ category: "Fruits", price: "$1", stocked: true, name: "Dragonfruit" },
{ category: "Fruits", price: "$2", stocked: false, name: "Passionfruit" },
{ category: "Vegetables", price: "$2", stocked: true, name: "Spinach" },
{ category: "Vegetables", price: "$4", stocked: false, name: "Pumpkin" },
{ category: "Vegetables", price: "$1", stocked: true, name: "Peas" }
]
@jplaza
jplaza / toolbox.clj
Created May 18, 2018 20:37
Extrae la clave de acceso de un RIDE PDF
(ns co.datil.toolbox.pdf
(:require [pdfboxing.text :as pdfbox]
[clojure.java.io :as io]
[clojure.string :as string]))
(defn -remove-trailing-slash
[url]
(string/replace #"(?<=.)/$" ""))
(defn -rand-name
@jplaza
jplaza / cli_clock.clj
Last active May 4, 2018 19:38
Convert seconds to a stop watch
(defn strftime [secs]
(format "%02d:%02d:%02d"
(mod (int (/ secs 3600)) 24)
(mod (int (/ secs 60)) 60)
(mod secs 60)))
(defn secs-elapsed-since-midnight []
(let [now (java.time.ZonedDateTime/now)
midnight (.truncatedTo now java.time.temporal.ChronoUnit/DAYS)
duration (java.time.Duration/between midnight now)]
@jplaza
jplaza / error-firmando.json
Created December 18, 2015 22:40
Datil sign issue error
{
"secuencial":766,
"firma":{
"result":"bad",
"error":"Ocurrió un error al tratar de firmar el comprobante, por favor inténtalo nuevamente.",
"status":400
},
"fecha_emision":"2015-12-16T15:38:01-05:00",
"emisor":{
"ruc":"1792478103001",
@jplaza
jplaza / poll-sqs.clj
Last active November 17, 2015 18:59
Minimal implementation of an SQS long polling daemon written in Clojure
(ns co.datil.sqsd
"Polls SQS periodically for messages."
(:require [amazonica.aws.simpleworkflow :as swf]
[amazonica.aws.sqs :as sqs]
[clojure.tools.logging :as log]
[environ.core :refer [env]]))
(defn process-msg
"Task: body of the message placed in the queue"
[queue-url msg]
{
"id":"07f471bcfd434d13897a6edcf190441d",
"secuencial":"42578",
"clave_acceso":"0911201501099258144100120010010000425781993590512",
"autorizacion":{
"numero":"0911201516311709925814410010997052341",
"fecha":"2015-11-09T16:31:17.000968",
"estado":"AUTORIZADO",
"mensajes":[
{
name: "Guayaquil",
photos: [{
file: "peñas.jpg",
description: "Barrio las Peñas",
created: "2015-10-24"
}, {
file: "malecón.jpg",
description: "Vista Aérea del Malecón",
created: "2014-12-30"
@jplaza
jplaza / legacy_support_invoice_response.json
Created September 21, 2015 20:09
Support for legacy (factora) JSON schema
{
"emisor": null,
"total_sin_impuestos": "225.57",
"secuencia": "263",
"tipo": "factura",
"total_impuestos": [
{
"codigo": "2",
"codigo_porcentaje": "2",
"base_imponible": "200.58",