Skip to content

Instantly share code, notes, and snippets.

View Ikhiloya's full-sized avatar

Ikhiloya Ikhiloya

View GitHub Profile
@Ikhiloya
Ikhiloya / How to Deploy a Spring Boot App with Docker to DigitalOcean App Platform.md
Last active January 19, 2024 23:23
This article provides developers with instructions on how to deploy a Java Spring Boot application to the DigitalOcean App Platform using Docker

How to Deploy a Spring Boot App with Docker to DigitalOcean App Platform

Digital Ocean App Platform Logo

Introduction

DigitalOcean App platform is a Platform-as-a-service (Paas) that allows developers to publish code directly to DigialOcean servers without worrying about the underlying infrastructure. The Platform supports two ways to build an image for your app: Cloud Native Buildpacks and Dockerfiles.

When an app is deployed to the App Platform either via GitHub or DockerHub, it defaults to using Dockerfile if one is present in the root directory or specified app spec. Otherwise, the App Platform checks your code to determine what language or framework it uses. If it supports the language or framework, it chooses an appropriate resource type and uses the proper buildpack to build the app and deploy a container.

Java/Spring boot is no

@Ikhiloya
Ikhiloya / App.java
Last active October 18, 2022 01:59
retrofit client for encryption and decryption of request and response data
public class App extends Application {
private static final String TAG = App.class.getSimpleName();
private static final String BASE_URL = "https://66d252d7-61d1-44e0-be70-1f77477ac86c.mock.pstmn.io";
private static App INSTANCE;
private ApiService apiService;
@Ikhiloya
Ikhiloya / PlacePredictionProgrammatically.java
Created June 1, 2019 23:25
A sample code that shows how to get place predictions programmatically to create a customized user experience using Google Places Autocomplete Search Ft
public class PlacePredictionProgrammatically extends AppCompatActivity {
private static final String TAG = PlacePredictionProgrammatically.class.getSimpleName();
private EditText queryText;
private Button mSearchButton;
private TextView mSearchResult;
private StringBuilder mResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Ikhiloya
Ikhiloya / SyncDataWorker.java
Created September 23, 2019 14:36
A WorkManager Worker class that fetches data from the internet and saves it to Android Room database
public class SyncDataWorker extends Worker {
private BookService bookService;
private BookDao bookDao;
private static final String TAG = SyncDataWorker.class.getSimpleName();
public SyncDataWorker(@NonNull Context appContext, @NonNull WorkerParameters workerParams) {
super(appContext, workerParams);
bookService = App.get().getBookService();
bookDao = App.get().getBookDao();
@Ikhiloya
Ikhiloya / DecryptionInterceptor.java
Last active March 3, 2021 21:21
Retrofit Interceptor to intercept and encrypt response from the server
/**
* Created by Ikhiloya Imokhai on 2019-10-19.
* <p>
* Retrofit Interceptor to intercept and decrypt response from the server
*/
public class DecryptionInterceptor implements Interceptor {
private final CryptoStrategy mDecryptionStrategy;
@Ikhiloya
Ikhiloya / jwtBlacklistedTokenCheck.java
Created February 10, 2020 07:25
check for token in the JWT blackist
//check if the token is in the blacklist
if (StringUtils.hasText(jwt) && jwtTokenBlacklistRepository.findByToken(jwt).isPresent()) {
LOG.info("blacklisted token");
((HttpServletResponse) servletResponse).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid token");
}
//Java
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("<your html file>"); //not in scope of this gist
webview.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url){
//Here you want to use .loadUrl again
//on the webview object and pass in
//"javascript:<your javaScript function"
webview.loadUrl("javascript:myJavaScriptFunc('" + argumentPassingIn + "')"); //if passing in an object. Mapping may need to take place
}
@Ikhiloya
Ikhiloya / NetworkInterceptor.kt
Last active October 28, 2020 10:18
Network interceptor for caching requests when there is network connection
class NetworkInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
Timber.d("network interceptor: called.")
val response = chain.proceed(chain.request())
val cacheControl = CacheControl.Builder()
.maxAge(5, TimeUnit.SECONDS)
.build()
private fun cache(): Cache? {
val cacheSize = 5 * 1024 * 1024.toLong()
return Cache(instance!!.applicationContext.cacheDir, cacheSize)
}
@Ikhiloya
Ikhiloya / OfflineCacheInterceptor.kt
Last active October 28, 2020 07:13
An offline interceptor to cache requests when there is no network connection. It checks if a specific annotation is present before caching.
open class OfflineCacheInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
val invocation: Invocation? = request.tag(Invocation::class.java)
if (invocation != null) {
val annotation: Cacheable? =
invocation.method().getAnnotation(Cacheable::class.java)