Skip to content

Instantly share code, notes, and snippets.

Michael Simons michael-simons

Block or report user

Report or block michael-simons

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@michael-simons
michael-simons / Java8RandomStream.java
Last active Aug 29, 2015
Create a stream of random doubles
View Java8RandomStream.java
Random random = new Random(System.currentTimeMillis());
random.doubles().limit(10).forEach(x -> {
// hogehoge
});
@michael-simons
michael-simons / gist:f10d29a09eabf141ed54
Last active Aug 29, 2015
Grouping map entries with Java 8 v1
View gist:f10d29a09eabf141ed54
public static Map<LocalDate, Integer> summarizePeriodsOld(final List<Bike> bikes, final Predicate<Map.Entry<LocalDate, Integer>> entryFilter) {
return bikes.stream()
.filter(Bike::hasMilages)
.flatMap(bike -> bike.getPeriods().entrySet().stream())
.filter(Optional.ofNullable(entryFilter).orElse(entry -> true))
.collect(
HashMap::new,
(map, period) -> {
map.merge(period.getKey(), period.getValue(), (val1, val2) -> val1 + val2);
},
@michael-simons
michael-simons / gist:793f77e8b98feebe3984
Last active Aug 29, 2015
Grouping map entries with Java 8 v2
View gist:793f77e8b98feebe3984
public static Map<LocalDate, Integer> summarizePeriods(final List<Bike> bikes, final Predicate<Map.Entry<LocalDate, Integer>> entryFilter) {
return bikes.stream()
.filter(Bike::hasMilages)
.flatMap(bike -> bike.getPeriods().entrySet().stream())
.filter(Optional.ofNullable(entryFilter).orElse(entry -> true))
.collect(
Collectors.groupingBy(
Map.Entry::getKey,
Collectors.reducing(0, Map.Entry::getValue, Integer::sum)
)
View gist:5830e4b64fb77713bb9a
List<String> converted = Files.lines(file, StandardCharsets.UTF_8)
.map(line -> line.replace("<credentialsId>oldID</credentialsId>", "<credentialsId>newID</credentialsId>"))
.collect(Collectors.toList());
@michael-simons
michael-simons / gist:861863
Created Mar 9, 2011
Configuration for replacing Spring 3 mvc:annotation-driven
View gist:861863
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
<bean id="pathMatcher" class="ac.simons.utils.ExtendedAntPathMatcher" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
<property name="useDefaultSuffixPattern" value="true" />
<property name="pathMatcher" ref="pathMatcher" />
</bean>
View ExtendedAntPathMatcher.java
package ac.simons.utils;
import java.util.Comparator;
/**
* @author michael.simons, 2011-02-15
*/
public class ExtendedAntPathMatcher implements PathMatcher {
private final AntPathMatcher delegate = new AntPathMatcher();
@michael-simons
michael-simons / enable_dailyfratze_oembed.php
Created Dec 21, 2011
Enables automatic embedding of pictures from dailyfratze.de through oEmbed
View enable_dailyfratze_oembed.php
<?php
/*
Plugin Name: Enable dailyfratze.de oEmbed
Description: Enables automatic embedding of pictures from dailyfratze.de through oEmbed
Author: Michael Simons
Version: 1.0
Author URI: http://michael-simons.eu
*/
// Profile
wp_oembed_add_provider('#https?://dailyfratze\.(?:de|com)/([a-z]+\w*)#i', 'https://dailyfratze.de/app/oembed.json', true);
@michael-simons
michael-simons / enable_twitter_oembed.php
Created Dec 21, 2011
Enables automatic embedding of twitter updates through oembed
View enable_twitter_oembed.php
<?php
/*
Plugin Name: Enable Twitter oEmbed
Description: Enables automatic embedding of twitter updates through oembed
Author: Michael Simons
Version: 1.0
Author URI: http://michael-simons.eu
*/
wp_oembed_add_provider('#https?://twitter.com/\#!/[a-z0-9_]{1,20}/status/\d+#i', 'https://api.twitter.com/1/statuses/oembed.json', true);
?>
View JooqSpringBootConfig.java
package de.enerko.ensupply.config;
import org.jooq.ConnectionProvider;
import org.jooq.ExecuteListenerProvider;
import org.jooq.SQLDialect;
import org.jooq.TransactionProvider;
import org.jooq.impl.DefaultConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.jooq.RecordMapperProvider;
@michael-simons
michael-simons / gist:3924630
Created Oct 20, 2012
Sicherer MySQL Dump mehrerer Datenbanken
View gist:3924630
mysqldump -uroot -pblah --opt --routines --add-drop-database --default-character-set=utf8 --create-options --databases db1 db2 usw | bzip2 > backup.sql.bz2
You can’t perform that action at this time.