Skip to content

Instantly share code, notes, and snippets.

@Sam-Kruglov
Sam-Kruglov / REST_response.json
Created January 11, 2018 11:25
Projection GET localhost:8080/users/1
{
"username": "jsmith",
"_links": {
"self": {
"href": "http://localhost:8080/users/1"
},
"user": {
"href": "http://localhost:8080/users/1{?projection}",
"templated": true
},
@Sam-Kruglov
Sam-Kruglov / UserController.java
Last active January 13, 2018 11:35
JsonFilter with broken links
@RepositoryRestController
public class UserController {
private final UserRepository userRepository;
private final RepositoryEntityLinks links;
public UserController(final UserRepository userRepository,
final RepositoryEntityLinks links) {
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 13, 2018 11:53
JsonFilter with broken links
{
"firstName": "John",
"links": [
{
"rel": "self",
"href": "http://localhost:8080/users/1?fields=firstName"
},
{
"rel": "user",
"href": "http://localhost:8080/users/1{?projection}"
@Sam-Kruglov
Sam-Kruglov / UserController.java
Last active January 13, 2018 12:16
JsonFilter without links simple
@RestController
public class UserController {
private final UserRepository userRepository;
public UserController(final UserRepository userRepository) {
this.userRepository = userRepository;
}
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 13, 2018 12:05
JsonFilter without links username
{
"username": "jsmith"
}
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Created January 13, 2018 12:06
JsonFilter without links username,firstName
{
"username": "jsmith",
"firstName": "John"
}
@Sam-Kruglov
Sam-Kruglov / RestConfig.java
Created January 13, 2018 12:21
JsonFilter
@Component
public class RestConfig extends RepositoryRestConfigurerAdapter {
@Override
public void configureJacksonObjectMapper(final ObjectMapper objectMapper) {
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
}
}
@Sam-Kruglov
Sam-Kruglov / UserController.java
Last active January 13, 2018 12:24
JsonFilter without links
@RepositoryRestController
public class UserController {
private final UserRepository userRepository;
public UserController(final UserRepository userRepository) {
this.userRepository = userRepository;
}
@Sam-Kruglov
Sam-Kruglov / RepeatedWordFinder.java
Created June 7, 2018 05:47
Finds the most repeated word in a text
public class RepeatedWordFinder {
public static void main(String[] args) {
System.out.println(findTheMostRepeatedWord("House, House, House, Dog, Dog, Dog, Dog, cat,cat"));
}
public static String findTheMostRepeatedWord(String s) {
return Arrays.stream(s.toLowerCase().trim().split("[\\n\\t\\r.,;:!?()]"))
@Sam-Kruglov
Sam-Kruglov / FileTimeChecker.java
Created July 2, 2018 13:07
Check reading the last modified time from a file
class FileTimeChecker{
public static void main(String[] args) throws IOException, URISyntaxException {
Path path = Files.write(Paths.get("/hey.txt"), "hey".getBytes());
File file = new File("/hey.txt");
Instant fileInstant = Instant.ofEpochMilli(file.lastModified());
System.out.println("fileInstant: " + fileInstant);