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
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuples;
import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;
id:0
event:random
data:751025203
id:1
event:random
data:-1591883873
id:2
event:random
package calculator
expect fun log(msg: String)
object Calculator {
fun add(x: Int, y: Int): Int {
log("add -> $x $y")
return x + y
}
package calculator
actual fun log(msg: String) = System.out.println(msg)
fun main(args: Array<String>) {
Calculator.add(1, 2)
Calculator.subtract(1, 2)
}
package calculator
actual fun log(msg: String) = console.log(msg)
fun main(args: Array<String>) {
Calculator.add(1, 2)
Calculator.subtract(1, 2)
}
@alexcheng1982
alexcheng1982 / generate_keystore.sh
Created December 12, 2017 16:46
Generate keystore
keytool -keystore mykey.jks -alias mykey -keyalg RSA -keysize 2048 -sigalg SHA256withRSA -genkey -validity 3650
@alexcheng1982
alexcheng1982 / HttpConnector.java
Last active December 12, 2017 16:54
Jetty HttpConnector
final Server server = new Server();
final HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSecureScheme("https");
httpConfiguration.setSecurePort(httpsPort);
final ServerConnector http = new ServerConnector(server,
new HttpConnectionFactory(httpConfiguration));
http.setPort(httpPort);
server.addConnector(http);
@alexcheng1982
alexcheng1982 / HttpsConnector.java
Created December 12, 2017 16:50
Jetty Https Connector
final SslContextFactory sslContextFactory = new SslContextFactory(keyStorePath);
sslContextFactory.setKeyStorePassword(keyStorePassword);
final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
final ServerConnector httpsConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfiguration));
httpsConnector.setPort(httpsPort);
server.addConnector(httpsConnector);
@alexcheng1982
alexcheng1982 / jetty_password.sh
Created December 12, 2017 16:52
Obfuscate Jetty password
java -cp jetty-util-9.2.17.v20160517.jar org.eclipse.jetty.util.security.Password password
@alexcheng1982
alexcheng1982 / ansible-docker
Created December 14, 2017 19:18
Ansible Docker file
FROM williamyeh/ansible:ubuntu16.04
RUN pip install --upgrade pip && \
pip install boto3 && \
pip install boto
ADD ansible /etc/ansible
RUN chmod +x /etc/ansible/ec2.py