Skip to content

Instantly share code, notes, and snippets.

val combinationsLetters = (for {
(i, idi) <- List("A", "B", "C", "D", "E").zipWithIndex
(j, idj) <- List("A", "B", "C", "D", "E").zipWithIndex.take(idi)
(k, _) <- List("A", "B", "C", "D", "E").zipWithIndex.take(idj)
} yield (i, j, k))
val combinationsNumbers = (for {
(i, idi) <- List("1", "2", "3").zipWithIndex
(j, _) <- List("1", "2", "3").zipWithIndex.take(idi)
} yield (i, j))
SELECT
(data->'backofficeInformation'->'customerNumber')::int,
identities->'countryCode'
FROM customers
cross join lateral jsonb_array_elements(data->'personalInformation'->'identities') identities
WHERE (data->'backofficeInformation'->'customerNumber')::int = 900198808
and (identities->>'isTaxCountry')::boolean = true
--same as
List(("A", 1), ("B", 2)).map(second)
def second[A, B](a: (A, B)) = (a._2, a._1)
def second2[A, B](a: (A, B)) = a match {
case (x, y) => (y, x)
}
def second3[A, B]: (A, B) => (B, A) = { case(a, b) => (b, a) }
def second4[A, B]: (A, B) => (B, A) = { case(a, b) => b -> a }
@renanreismartins
renanreismartins / VavrOnSuccess.java
Created November 30, 2019 22:32
Trying to understand Try vavr api
@Test
public void test() {
loadName(1)
.onSuccess(n -> log(format("onSuccess before recovery: %s", n)))
.andThen(n -> log(format("and then log this before recovery: %s", n)))
.onFailure(e -> log("error before recovery"))
.recoverWith(IllegalArgumentException.class, e -> loadNameFromFallback())
.onSuccess(n -> log(format("onSuccess after recovery: %s", n)))
.onSuccess(n -> log(format("another onSuccess: %s", n)))
.andThen(n -> log(format("and then log this after recovery: %s", n)))
List(1, 2, 3, 4, 5) match {
case (a1 @ 1) :: (a2 @ 2 ):: c :: _ => c
case List(a1 @ 1, a2 @ 2, c) => c
case _ => "no"
}
sealed trait State
case class WithOffer(offer: Offer) extends State
#!/usr/bin/env python
import sys
import re
import csv
p = re.compile(ur'[^\s+\,\.\!\?\:\;\"\(\)\<\>\#\$\=\-\/]+')
reader = csv.reader(sys.stdin, delimiter='\t')
next(reader, None) # skip headers
for line in reader:
http://content.udacity-data.com/course/hadoop/forum_data.tar.gz
(defn letras-faltantes [palavra acertos]
(remove (fn [letra]
(contains? acertos (str letra))) palavra))
(defn acertou-a-palavra-toda? [palavra acertos]
(empty? (letras-faltantes palavra acertos)))
(defn le-letra! [] (read-line))
(defn acertou-chute? [letra palavra]
public static void main(String[] args) {
Optional<String> mapped = getMerchantOrderIdFromUrl("haveId").map(orderId -> {
return orderId + " mapped";
});
System.out.println(mapped);
Optional<Optional<String>> merchant = getMerchantOrderIdFromUrl("haveId").map(orderId -> {
return getMerchant(orderId);
});