Skip to content

Instantly share code, notes, and snippets.

View stoan's full-sized avatar

Siya Sosibo stoan

View GitHub Profile
@adhipg
adhipg / countries.sql
Created January 12, 2012 11:41
Sql dump of all the Countries, Country Codes, Phone codes.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
@eugenp
eugenp / PaginationDiscoverabilityListener.java
Last active March 24, 2022 13:07
Pagination with REST - the Discoverability Listener full
package org.baeldung.web.hateoas;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
import com.google.common.base.Preconditions;
@johntdyer
johntdyer / sendsqs.js
Last active August 2, 2022 13:12
AWS Lambda sample: Send received events to SQS as Message
// PUT YOUR AWS ACCOUNT NUMBER HERE
var AWS_ACCOUNT_ID= '12345';
// PUT YOUR SQS QUEUE NAME HERE
var AWS_SQS_QUEUE_NAME='catch-dlr-dyer-testing';
var QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/' + AWS_ACCOUNT_ID + '/' + AWS_SQS_QUEUE_NAME;
var AWS = require('aws-sdk');
var sqs = new AWS.SQS({region : 'us-east-1'});
@luizrobertofreitas
luizrobertofreitas / spring-boot-utc-timezone
Created June 5, 2017 15:06
Setting UTC timezone spring-boot
@SpringBootApplication
public class Application {
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
@Allan-Gong
Allan-Gong / flatmap_optionals.java
Created January 18, 2018 05:01
Options to flatMap a list of Optionals in Java8
// Ways to transform List<Optional<T>> to List<T> (excluding empty ones)
// 1. Using filter()
List<String> filteredList = listOfOptionals.stream()
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
// 2. Using flatMap()
List<String> filteredList = listOfOptionals.stream()
@Toparvion
Toparvion / HOWTO.md
Last active May 23, 2024 02:35
JUnit test for conditional Spring Boot bean registration (@ConditionalOnProperty)

Problem

Suppose you have two classes that should be registered with Spring context exclusively, e.g. only one of the beans must exist in the context at any time based on some boolean property value. Of course you can do it by adding explicit if condition into your @Configuration class. But if the classes have no common interface it may be quite cumbersome. As an alternative you can use @ConditionalOnProperty annotation on your classes, e.g.:

@Service
@ConditionalOnProperty(name = "use-left-service", havingValue = "true", matchIfMissing = false)
public class LeftService
@dblevins
dblevins / Dates.java
Last active May 28, 2022 20:02
Works for Java 8 and above. For Java 7 and before, see this legacy version https://gist.github.com/dblevins/03df3cd5eb12f2da05997eef80ac4eca
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* This pattern has the following benefits:
*
* - Date formats are referenced as a strong type
* - Code completion on patterns