Skip to content

Instantly share code, notes, and snippets.

@juniorgarcia
juniorgarcia / every.js
Created December 9, 2021 11:47
Array.every e Array.some
/**
* Arrays tem um método para avaliar se todos os itens
* correspondem a uma condição: o método "every"
*
* O argumento que ele aceita é uma função que recebe um item do array por
* iteração, e, caso essa função retorne `truthy` para todos os elementos,
* Array.every retorna `true`, confirmando que todos os itens do seu array
* correspondem a essa condição.
*
* Vamos fazer um exercício: dado um array de números inteiros, verifique se
@juniorgarcia
juniorgarcia / log-proxy.js
Last active December 8, 2021 11:20
JS Proxy
const person = {
name: 'John Doe',
age: 42,
}
const logService = (message) => {
console.log(`INFO: ${message}`)
}
/**
@juniorgarcia
juniorgarcia / truthy-falsy-cheatsheet.js
Last active November 29, 2021 12:14
Truthy and falsy cheat sheet
// Cheat sheet para verificar quais valores são truthy e falsy
const vals = {
0: 0,
1: 1,
'Número negativo': -1,
true: true,
false: false,
null: null,
undefined: undefined,
@juniorgarcia
juniorgarcia / ClojureArticle-ClojureFunctionalExample.clj
Last active October 28, 2019 14:17
Clojure Article - Clojure functional programming example
(use '[clojure.string :only (join)])
(def names ["John" "Doe"])
(defn write-all-names [names]
(str (join ", " names) "."))
(println (write-all-names names))
; Johh, Doe.
@juniorgarcia
juniorgarcia / article-fp-js-example-1.1.js
Last active April 15, 2019 15:40
Artigo - Introdução a programação funcional com JavaScript - Exemplo 1.1
let numbers = [1, 5, 10];
const doubleValue = x => x * 2;
console.log("Map result: ", numbers.map(doubleValue)); // [2, 10, 20]
console.log("Numbers: ", numbers); // [1, 5, 10]
@juniorgarcia
juniorgarcia / article-fp-js-example-1.js
Last active April 15, 2019 15:41
Artigo - Introdução a programação funcional com JavaScript - Exemplo 1
let numbers = [1, 5, 10];
const doubleValue = x => x * 2;
console.log(numbers.map(doubleValue)); // [2, 10, 20]
@juniorgarcia
juniorgarcia / ClojureArticle-JSFunctionalExample.js
Last active October 28, 2019 14:19
Clojure Article - JavaScript functional programming example
let names = ["John", "Doe"];
let writeAllNames = (names) => names.join(', ') + '.';
console.log(writeAllNames(names));
// John, Doe.
@juniorgarcia
juniorgarcia / File globbing on Linux - practical examples.md
Last active February 13, 2016 18:33
Practical examples of how to use file globbing on Linux terminal

File globbing: Practical examples

For this examples, we will start creating the file structure. It's easier tounderstand. The $ character in the lines below don't need to be typed, they are just a hint like "hey, we're typing this on terminal".

To create the structure, do the following:

  1. Open your terminal and type: $ mkdir fileGlobbingLearning
  2. Open your folder: $ cd fileGlobbingLearning
@juniorgarcia
juniorgarcia / convertCases.js
Created December 7, 2015 02:47
Simple cases conversion using JavaScript
/* Using functional programming to convert cases */
function convertCase(text, callback) {
return callback.apply(null, [text]);
}
/* convert_to_snake_case */
function snakeCase(text) {
return text.replace(/\s+/g, '_').toLowerCase();
}