Skip to content

Instantly share code, notes, and snippets.

app.post('/customers/:customerId/orders/', (req, res) => {
if (req.body.items.length === 0) {
res.status(400).end()
} else {
MongoClient.connect(url, function (err, client) {
if (err) {
console.error(err)
}
const db = client.db(dbName)
const collection = db.collection('orders')
@carlosmaniero
carlosmaniero / updateStatus.js
Created February 19, 2019 03:51
It shows how orders without status are treated by the application: It is part of the "Agile practices on Legacy code"
const updateStatus = (order, newStatus) => {
if (order.status === undefined) {
order.status = 'ORDERED'
}
//...
}
@carlosmaniero
carlosmaniero / Elm.hs
Last active October 30, 2017 13:19
Elm architecture in Haskell: A study case
data Model = Model
{ name :: String
, gender :: String
, loading :: Bool
, homeworld :: String
} deriving (Show)
data PersonResponse = PersonResponse
{ personName :: String
@carlosmaniero
carlosmaniero / arrow.js
Created October 24, 2017 16:52
Arrow functions is not a syntax sugar for functions
const withFunction = {
myOwnProp: 42,
myOwnFunc: function () {
return this.myOwnProp
}
}
const withArrow = {
myOwnProp: 42,
myOwnFunc: () => {
import java.util.HashMap;
import java.util.Map;
class Fair {
private final int quantity;
Fair(int quantity) {
this.quantity = quantity;
}
import java.util.stream.Stream;
public class ReduceSum {
public static void main(String args[]) {
int sum = Stream.of(1, 2, 3, 4, 5)
.reduce(0, (acc, item) -> acc + item);
System.out.println(sum);
}
}
import java.util.HashMap;
import java.util.Map;
public class StreamMap {
public static void main(String args[]) {
Map<String, Integer> fruits = new HashMap<>();
fruits.put("Banana", 7);
fruits.put("Apple", 2);
fruits.put("Kiwi", 1);
import java.util.stream.Stream;
public class StreamForEach {
public static void main(String args[]) {
System.out.println("Fruit List:");
Stream.of("Banana", "Apple", "Kiwi")
.forEach(System.out::println);
}
}
public class LambdaExpression {
public static void main(String args[]) {
TouchMe touchMe = new TouchMe(System.out::println);
touchMe.touch(); // 1
touchMe.touch(); // 2
touchMe.touch(); // 3
touchMe.touch(); // 4
touchMe.touch(); // 5
}
public class LambdaExpression {
public static void main(String args[]) {
TouchMe touchMe = new TouchMe(times -> System.out.println(times));
touchMe.touch(); // 1
touchMe.touch(); // 2
touchMe.touch(); // 3
touchMe.touch(); // 4
touchMe.touch(); // 5
}