This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
module ActiveModel | |
# == Active Model Exclusion Validator | |
module Validations | |
class VersionValidator < EachValidator | |
def validate_each(record, attribute, value) | |
record.errors.add(attribute, "Non può essere vuoto") if value.nil? or value.strip.empty? | |
record.errors.add(attribute, "La version non è espressa nel formato 2.3.4") unless value =~ /\b\d+\.\d+\.\d+\b/ | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@712a95c7 | |
2 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@712a95c7 | |
3 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@712a95c7 | |
5 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration numeric_boolean -> org.hibernate.type.NumericBooleanType@563afc0c | |
7 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration true_false -> org.hibernate.type.TrueFalseType@5063b8c1 | |
8 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration yes_no -> org.hibernate.type.YesNoType@4a2c1b1c | |
10 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration byte -> org.hibernate.type.ByteType@7ec77512 | |
10 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CurrentUser extends User { | |
public String who() { | |
return "who - CurrentUser class!"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yay! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
OlderNewer