Skip to content

Instantly share code, notes, and snippets.

View Afolayan's full-sized avatar

Jephthah Afolayan Afolayan

View GitHub Profile
@Afolayan
Afolayan / german-driving-license.md
Created April 12, 2026 17:02 — forked from blessanm86/german-driving-license.md
Quick Ref Notes for German Driving License Test

This is unmaintained and was created for personal use. As I passed the exam I have no use to keep this up to date. Feel free to fork

What are the consequences for a person driving a motor vehicle under the influence of drugs (e.g. hashish, heroin, cocaine)?

[x] Confiscation of driving licence or driving ban
[x] Compulsory medical/psychological examination
[x] Fine and/or imprisonment

In which instances do you have to approach a pedestrian crossing with particular care?

Proposed new module

Organizing existing modules

├── app ├── core │ ├── adapter │ ├── behaviourmanager │ ├── current core │ ├── date │ ├── design

@Afolayan
Afolayan / GetFile.kt
Last active October 8, 2023 20:32
Controller and RestController functions to get a single file
@GetMapping("/uploads/{fileName:.+}")
fun getFile(@PathVariable fileName: String): ResponseEntity<Resource> {
val file = fileStorageService.loadAsResources(fileName)
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"${file.filename}\"")
.body(file)
}
@GetMapping("/$FAKE_PATH_URL/{fileName:.+}")
@Afolayan
Afolayan / FileStorageServiceImpl.kt
Last active October 8, 2023 19:29
Implementation details for the `FileStorageService` interface
import com.afolayanseyi.springboot.tutorial.exception.StorageException
import com.afolayanseyi.springboot.tutorial.exception.StorageFileNotFoundException
import com.afolayanseyi.springboot.tutorial.configuration.StorageProperties
import org.springframework.core.io.Resource
import org.springframework.core.io.UrlResource
import org.springframework.stereotype.Service
import org.springframework.util.FileSystemUtils
import org.springframework.util.StringUtils
import org.springframework.web.multipart.MultipartFile
import java.io.IOException
class RandomQuoteLocalDataSource @Inject constructor(
private val coroutineDispatcher: CoroutineDispatcher,
private val randomQuotesDao: RandomQuotesDao,
) {
suspend fun insertRandomQuote(randomQuoteEntity: RandomQuoteEntity) {
withContext(coroutineDispatcher) {
randomQuotesDao.insertRandomQuote(randomQuoteEntity)
}
}
@Database(
entities = [RandomQuoteEntity::class],
version = 1
)
@TypeConverters(DateConverter::class, ListToStringConverter::class)
abstract class RandomQuotesDatabase : RoomDatabase() {
abstract fun randomQuotesDao(): RandomQuotesDao
}
@Dao
interface RandomQuotesDao {
@Query("SELECT * FROM $RandomQuotesTable")
fun getAllRandomQuotes(): Flow<List<RandomQuoteEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertRandomQuote(randomQuote: RandomQuoteEntity)
}
@HiltViewModel
class QuotesViewModel @Inject constructor(
private val fetchRandomQuoteUseCase: FetchRandomQuoteUseCase,
private val getRandomQuotesUseCase: GetRandomQuotesUseCase
) : ViewModel() {
private val _quotesUiState: MutableStateFlow<RandomQuotesUiState> =
MutableStateFlow(RandomQuotesUiState.Loading)
val quotesUiState: StateFlow<RandomQuotesUiState> get() = _quotesUiState.asStateFlow()
// service class
private const val RandomQuotePath = "quotes/random"
interface RandomQuoteApiService {
@Headers("Accept: application/json")
@GET(RandomQuotePath)
suspend fun getRandomQuote(): Response<List<RandomQuoteResponse>>
}
// remote data source
interface IRandomQuoteRepository {
fun getRandomQuotes(): Flow<List<RandomQuote>>
fun fetchNewRandomQuote(): Flow<Result<RandomQuote>>
}
class RandomQuoteRepository @Inject constructor(
private val coroutineDispatcher: CoroutineDispatcher,
private val localDataSource: RandomQuoteLocalDataSource,