Skip to content

Instantly share code, notes, and snippets.

View vvgomes's full-sized avatar
🦖

Vinicius Vieira Gomes vvgomes

🦖
View GitHub Profile
(function sayHello(count = 50) {
if (count === 0) return;
console.log("hello world");
sayHello(count - 1);
})();
const ROMAN_VALUES = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};
/*
Monte Carlo Simulation for 🎲 🎲
Example output for 1,000,000 simulations
2: ⬜⬜⬜
3: ⬜⬜⬜⬜⬜
4: ⬜⬜⬜⬜⬜⬜⬜
5: ⬜⬜⬜⬜⬜⬜⬜⬜⬜
6: ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜
// definitions
const toLines = logs => logs.split("\n");
const notEmpty = line => line.trim();
const toParts = line => line.split(" ");
const toLogEntry = parts => ({
path: parts[parts.length - 2],
status: parseInt(parts[parts.length - 1])
});
@vvgomes
vvgomes / pyramid.js
Last active February 25, 2022 15:52
/*
height = 6
.....∆
....∆∆∆
...∆∆∆∆∆
..∆∆∆∆∆∆∆
.∆∆∆∆∆∆∆∆∆
∆∆∆∆∆∆∆∆∆∆∆
/*
[1] => 1
[1, 2]
[4, 5] => 1, 2, 5, 4
[1, 2, 3]
[4, 5, 6]
[7, 8, 9] => 1, 2, 3, 6, 9, 8, 7, 4, 5
function palindrome(word) {
if (word.length < 2) return true;
const lastIndex = word.length - 1;
const indexBeforeLast = word.length - 2;
return word[0] == word[lastIndex] && palindrome(word.substr(1, indexBeforeLast));
}
console.log("empty:", palindrome(""));
import { curry, map, compose } from "ramda";
export const composeEach = curry((fs, g) =>
map(f => compose(g, f), fs)
);

CQRS & REST

Assuming:

CQRS will tell you to divide your application in two major architectural components: commands & queries. A command represents an user intent - all changes in the state of the application should be initiated exclusively by commands. Queries, on the other hand, represent questions an user can ask about the application state.

When it comes to exposing a REST-like API, it is important that a CQRS application makes it explicit the separation between commands and queries, so that clients can dynamically build task-based user interfaces. Assuming a JSON over HTTP API, that explicit separation could be accomplished by exposing commands as resources.

Flip Function in Clojure

Recently, I found myself in need of a flip function in Clojure. Since I could not find anything in the official documentation, Stackoverflow, or Freenode, I came up with this:

(defn flip [f]
  (comp (partial apply f) reverse list))

Its behavior can be described like this (assuming Midje):