Skip to content

Instantly share code, notes, and snippets.

curl -XPUT 'http://localhost:9200/us/user/1?pretty=1' -d '
{
"email" : "john@smith.com",
"name" : "John Smith",
"username" : "@john"
}
'
curl -XPUT 'http://localhost:9200/gb/user/2?pretty=1' -d '
{
@wezhang
wezhang / patch nerd fonts.cmd
Created July 20, 2017 06:48
[Patch Nerd Fonts] Patch fonts with fontforge in windows
# Run in Administrator
d:\Programs\FontForgeBuilds\bin\fontforge.exe -script font-patcher "c:\windows\fonts\DejaVu Sans Mono for Powerline.ttf" -w -c
@wezhang
wezhang / mockHttpService.java
Last active July 26, 2017 02:46
[mock Http service with WireMock] Mock http service with stubfor in wiremock #wiremock
configureFor(mockUri.getHost(), mockedPort);
stubFor(request(action,
urlEqualTo(serviceUrl.substring(mockUri.resolve("/").toString().length() - 1)))
.willReturn(
aResponse()
.withStatus(statusCode)
.withBody(response.replaceAll("\\\\n", "\n"))));
@wezhang
wezhang / enum.java
Created July 27, 2017 08:02
[Java types] samples for basic types
public enum UserStatus {
PENDING,
ACTIVE,
INACTIVE,
DELETED;
}
public enum WhoisRIR {
ARIN("whois.arin.net"),
RIPE("whois.ripe.net"),
/**
* Retry observable subscription if timeout.
*
* For every retry it will wait delay + delayAmount so we wait more and more every retry.
*
* @param maxRetries number of retries
* @param delay milliseconds of wait between each try
* @param delayAmount delay + delayAmount
*/
class RetryAfterTimeoutWithDelay(val maxRetries: Int, var delay: Long, val delayAmount: Long = 100)
@wezhang
wezhang / phaser.java
Last active August 10, 2017 02:06
[Phaser for multi threads sync] The class Phaser is a multithreads sync helper class in Java #Phaser #sync
import java.util.concurrent.Phaser;
// Main thread
// Reset the debug process Phaser
debugProcessPhaser = new Phaser(1);
new Thread(() -> {
// new debug process start
debugProcessPhaser.register();
@wezhang
wezhang / avoid_null_check.java
Created August 10, 2017 02:51
[Avoid null check in Java chain call] Java 8 has Optional class can avoid null check in chain call.
Optional.of(new Outer())
.map(Outer::getNested)
.map(Nested::getInner)
.map(Inner::getFoo)
.ifPresent(System.out::println);
@wezhang
wezhang / IJ_background_task_indicator.java
Created August 23, 2017 07:39
[Intellij background task indicator enable] #intellij
Task.Backgroundable checkSshCertBackgroundTask = new Task.Backgroundable(
submitModel.getProject(), "Verify Authentication...", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
sleep(20 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
@wezhang
wezhang / tryParse.java
Created August 30, 2017 03:20
[Try parse int]
boolean tryParseInt(String value) {
try {
Integer.parseInt(value);
return true;
} catch (NumberFormatException e) {
return false;
}
}
@wezhang
wezhang / iso8601_date_parse.java
Last active September 1, 2017 02:33
[Java ISO 8601 parse] Only jdk function without joda-time
DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_DATE_TIME;
TemporalAccessor accessor = timeFormatter.parse("2015-10-27T16:22:27.605-07:00");
Date date = Date.from(Instant.from(accessor));
System.out.println(date);