Skip to content

Instantly share code, notes, and snippets.

Avatar

Biniam biniama

View GitHub Profile
@biniama
biniama / pom.xml
Created Mar 19, 2021
Dependencies
View pom.xml
<dependencies>
<!-- The app must be a webapp to have an embedded container (e.g. Tomcat) on the classpath. -->
<!-- Otherwise, the app starts and shuts down automatically. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
@biniama
biniama / balanced_sum.py
Created Feb 24, 2021
Hacker Rank Exercises
View balanced_sum.py
#!/bin/python3
import math
import os
import random
import re
import sys
#
@biniama
biniama / braking.md
Created Jun 24, 2020 — forked from cooervo/braking.md
Fahrschule
View braking.md
@biniama
biniama / DateFormatFinder.java
Last active Nov 19, 2019
Find date format given the date object
View DateFormatFinder.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Source: https://stackoverflow.com/questions/7579227/how-to-get-the-given-date-string-formatpattern-in-java
*/
public class DateFormatFinder {
@biniama
biniama / SwaggerDocConfig.java
Last active Mar 12, 2020
Swagger Documentation with Spring Boot (working UI)
View SwaggerDocConfig.java
package com.example.springbootswagger.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
@biniama
biniama / PojoToJson.java
Created Nov 2, 2018
Convert POJO to JSON
View PojoToJson.java
import com.fasterxml.jackson.databind.ObjectMapper;
private static void pojoToJson(Object object) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
log.info(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));
}
@biniama
biniama / How to run Simple Server Locally
Last active Oct 30, 2018
Simple API Server using Spring Boot
View How to run Simple Server Locally
1. Make sure Spring Boot is installed
`sdk install springboot`
`spring --version`
2. Run
`spring run app.groovy`
@biniama
biniama / Difference
Last active Oct 20, 2018
Adapter vs Decorator vs Bridge
View Difference
In scope and intent
Adapter - intent is to mix an interface into a class that doesn't currently implement htat interface.
Decorator - intent is to change the way a method behaves differently for different decorators.
Bridge - intent is to insolate sub-systems so you can swap out sub-systems without impacting the code that is using that sub-systems.
The point of a Bridge is to isolate two subsystems so that they can be independently modified. Bridges are big things, often comprised of other patterns (like Adapters and Decorators). This segment looks at how to implement a Bridge and discusses the differences between Bridge and similar patterns like Adapter.
E.g. JDBC (bad implementation of Bridge since swapping doesn't work as it should)
Best example: ORM systems like Hibernate.
@biniama
biniama / SingeltonGoF.java
Last active Oct 20, 2018
Singleton Pattern - Multiple Implementations by Allen Holub (holub.com/patterns)
View SingeltonGoF.java
class Singelton {
static Singleton instance = null;
//private constructor
private Singelton() {}
public static Singleton getInstance() {
if(instance == null)
instance = new Singleton();
return instance;
@biniama
biniama / PhonePadExercise.java
Last active Oct 17, 2018
"Find Unique Numbers of Length n" using Java
View PhonePadExercise.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PhonePadExercise {
public static void main(String[] args) {
Integer selectedDigit = 4;