Skip to content

Instantly share code, notes, and snippets.

View michael-simons's full-sized avatar

Michael Simons michael-simons

View GitHub Profile
@michael-simons
michael-simons / Java8RandomStream.java
Last active August 29, 2015 13:57
Create a stream of random doubles
Random random = new Random(System.currentTimeMillis());
random.doubles().limit(10).forEach(x -> {
// hogehoge
});
@michael-simons
michael-simons / gist:f10d29a09eabf141ed54
Last active August 29, 2015 14:01
Grouping map entries with Java 8 v1
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 August 29, 2015 14:01
Grouping map entries with Java 8 v2
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)
)
List<String> converted = Files.lines(file, StandardCharsets.UTF_8)
.map(line -> line.replace("<credentialsId>oldID</credentialsId>", "<credentialsId>newID</credentialsId>"))
.collect(Collectors.toList());
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 December 21, 2011 08:43
Enables automatic embedding of pictures from dailyfratze.de through oEmbed
<?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 December 21, 2011 08:45
Enables automatic embedding of twitter updates through oembed
<?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);
?>
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 October 20, 2012 20:13
Sicherer MySQL Dump mehrerer Datenbanken
mysqldump -uroot -pblah --opt --routines --add-drop-database --default-character-set=utf8 --create-options --databases db1 db2 usw | bzip2 > backup.sql.bz2
@michael-simons
michael-simons / jquery.fancybox-1.3.4.with_touch_support.js
Created December 12, 2012 19:57
This is a patched version of jQuery Fancybox (http://fancybox.net) that supports touch events (wipe left / right). You need http://modernizr.com and http://www.netcu.de/jquery-touchwipe-iphone-ipad-library to use this.
/*
* FancyBox - jQuery Plugin
* Simple and fancy lightbox alternative
*
* Examples and documentation at: http://fancybox.net
*
* Copyright (c) 2008 - 2010 Janis Skarnelis
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
*
* Version: 1.3.4 (11/11/2010)