Posts

Showing posts from 2017

How to style your input file in Reagent with Bootstrap

Image
Ok this caused me a lot of headache, hope it will help anyone. In bootstrap the only way to style a input with type file, is to close it in a label. Like this: <label class="btn btn-default btn-file"> Browse <input type="file" style="display: none;"> </label>     Unfortunately, as things are now, the only way to do something like this in Reagent is to set the InnerHhtml and do something like this: (defn ^:export on-click   [event]   (js/alert "Upload Button Clicked") (defn ^:export on-change   [event]   (js/alert "File Changed) (def input-html "<input id='upload-file' name='updload-file' type='file' style='display: none;' onclick='{ns}.table.on_click(event)' onchange='{ns}.table.on_change(event);'></input>") [:label.btn.btn-primary.col-span-1      {:dangerouslySetInnerHTML       {:__html (str (label-input "Select File") input-...

How to do an upload using REST (Swagger) and Clojurescript (ajav

Hoping to help someone else that is also struggling with this. I have used Luminus with Reagent to try this. Luminus come with Swagger for REST API, it's a great tool because it gives you the possibility to try the API as soon as you have write it. This is the code to write a REST end-point that accept a file in upload (ns your-clojure-ns   (:require [ring.util.http-response :refer :all]             [compojure.api.sweet :refer :all]             [schema.core :as s]             [ring.swagger.upload :as upload]) (defapi service-routes   {:swagger {:ui "/swagger-ui"              :spec "/swagger.json"              :data {:info {:version "1.0.0"                            :title "Sample API"                 ...

First project with Luminus and Reagent... impressions.

Ok I have started a project for a friend https://github.com/marcomanzi/arcatron, it's web application to charge customers for calls done. I'm using Luminus with Reagent as frontend... how it is going... I will compare this with my experience in doing something similar using Java, with Spring and Vaadin. During this development I had more feeling coming out, these are the things I want to share (not ordered by relevance) Fun: Well, this is a totally new experience, I have Terminator with 3 windows, one with lein test-refreh, one with lein run and one with lein figwheel. I really enjoy that I see happening in my browser while I change them. It's a new experience because with Vaadin every little change I had to restart the application server (it does not take long though) Creativity: Because there is not a clear path written (with Spring a Vaadin you are taken by hand and they guide you to the final result like a parent with a child) I was able to come out with my soluti...

SICP in Clojure: Chapter 2 (part 1)

Going on with my study of SICP, this is the first part of chapter 2 (that is a very big chapter and also has a lot of great examples). I also updated the code in the first chapter for some issues with chapter 2 names that were replicated (I made some private definitions there to use refer all here). The painter example of this book was really cool and actually you can create a painter with Quil library if you want to see it works. (ns sicp.chapter-2 (:require [sicp.chapter-1 :refer :all])) ;Common functions (defn null? [l] (and (seq? l) (empty? l))) ;Chapther 2: Building Abstractions with Data (defn linear-combination [a b x y] (+ (* a x) (* b y))) (declare add mul) (defn linear-combination [a b x y] (add (mul a x) (mul b y))) ;Chapter 2.1.1 (declare make-rat numer denom) (defn add-rat [x y] (make-rat (+ (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (defn sub-rat [x y] (make-rat (- (* (numer x) (denom y)) ...

What Clojure is missing...

Ok, now I have played with Clojure for a lot of time. I know how to write clojure programs, how to write in a functional style (on a base-medium level). What is my main work, what kind of applications I build for my company... Web Applications, batch programs for some heavy computations. Our main application is built with Grails, and I can't say that I'm am so found on Grails..... buuut .... Lately I built a web app to handle the deployment through Docker of our Web Application and I was thinking about using Clojure. This is how the discussion went (more or less): Marco : "I would like to use Clojure, is great, it gives immediate feedback and I would like to try because I feel I can do a good job" Other People  (in this company before starting we discuss pro and contro of every decision): "Mmm I heard of it.. yes it can be an idea, but what are you going to use, what is the standard. Let's say that you start the application and then you have to move on...

SICP in Clojure: Chapter 1

With a new year some new objectives should be set. Learn French Understand better functional programming Use Clojure in a real project (if you need help in some real project let me know :) ) This post is about the 2nd point. To learn more about functional programming I'm reading  Structure and Interpretation of Computer Programs .  This is really a great book but all the examples are in Lisp. To make it more actual I'm rewriting all the examples in clojure (and some exercises too).    I think it can be useful to others too, so here it is chapter 1: (ns sicp.chapter-1) ;1.1 Expressions (+ 137 349) (- 1000 334) (* 5 99) (/ 10 5) (+ 2.7 10) (+ 21 35 12 7) (* 25 4 12) (+ (* 3 5) (- 10 6)) (+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) (+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) ;1.2 Naming and the Environment (def size 2) size (* 5 size) (def pi 3.14159) (def radius 10) (* pi (* radius radius)) (def circumference (* 2 pi radius)) c...