Skip to content

Instantly share code, notes, and snippets.

View mikaelhg's full-sized avatar
🏠
Working from home

Mikael Gueck mikaelhg

🏠
Working from home
View GitHub Profile
@mikaelhg
mikaelhg / Sandbox.java
Last active August 29, 2015 14:03
PEG Sandbox
package io.mikael.peg;
import java.util.Arrays;
public class Sandbox {
public static void main(String[] args) {
System.out.printf("character('a', 'h').match(\"far\") = <%s>%n",
character('a', 'h').match("far"));
@mikaelhg
mikaelhg / LambdaConverter.java
Last active August 29, 2015 14:02
Playing around with ideas for easily readable bean or even JSON converters using Java 8 lambdas
package io.mikael.convert;
import java.util.ArrayList;
import java.util.List;
import java.util.function.*;
public class LambdaConverter {
public static class Foo {
public String getA() { return "A"; }
@mikaelhg
mikaelhg / snippet.java
Created April 30, 2014 16:02
Java 8 lambda streams come in handy when parsing HTML with Jsoup and Lombok @builders
Document doc = Jsoup.parse(...);
doc.select("form#login").stream()
.map(e -> e.attr("action"))
.map(action -> find(action, LINK_ID_PATTERN).group(1))
.filter(Objects::nonNull)
.findFirst()
.ifPresent(builder::id);
content.select("div#datePublished").stream()
@mikaelhg
mikaelhg / ruby-inspect-parser.rb
Last active August 29, 2015 14:00
A Parslet parser for a random Ruby .inspect dump
#!/usr/bin/env ruby
require 'parslet'
require 'pp'
require 'awesome_print'
class InspectParser < Parslet::Parser
# TOKENS
@mikaelhg
mikaelhg / OptionalDemo.java
Created April 25, 2014 20:34
Lambda / Optional demos
private static <T> boolean fillIf(final Supplier<T> supplier, final Consumer<T> consumer) {
return fillIf(supplier, consumer, null);
}
private static <T> boolean fillIf(final Supplier<? extends T> supplier, final Consumer<T> consumer, final Consumer<Exception> exceptionHandler) {
try {
final T data = supplier.get();
if (null == data) {
return false;
}
@mikaelhg
mikaelhg / check_clock.c
Created February 16, 2014 07:43
Run JDK check for Linux clock monotonicity manually
// gcc check_clock.c -ldl -o check_clock
// ripped from http://hg.openjdk.java.net/jdk8u/jdk8u-gate/hotspot/file/9c2ddd17626e/src/os/linux/vm/os_linux.cpp
#include <dlfcn.h>
#include <stdio.h>
#include <linux/time.h>
typedef int clockid_t;
int main(int argc, const char* argv[]) {
@mikaelhg
mikaelhg / gist:5747171
Created June 10, 2013 07:57
socat port forward
sudo socat TCP4-LISTEN:80,fork TCP4:localhost:9000
@mikaelhg
mikaelhg / etc_apt_apt.conf.d_99fastdownload
Created April 28, 2013 19:57
Ubuntu automatic mirror configuration and fast package download for Vagrant guests
Acquire::http::Pipeline-Depth "15";
@mikaelhg
mikaelhg / HazelTest.java
Last active December 16, 2015 14:09
Hazelcast vs. Infinispan
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@mikaelhg
mikaelhg / precise_sources_fi.list
Created April 11, 2013 10:46
Precise apt-get sources.list for Finnish mirrors
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://fi.archive.ubuntu.com/ubuntu/ precise main restricted
deb-src http://fi.archive.ubuntu.com/ubuntu/ precise main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://fi.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://fi.archive.ubuntu.com/ubuntu/ precise-updates main restricted