Skip to content

Instantly share code, notes, and snippets.

View hanbei's full-sized avatar

Florian Schulz hanbei

View GitHub Profile
@hanbei
hanbei / json_format.sh
Created July 9, 2019 07:03
Format a json file with jq in place
#!/bin/bash
tmpf=$(mktemp --tmpdir=$(dirname $1) -t)
jq . "$1" > "$tmpf"
mv -f "$tmpf" "$1"
@hanbei
hanbei / clean.sh
Created July 5, 2019 12:14
Parse json response from wiremock recording
jq .request.bodyPatterns[].equalToJson {} | sed 's/\\"/"/g' - | sed 's/\\"/\"/g' - | sed 's/^"//g' - | sed 's/"$//g'
@hanbei
hanbei / HashCodeTest.java
Created February 15, 2018 12:38
ImmutableMap hasCode Bug
public void testHashCode() {
ImmutableMap<String, Object> f1 = ImmutableMap.of("test", "test", "test2", "test2");
ImmutableMap<String, Object> f2 = ImmutableMap.of("test2", "test2", "test3", "test3");
assertFalse(f1.equals(f2));
int hcf1 = f1.hashCode();
int hcf2 = f2.hashCode();
assertThat(hcf1, not(hcf2));
}
@hanbei
hanbei / Dockerfile
Last active February 2, 2018 13:06
NPM docker local dev environment
FROM node:8.9.4-alpine
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN mkdir -p /opt/workspace
WORKDIR /opt/workspace
VOLUME /opt/workspace
@hanbei
hanbei / RandomUrlGenerator.java
Created January 10, 2018 12:47
RandomUrlGenerator
import org.apache.commons.lang3.RandomStringUtils;
import java.security.SecureRandom;
import java.util.Random;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.joining;
public final class RandomUrlGenerator {
package rxsearcher.searcher.kelkoo;
import com.google.common.util.concurrent.Uninterruptibles;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.disposables.Disposable;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
@hanbei
hanbei / mongodb.sh
Created October 12, 2017 12:30
MongoDB docker start/stop script
#!/bin/bash
# sudo docker run -d -p 27017:27017 --net static_internal --ip 201.1.1.2 --name mongodb mongo
start() {
sudo docker start mongodb
}
stop() {
sudo docker stop mongodb
@hanbei
hanbei / Person.java
Created August 8, 2017 09:04
Person StepBuilder in Java 8
public static class Person {
String name;
int age;
private Person(String name, int age) {
this.name = name;
this.age = age;
}
static PersonWaitingForName create() {
@hanbei
hanbei / JsonObjectBuilder.java
Last active January 10, 2018 12:49
JsonObjectBuilder
package com.foxydeal.fdcinput;
/**
* Created by fschulz on 17.12.2015.
*/
public class JsonObjectBuilder {
public static final String QUOTE = "\"";
private StringBuilder jsonString;
private int propertyCounter = 0;
@hanbei
hanbei / useful git commands
Last active January 4, 2017 13:02
Prune local branches
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
# fetch all repos
find . -maxdepth 1 -type d -exec echo {} \; -exec git --git-dir={}/.git --work-tree=$PWD/{} fetch \;
# prune all repos
find . -maxdepth 1 -type d -exec echo {} \; -exec git --git-dir={}/.git --work-tree=$PWD/{} remote prune origin \;