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
View SimpleChatServer.java
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
View SimpleChatServerTest.java
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
View SimpleChatClient.java
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
View SimpleChatClient.java
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;
View Page99.java
List.of(manager1, manager2).stream()
.flatMap(m ->
Stream.concat(m.getEmployeeList().stream(), Stream.of(m)))
.distinct()
.mapToInt(Employee::getYearlySalary)
.sum();
View tutorial-reactive-spring-1-c-initial-rest-controller
@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
View tutorial-reactive-spring-1-a-kotlin-app
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
View CityAndPhone.java
public static class CityAndPhone {
private String city;
private String phone;
public CityAndPhone(String city, String phone) {
this.city = city;
this.phone = phone;
}
View Exercise32_Oracle.java
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 -> {
View Exercise32_4.java
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();
}