Just remembered that I had a simple project in golang =] https://git.sr.ht/~lucasemmoreira/go-croqui
Code
Go croqui added to my projects!
My first clojure project on the list!
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.
Integration test in a good way
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!
pomodoro is now its own thing!
I started using my pomodoro script again, and made few improvements. Also, I separated in its own repository.
Extract infos from a pdf!
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 =]
Managing dependencies in clojure
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]]
Divide and Conquer to optimality!
This week I made a pretty cool achievement for the paper on the wall that says that I am an applied mathematician. This week, I developed a branch and bound to solve a mixed integer linear problem.
Yeah… so?
Well, hipothetical reader, if you asked me that, I would say that you are not familiar with the power of integer programming. This kind of technique is pretty useful in the industry, in an area called operational research.
To make it simple, it is intended to help the user make better decisions. In other words, it is inside the prescription area inside artificial intelligence (more on this later!).
Ok… tell me more… (I think)
Let’s think of an example. Let’s say you have to find the best route from point A to point B, and for the sake of the example, you do not want google to track you down, so you cannot use google.maps =].
In this case, integer programming can help you! Why? Because you have to make the decisions of where to turn and when.
Ok, the problem passed the first test. The second test is a lot more techinical. You have to be able to model this problem only with linear equations. Putting aside what is the modelling per se, you might be wondering: “Why must it be linear? Nothing in the world follows a linear curve!”. To which my answer would be: “Correct, hypothetical reader! But you gain something pretty cool by forcing it to be linear. The solution you find is guaranteed to be optimal! In the worst case, I can tell you how better the solution could be, if not optimal!”
And now, I will give you some time to think about this. I am telling you there is an algorithm that with few conditions (one might be hard one), you can have the best kind o quality measure one can think of. The final solution is n percent
worse than the best one.
Ok… I’m kind of sold. But what does Branch and Bound have to do with this?
Well, branch and bound is the go to algorithm framework solvers use to find this measure of quality I mentioned earlier. And I made one in clojure! I had to solve a small problem and I could not find a decent package similar to pulp in python (which is very sad, if I may say so).
Nice, but I don’t need to find a route…
Glad you mentioned this! That’s the beauty of it. Branch and Bound is a framework in which, if you can mathematically model the problem, you can solve a bunch of kind of problems:
- Find the best location to build a station (fire fighters, restaurants, telecomunication towers, etc…)
- Find the best way to load a truck (or any container for this matter).
- Best way to plan your production
and others. Here you can find a bunch of applications! =]
Pomodoro with shell script
By now, you must be asking yourself: “Oh my god, all you know is janet/functional programming?!”, to which my answer would be a resounding “Yes!”.
However, today I decided to step a little bit outside my comfort zone and make a little script to help me use pomodoro for productivity.
Like you, hypothetical reader, I use dwm with dmenu. With these you can easily create a pomodoro executable to work for you. I say easily because I have no experience with shell script and I made it happen.
Enjoy =]
Moving averages beatifully
So this is another post on the janet journey. My goal here was to create a simple moving average function in janet (maybe just as a functional programming lover).
The code
I created a repo named numja that I intend to put all mathy stuff there. And moving average fits that category.
The second step was to create a small script that would run with the new “lib”.
The result
Simple as the proposition is, simple the code and simple the result. I used the “lib”, and plotted with gnuplot and voila!
Janet? Janet!
Do you like C but changed because you were tired of the low productivity, the annoying syntax and - oh my god! - Segmentation fault? Holy shit! Me too!
But then, a couple of years ago, a friend of mine showed me Janet. And I was from the get go hooked! It took me a while to create something in it, now I have something to show.
Why Janet?
Come on… google it…
What have I done with it?
Well, I have this pet project that it is to create a Janet wrapper for ncurses. But that will deserve a post on its own. For now, I will show a game of life using the prototype version of the janet-ncurses.
- I created a repo for it: https://git.sr.ht/~lucasemmoreira/game-of-life
- It is very simple to use it. The big bang file is the initial state of it. Play with it!
- Now you can run with janet, if you have installed it,
make
/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Go croqui added to my projects!