Code

Indent file on save, please

code format align

So, I discovered that I really like to format the code on save (I am not the best typer). So emacs to the rescue:

(defun le2m/indent-buffer ()
  "indent whole buffer"
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))

(add-hook 'clojure-mode-hook
          (lambda ()
            (add-hook 'before-save-hook
                      #'le2m/indent-buffer
                      t t)))

I did this on clojure-mode but it can be done in any mode I guess.

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Indent file on save, please

Wait, do you want to choose a alias with cider?

code clojure cider

Another thing you may want/need is to use an alias when connecting cider. I know that cider can have that set up on your configuration. You can use .dir-locals.el to set up per project but I personally prefer to be able to choose when connecting.

(defun start-cider-repl-with-lein-profile ()
   (interactive)
   (letrec ((profile (read-string "Enter profile name: "))
          (lein-params (concat "with-profile +" profile " repl :headless :host localhost")))
     (message "lein-params set to: %s" lein-params)
     (set-variable 'cider-lein-parameters lein-params)
     (cider-jack-in '())))

 (defun start-cider-repl-with-cli-profile ()
   (interactive)
   (letrec ((profile (read-string "Enter profile name: "))
          (cli-params (concat "-A:" profile)))
     (message "cli-params set to: %s" cli-params)
     (set-variable 'cider-clojure-cli-aliases cli-params)
     (cider-jack-in '())))

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Wait, do you want to choose a alias with cider?

Running repl commands in cider (emacs)

code clojure emacs cider

Ok, I will admit.. this took a while. But I have found a nice way of doing this.

What is this? Well, let’s say that you have a command to start your server in user namespace. With this cool feature, now you can run this with a emacs command (or shortcut if you bind it).

The cool thing about this is that the command will run with the namespace from the repl and not the last ns that you loaded with cider =].

Here is a taste:

(defun le2m/cool-repl-command ()
 (interactive)
 (cider-interactive-eval
  (cider-insert-in-repl (format "(clojure.core/require 'a-namespace)
                                  (a-namespace/do-something
                                  (fn lambda-example [t] (:get-a-key (meta t))))") 't)))

  1. stackoverflow reference that started this

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Running repl commands in cider (emacs)

New fun hobby

fun code raylib janet

Why not have another hobby? =p

Figure 1: jaylib basic window

Figure 1: jaylib basic window

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: New fun hobby

Go croqui added to my projects!

code

Just remembered that I had a simple project in golang =] https://git.sr.ht/~lucasemmoreira/go-croqui

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Go croqui added to my projects!

My first clojure project on the list!

code finance

Recently, I created a new page on this website. I decided to put all cool projects that I made/find around the web (spoiler alert, for now it has only my projects hehe).

I have already put a few, but I noticed that none of them are in clojure which is my most fluent programming language these days.

So, let me introduce you to: invoice-translator!

The idea of the project is for you to be a little bit more aware of how you are spending your money every month. You can use something like gnucash for something like this, right? Well, yes but the tricky part is that you would have to populate the data. Or translate it to gnu-cash if you will.

Hence: invoice-translator! The idea here is to use the software to transform you credit card invoice (for now) into a csv in order to be fed to your money handling software.

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: My first clojure project on the list!

Integration test in a good way

code tools rest

This is another tale of redemption… I really enjoy minimalistic solutions and yet, I was not using for integration tests…

So, as everything that needs a start, what was the problem? For some time, I have been thinking about integration tests. What I am calling integration here means a way to test an API that goes through other APIs.

The non minimal

I tried a few approaches. One was to create a “fake” data structure that would represent the return of one API but that proved to be very difficult to insert in my coding routine.

Another approach was to use a http request client. The one I used the most was restclient mode in emacs. Which is pretty good. Here is an example of a GET request from the README:

#
# XML is supported - highlight, pretty-print
#
GET http://www.redmine.org/issues.xml?limit=10

With the mode, you have some shortcuts and can have a bunch of requests in a single file. It is pretty cool actually. The problem? it is not very good in the automation front… I did not find an easy way to run all these requests.

Well, what is the solution? Thinking minimal. Like, really minimal. I mean curl minimal.

Now, what is the problem with curl? It is tedious to make it work if you are not used to it. You have a lot of the control of how the request should be made…

Save this. We will come back to it.

The minimal

Why is it a solution, then? Because you made your request with a command line, it is very easy to automate with a script, such as a shell script.

For instance, you can create an “integration” test script like so:

# testing with 10
curl -X GET http://www.redmine.org/issues.xml?limit=10

# a test with json post
curl -X POST http://www.afakeurl.org/afakemethod --json @path-to-json-file

echo

Pretty simple if you ask me. Now, after a commit or when you feel like it, it is one command away.

Remember the problem? Well, I wonder if it really is. More control over it means that you are fully aware of what is going on. Meaning, you have a better understanding of the process. You have to study more? Sure, however I would argue it is the extra mile that could make you a better coder.

I am leaving giving my thanks to ’erica and umgeher for this small realization. Cheers!

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Integration test in a good way

pomodoro is now its own thing!

code shell-script life tools

I started using my pomodoro script again, and made few improvements. Also, I separated in its own repository.

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: pomodoro is now its own thing!

Extract infos from a pdf!

code shell-script clojure

Hypothetical reader, I bet you always wanted to extract the text from a pdf file. Sure there are a few big tech options but let me appeal to your minimalistic side: pdfminer! This is a simple jar that extracts the text from the pdf into a huge string.

What is this good for you might ask. Well, you can extract the code payment from an invoice. How? There you go: invoice =]

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Extract infos from a pdf!

Managing dependencies in clojure

clojure lein code

Today I was having a hard time to load a nice lib for managing excel files (https://github.com/mjul/docjure). I was having some weird problems at loading them in cider (btw, if you don’t use it, start now!).

I gave some search into it, and lein has a nice feature to handle dependencies. The command that saved me this time was:

lein deps :tree

It gave me a quick report on what was strange with the dependencies. Some examples:

1Possibly confusing dependencies found:
2[metosin/compojure-api "2.0.0-alpha30"] -> [com.fasterxml.jackson.datatype/jackson-datatype-joda "2.9.8"] -> [joda-time "2.7"]
3 overrides
4[midje "1.9.9"] -> [clj-time "0.15.1" :exclusions [org.clojure/clojure]] -> [joda-time "2.10"]
5
6Consider using these exclusions:
7[midje "1.9.9" :exclusions [joda-time]]
Possibly confusing dependencies found:
[metosin/compojure-api "2.0.0-alpha30"] -> [com.fasterxml.jackson.datatype/jackson-datatype-joda "2.9.8"] -> [joda-time "2.7"]
 overrides
[midje "1.9.9"] -> [clj-time "0.15.1" :exclusions [org.clojure/clojure]] -> [joda-time "2.10"]

Consider using these exclusions:
[midje "1.9.9" :exclusions [joda-time]]

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Managing dependencies in clojure