Skip to content

Instantly share code, notes, and snippets.

Pradeep kpradeep12

View GitHub Profile
@kpradeep12
kpradeep12 / Pizza.kt
Last active Jan 26, 2019
This class will demonstrate the kotlin features along with building a Pizza DSL.
View Pizza.kt
enum class Cheese{Light, Normal, Extra;}
enum class Sauce{Marinara, GarlicParmesan, Alfredo}
interface Topping
enum class Veg: Topping {Onion, Tomato, Pepper, Spinach;}
enum class Meat: Topping {Chicken, Pepperoni;}
fun main() =
pizza {
large {
add(Sauce.Alfredo)
@kpradeep12
kpradeep12 / GeneratorTest.java
Created Jan 17, 2019
Generate number, character, strings, boolean and dates for test data using strategy design pattern.
View GeneratorTest.java
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Random;
interface Generator<T> {
T generate();
static Generator<Boolean> generateBoolean(){
return new Generator<>() {
Random random = new Random();
View WorldClock.java
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.stream.Stream;
public class WorldClock {
public static void main(String[] args) {
DateTimeFormatter FORMAT = DateTimeFormatter.ofPattern("E, dd MMM u hh:mm:ss a z");
View DesktopUtility.java
public class DesktopUtility {
public static void main(String[] args) throws URISyntaxException, IOException {
Desktop desktop = java.awt.Desktop.getDesktop();
if(!Desktop.isDesktopSupported())
return;
// Opens composing window of default mail client
desktop.mail(new URI("mailto:<email address>"));
View JavaAPI.java
import j2html.tags.DomContent;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
View ReactiveObservables.java
Observable<Integer> observable = Observable.create(observableEmitter -> { // <1>
System.out.println("Generating numbers");
new Random().ints(10, 0, 5) // <2>
.forEach(i -> {
delay(500); // <3>
observableEmitter.onNext(i); // <4>
});
});
View EmployeeService.java
class Employee{
private Integer id;
private String name;
private Integer age;
Employee(Integer id, String name, Integer age) {
this.id = id;
this.name = name;
this.age = age;
}
You can’t perform that action at this time.