This file contains 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
public static void main(String[] args) throws JsonProcessingException { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
objectMapper.registerModule(new JavaTimeModule()); | |
System.out.println(objectMapper.writeValueAsString(new Entity())); | |
} | |
static class Entity { | |
ZonedDateTime time = ZonedDateTime.now(); | |
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ") |
This file contains 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 'set' | |
#h = Hash.new { |hash, key| hash[key] = [] } | |
h = Hash.new { |hash, key| hash[key] = Set.new } | |
h[:key] << "value 1" | |
h[:key] << "value 2" | |
h[:key2] << 1 | |
puts h | |
puts h[:key].class.name |
This file contains 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
a = [1, 2, 3, 4] | |
puts a.inject(:+) | |
puts a.inject{|sum, x| sum + x} | |
b = ["1", "2"] | |
c = b.map { |e| e.to_i } |
This file contains 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
sum = -> (a, b) {puts a + b} | |
sum.call(1 , 2) | |
def block1 | |
lambda { return 100}.call | |
return :lambda | |
end | |
def block2 |
This file contains 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
book_params = {price: 100, isbn: 100} | |
puts book_params.class.name | |
puts p.inspect | |
class Book | |
def initialize(book_params) | |
if (book_params.instance_of? Hash) | |
book_params.each do |k, v| |
This file contains 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
# force ending lines LF | |
* text eol=lf |
This file contains 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; | |
import java.util.Comparator; | |
import java.util.List; | |
public class Comparings { | |
public static void main(String[] args) { | |
List<User> list = Arrays.asList(new User("a"), new User("b"), new User(""), new User(null)); | |
// | |
// list.sort((l, r) -> Comparator.nullsFirst(Comparator.nullsFirst(Comparator.naturalOrder())).compare(l.name, | |
// r.name)); |
This file contains 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
public class RandomPasswordGenerator { | |
private RandomPasswordGenerator() { | |
} | |
private static final char[] LOWERCASES = createCharArray('a', 'z'); | |
private static final char[] UPPERCASES = createCharArray('A', 'Z'); | |
private static final char[] DIGITS = createCharArray('0', '9'); | |
private static final SecureRandom RANDOM = new SecureRandom(); |
This file contains 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
private static final ObjectMapper objectMapper = new ObjectMapper() | |
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | |
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false).setSerializationInclusion(Include.NON_NULL) | |
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); | |
static { | |
objectMapper.getSerializerProvider().setNullKeySerializer(new NullKeySeriliazer()); | |
objectMapper.setVisibility(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() | |
.withFieldVisibility(JsonAutoDetect.Visibility.ANY).withGetterVisibility(JsonAutoDetect.Visibility.NONE) | |
.withSetterVisibility(JsonAutoDetect.Visibility.NONE) |
This file contains 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
scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/ | |
scp -i xxx-dev.pem ec2-user@dev.xxx.com:/var/log/xxx/xxx-user.log /home/toan/xxx-user.log |
OlderNewer