Skip to content

Instantly share code, notes, and snippets.

View gicappa's full-sized avatar
🏠
Working from home

Gian Carlo Pace gicappa

🏠
Working from home
  • Hyland / Alfresco
  • Gallarate, VA
  • X @gicappa
View GitHub Profile
@gicappa
gicappa / 1-Emapp.java
Last active March 4, 2023 15:45
Hexagonal Architecture
package application;
/* ... */
// Application level is the holder of primary drivers
// This is actually the specific implementation of the application server
// (SparkJava in this case)
public class Emapp implements Runnable {
private final Mapper mapper;
/**
* Reads only valid amount from standard output and returns
* it to the caller.
*
* @param prompt to be shown to the user to mark where to input
* @param min amount allowed
* @param max amount allowed
* @return the valid amount
*/
public BigDecimal inputBigDecimalValue(String prompt, BigDecimal min, BigDecimal max) {
package gk;
import static java.math.BigDecimal.ZERO;
import java.math.BigDecimal;
import java.util.Scanner;
public class AmountParser {
Scanner sc = new Scanner(System.in);
@gicappa
gicappa / total_price.rs
Created April 20, 2018 23:07
Total price in three sauces...
fn total_price(&self, shopping_list: &[&str]) -> Option<f32> {
let mut total = 0.0;
for item in shopping_list {
if self.price(item) == None {
return None;
}
total += self.price(item).unwrap();
}
Some(total)
}
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class SecureMessage {
private final String key;
@gicappa
gicappa / labelled_break.txt
Created May 16, 2016 10:44
Labelled break number in JDK Std Lib
com/sun/imageio/plugins/png/PNGImageReader.java: break loop;
com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java: break find;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_1;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_2;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_3;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_4;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_5;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_6;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_7;
com/sun/jmx/snmp/IPAcl/Parser.java: break label_8;
@gicappa
gicappa / yay
Created February 28, 2016 20:23
yay!
@gicappa
gicappa / FizzBuzz.java
Last active August 29, 2015 14:18
FizzBuzz with java 8
import java.util.Arrays;
public class FizzBuzz {
public static String compute(Integer number) {
return Arrays.stream(Multipliers.values())
.filter(m -> (number % m.multiple == 0))
.map(Enum::name)
.reduce((s, r) -> s + r)
@gicappa
gicappa / CurrentUser.java
Last active August 29, 2015 14:03
downcasting
class CurrentUser extends User {
public String who() {
return "who - CurrentUser class!";
}
}
require "test/unit"
class VarianceTest < Test::Unit::TestCase
def test_it_should_compute_the_average_out_of_an_array
assert_equal(50, [40, 30, 50, 80].average)
end
def test_it_should_compute_variance_out_of_an_array
assert_equal(350, [40, 30, 50, 80].variance)