Skip to content

Instantly share code, notes, and snippets.

View mingliangguo's full-sized avatar

Mingliang mingliangguo

View GitHub Profile
@mingliangguo
mingliangguo / spring-heathcheck.java
Last active July 15, 2018 02:56
spring-heathcheck
@Component
public class CassandraHealthCheck implements HealthIndicator {
@Autowired
private CassandraProperties properties;
public Health health() {
boolean hasKeyspace = false;
try {
@mingliangguo
mingliangguo / apple.script
Created May 31, 2018 03:15
macOS-productive
tell application "PopClip" to appear
@mingliangguo
mingliangguo / async-schedule.java
Created May 24, 2018 01:23
[Java Async] sample async #java
// https://dzone.com/articles/asynchronous-timeouts
private static final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(
1,
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("failAfter-%d")
.build());
public static <T> CompletableFuture<T> failAfter(Duration duration) {
@mingliangguo
mingliangguo / mockito.java
Last active June 5, 2018 20:33
mockito #test #mock
when(someMock.someMethod()).thenAnswer(new Answer() {
private int count = 0;
public Object answer(InvocationOnMock invocation) {
if (count++ == 1)
return 1;
return 2;
}
@mingliangguo
mingliangguo / downgrad-node.sh
Created April 30, 2018 19:05
downgrade node to a specific version
$ brew install node@8 // just install node8 side by side
$ brew unlink node // unlink old one
$ brew link node@8 // link node version 8
@mingliangguo
mingliangguo / emoji.js
Created April 2, 2018 03:04
emoji converter
// convert emoji character to unicode key sequences
var getCode = emoji => emoji.split('').map(c => c.codePointAt(0).toString(16)).join('-');
var unifiedToEmoji = unified => {
return unified
.split('-')
.map(hex => parseInt(hex, 16))
.map(hex => String.fromCodePoint(hex))
.join('');
};
\n
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
\n
@mingliangguo
mingliangguo / gradle recipe
Last active February 16, 2017 17:34
gradle recipe
# You can tell Gradle to re-download some dependencies in the build script by flagging the dependency as 'changing'. Gradle will then check for updates every 24 hours, but this can be configured using the resolutionStrategy DSL. I find it useful to use this for for SNAPSHOT or NIGHTLY builds.
# refer to [link](http://stackoverflow.com/questions/13565082/how-can-i-force-gradle-to-redownload-dependencies)
# https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
@mingliangguo
mingliangguo / disable_SSL_and_hostname_verification.java
Last active March 14, 2025 07:38
disable SSL and host name verification for apache httpclient
try {
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
}
@mingliangguo
mingliangguo / pre-commit
Created January 24, 2017 15:40 — forked from mebibou/pre-commit
JSHint and JSCS pre-commit hook
#!/bin/sh
# pre-commit git hook.
files=$(git diff --cached --name-only --diff-filter=ACMR -- \*.js **/*.js)
pass=true
if [ "$files" != "" ]; then
for file in ${files}; do