Skip to content

Instantly share code, notes, and snippets.

View finnkvan's full-sized avatar

Finn finnkvan

View GitHub Profile
@finnkvan
finnkvan / README.md
Created July 20, 2022 17:12 — forked from leonardofed/README.md
A curated list of AWS resources to prepare for the AWS Certifications


A curated list of AWS resources to prepare for the AWS Certifications

A curated list of awesome AWS resources you need to prepare for the all 5 AWS Certifications. This gist will include: open source repos, blogs & blogposts, ebooks, PDF, whitepapers, video courses, free lecture, slides, sample test and many other resources.


FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

class MainFragment : androidx.fragment.app.Fragment() {
companion object {
fun newInstance() = MainFragment()
}
private lateinit var viewModel: MainViewModel
private lateinit var message: TextView
override fun onCreateView(
import retrofit2.Response
internal const val UNKNOWN_CODE = -1
sealed class ApiResponse<T> {
companion object {
fun <T> create(response: Response<T>): ApiResponse<T> {
return if (response.isSuccessful) {
val body = response.body()
if (body == null || response.code() == 204) {
class RetrofitClient {
fun getRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl("https://pokeapi.co/api/v2/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(LiveDataCallAdapterFactory())
.build()
}
}
class LiveDataCallAdapterFactory: CallAdapter.Factory() {
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>? {
val observableType =
CallAdapter.Factory.getParameterUpperBound(0, returnType as ParameterizedType) as? ParameterizedType
?: throw IllegalArgumentException("resource must be parameterized")
return LiveDataCallAdapter<Any>(CallAdapter.Factory.getParameterUpperBound(0, observableType))
}
}
class LiveDataCallAdapter<R>(private val responseType: Type): CallAdapter<R, LiveData<ApiResponse<R>>> {
override fun adapt(call: Call<R>): LiveData<ApiResponse<R>> {
return object : LiveData<ApiResponse<R>>() {
private var isSuccess = false
override fun onActive() {
super.onActive()
if (!isSuccess) enqueue()
}
interface PokeApi {
@GET("characteristic/{id}")
fun getCharacteristic(@Path("id") id: Int): LiveData<PokeCharacteristic>
}
// Copyright: https://developer.android.com/topic/libraries/architecture/livedata
class NameViewModel : ViewModel() {
// Create a LiveData with a String
val currentName: MutableLiveData<String> by lazy {
MutableLiveData<String>()
}
// Rest of the ViewModel...
}
@finnkvan
finnkvan / Counter.java
Created October 24, 2018 20:18
Using Volatile
package com.pivincii;
public class Counter {
private volatile int count = 0;
public void increment() {
count ++;
}
public void decrement() {