Skip to content

Instantly share code, notes, and snippets.

@relax-more
relax-more / MemoOf java.time.Instant.md
Created December 3, 2015 08:02
java Date --> Instant

java.time.Instant

Instant (java.time.Instant) Probably the best place to start with the java.time package is the Instant class. An Instant represents a point in time (similar to java.util.Date) with nanoseconds precision (unlike the old Date which has milliseconds precision). Representing a point in time using nanoseconds precision requires more space than a Long can provide, therefore the internal representation is composed of two Long fields, the first holds the number of seconds since (or before) the standard Java epoch and the other the number of nanoseconds of the last seconds (so never larger than 999,999,999). Let's start with obtaining an Instant instance and print its value:

refed by https://dzone.com/articles/java-8-apis-javautiltime

@relax-more
relax-more / unionFromWikipedia.c
Last active December 3, 2015 06:05
共用体使ったこと無いけど便利そう
#include <stdio.h>
#include <string.h>
union U /* 共用体Uを定義 */
{
double x;
int y;
char z[10]; /* int,double,char[10]のいずれかを格納できる */
};
@relax-more
relax-more / AreTest.java
Created November 9, 2015 12:04
how to assert Exception with TypeSafeMatcher
public class AreTest {
@Test
public void test_WithTypeSafeMatcher() throws Exception {
when(service.getAre()).thenThrow(ApiException.class);
thrown.expect(new TypeSafeMatcher<ApiException>() {
@Override
public void describeTo(Description description) {
description.appendText("expects EXPECTED_ERROR_CODE");
}
@Override
@relax-more
relax-more / AuthorService.java
Created November 5, 2015 08:21
use com.google.common.base.MoreObjects.MoreObjects.firstNonNull.
public class AuthorService {
public Author getOrDefault(String authorId, Author defaultAuthor) {
Author author = get(authorId); // get() is nullable method
return MoreObjects.firstNonNull(author, defaultAuthor);
}
}
pngcrush - Optimize PNG file (image) to Speed up WebSite
Read more: http://linuxpoison.blogspot.jp/2010/01/pngcrush-optimize-png-file-image-to.html#ixzz3qaibxYxI
http://linuxpoison.blogspot.jp/2010/01/pngcrush-optimize-png-file-image-to.html
@relax-more
relax-more / After.java
Last active October 13, 2015 09:11
How to use Stream.map()
static final Ordering<Banner> RANDOM_ORDER = Ordering.natural()
.onResultOf((Banner b) -> b.getWeight() * randomGenerator.nextDouble())
.reverse();
public List<BannerViewModel> getBanners(List<Banner> banners, final String language) {
final List<Banner> selectedList = RANDOM_ORDER.greatestOf(banners, MAX_SIZE);
return selectedList.stream().map(b ->
BannerViewModel.builder()
.id(b.getId())
.href(getHref(b, language))
@relax-more
relax-more / memo.MD
Last active October 9, 2015 07:33
Which is better HttpClient ?
@relax-more
relax-more / Sample.java
Created October 9, 2015 07:27
What is MockitoRule ?
public class ExampleTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private List list;
@Test
public void shouldDoSomething() {
https://research.preferred.jp/2011/10/tim-sort/