Skip to content

Instantly share code, notes, and snippets.

View vvgomes's full-sized avatar
🦖

Vinicius Vieira Gomes vvgomes

🦖
View GitHub Profile

Keybase proof

I hereby claim:

  • I am vvgomes on github.
  • I am vvgomes (https://keybase.io/vvgomes) on keybase.
  • I have a public key whose fingerprint is 7AD1 F498 2E98 BC63 5FD4 909B 12F9 2C54 E7C6 B118

To claim this, I am signing this object:

@vvgomes
vvgomes / foo.js
Last active August 10, 2021 18:10
Ramda vs Lodash
var _ = require("lodash");
var R = require("ramda");
var companies = [
{ name: "tw", since: 1993 },
{ name: "pucrs", since: 1930 },
{ name: "tw br", since: 2009 }
];
var r1 = _(companies).chain()

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):

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.

import { curry, map, compose } from "ramda";
export const composeEach = curry((fs, g) =>
map(f => compose(g, f), fs)
);
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(""));
/*
[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
@vvgomes
vvgomes / pyramid.js
Last active February 25, 2022 15:52
/*
height = 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])
});
/*
Monte Carlo Simulation for 🎲 🎲
Example output for 1,000,000 simulations
2: ⬜⬜⬜
3: ⬜⬜⬜⬜⬜
4: ⬜⬜⬜⬜⬜⬜⬜
5: ⬜⬜⬜⬜⬜⬜⬜⬜⬜
6: ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜