Skip to content

Instantly share code, notes, and snippets.

View trishagee's full-sized avatar

Trisha Gee trishagee

View GitHub Profile
@trishagee
trishagee / SimpleChatServer.java
Created December 21, 2021 05:23
Simple chat server using ServerSocketChannel and the Channels factory methods
package ch15;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.nio.channels.Channels;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
@trishagee
trishagee / SimpleChatServerTest.java
Created December 21, 2021 05:21
Test harness for poking the SimpleChatServer
package ch15;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
@trishagee
trishagee / SimpleChatClient.java
Created December 21, 2021 05:19
Simple chat server and client, HFJ 2nd Ed
package ch15;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
@trishagee
trishagee / SimpleChatClient.java
Created December 21, 2021 05:16
Simple Chat Server and Client, NIO and ByteBuffers
package ch15;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
List.of(manager1, manager2).stream()
.flatMap(m ->
Stream.concat(m.getEmployeeList().stream(), Stream.of(m)))
.distinct()
.mapToInt(Employee::getYearlySalary)
.sum();
@RestController
class RestController(val priceService: PriceService) {
fun prices(@PathVariable symbol: String): Flux<StockPrice> {
}
}
@trishagee
trishagee / tutorial-reactive-spring-1-a-kotlin-app
Created October 21, 2019 10:43
Default Spring Boot Kotlin application
package com.mechanitis.demo.stockservice
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class StockServiceApplication
fun main(args: Array<String>) {
runApplication<StockServiceApplication>(*args)
@trishagee
trishagee / CityAndPhone.java
Last active January 4, 2017 14:17
Refactoring to pipelines, Java
public static class CityAndPhone {
private String city;
private String phone;
public CityAndPhone(String city, String phone) {
this.city = city;
this.phone = phone;
}
static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream stream = IntStream.range(0, LIST_SIZE);
if (parallel) {
stream = stream.parallel(); // Convert the stream to a parallel one
}
stream.forEach(i -> {
static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Supplier<Stream<String>> streamSupplier = () -> wordList.stream();
Stream<String> stream = streamSupplier.get();
if (true == parallel) {
stream = stream.parallel();
}