Skip to content

Instantly share code, notes, and snippets.

View alexcheng1982's full-sized avatar
๐ŸŽ‰
AI time

Fu Cheng alexcheng1982

๐ŸŽ‰
AI time
View GitHub Profile
@alexcheng1982
alexcheng1982 / createIndex.java
Created June 25, 2015 23:25
Elasticsearch - Create index when not exist
private void createIndex() {
boolean indexExists = client.admin().indices().prepareExists(INDEX_NAME).execute().actionGet().isExists();
if (!indexExists) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Index {} doesn't exist, create it now.", INDEX_NAME);
}
client.admin().indices().prepareCreate(INDEX_NAME).execute();
}
}
@alexcheng1982
alexcheng1982 / wechat_font.css
Created July 2, 2015 02:11
WeChat web font
body {
font-family: "Helvetica Neue",Helvetica,"Hiragino Sans GB","Microsoft YaHei","ๅพฎ่ฝฏ้›…้ป‘",Arial,sans-serif;
}
body {
font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', ๅพฎ่ฝฏ้›…้ป‘, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif;
}
@alexcheng1982
alexcheng1982 / proxy.js
Last active August 29, 2015 14:25
NodeJS proxy server with CORS support
var connect = require('connect'),
httpProxy = require('http-proxy');
var app = connect();
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:8080'
});
proxy.on('proxyReq', function(proxyReq, req, res, options) {
@alexcheng1982
alexcheng1982 / php_tidy.md
Last active August 29, 2015 14:26
PHP HTML tidy

Install php tidy sudo yum install php-tidy then restart Apache

@alexcheng1982
alexcheng1982 / node5x.sh
Created November 22, 2015 21:23
Install NodeJS 5.x on Ubuntu
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
@alexcheng1982
alexcheng1982 / Dockerfile
Last active June 6, 2016 21:51
Java 8 + Maven 3.3.9 - Dockerfile
FROM phusion/baseimage
CMD ["/sbin/my_init"]
RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2 \
unzip \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
@Component
public class CalculatorHandler {
public Mono<ServerResponse> add(final ServerRequest request) {
return calculate(request, (v1, v2) -> v1 + v2);
}
public Mono<ServerResponse> subtract(final ServerRequest request) {
return calculate(request, (v1, v2) -> v1 - v2);
}
public Mono<ServerResponse> multiply(final ServerRequest request) {
return calculate(request, (v1, v2) -> v1 * v2);
@Configuration
public class Config {
@Bean
@Autowired
public RouterFunction<ServerResponse> routerFunction(final CalculatorHandler calculatorHandler) {
return RouterFunctions.route(RequestPredicates.path("/calculator"), request ->
request.queryParam("operator").map(operator ->
Mono.justOrEmpty(
ReflectionUtils.findMethod(CalculatorHandler.class, operator, ServerRequest.class))
.flatMap(method -> (Mono<ServerResponse>) ReflectionUtils
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class FunctionalStarterApplicationTests {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void calculate() {
assertThat(doCalculate("add", "3", "5")).isEqualTo("8");
assertThat(doCalculate("subtract", "3", "5")).isEqualTo("-2");
assertThat(doCalculate("multiply", "3", "5")).isEqualTo("15");