Skip to content

Instantly share code, notes, and snippets.

View feresr's full-sized avatar

Fernando Raviola feresr

View GitHub Profile
private fun <T> any(): T {
 Mockito.any<T>()
 return uninitialized()
 }
 private fun <T> uninitialized(): T = null as T
class MyBroadcastReceiver(val listener : MyBroadcastListener) extends BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
listener.onSomeEventHappened()
}
interface MyBroadcastListener {
fun onSomeEventHappened()
}
}
package com.feresr.wallpapers.wallpapers
class WallpapersAdapter(private val context: Context, private val inflater: LayoutInflater) : BaseAdapter<Wallpaper>() {
companion object {
val TYPE_WALLPAPER: Int = 0
val TYPE_LOADING: Int = 1
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, item: Wallpaper) {
@feresr
feresr / Presenter.kt
Created June 20, 2018 05:08
Presenter.kt
abstract class BasePresenter<I : MVI.Intent, S : MVI.ViewState> {
private val intents: PublishSubject<I> = PublishSubject.create<I>()
private var states: Observable<S>? = null
private var disposable: Disposable? = null
private var viewDisposable: Disposable? = null
fun onCreate() {
states = intents
Fatal Exception: java.lang.IllegalStateException
Operation is already in progress
Fatal Exception: java.lang.IllegalStateException: Operation is already in progress
at kotlinx.coroutines.io.ByteBufferChannel.access$getReadOp$p(ByteBufferChannel.java:46)
at kotlinx.coroutines.io.ByteBufferChannel.access$flushImpl(ByteBufferChannel.java:157)
at kotlinx.coroutines.io.ByteBufferChannel.access$flushImpl(ByteBufferChannel.java:92)
at kotlinx.coroutines.io.ByteBufferChannel.access$flushImpl(ByteBufferChannel.java:75)
at kotlinx.coroutines.io.ByteReadChannelKt.discard(ByteReadChannelKt.java:3)
at io.ktor.client.response.HttpResponse$close$1.invokeSuspend(HttpResponse.java:3)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.b + 6(BaseContinuationImpl.java:6)
@feresr
feresr / sdl.cmake
Created April 17, 2020 16:30
sdl.cmake
# sdl2 cmake project-config input for ./configure scripts
set(prefix "/usr/local/Cellar/sdl2/2.0.12_1")
set(exec_prefix "${prefix}")
set(libdir "${exec_prefix}/lib")
set(SDL2_PREFIX "/usr/local/Cellar/sdl2/2.0.12_1")
set(SDL2_EXEC_PREFIX "/usr/local/Cellar/sdl2/2.0.12_1")
set(SDL2_LIBDIR "${exec_prefix}/lib")
set(SDL2_INCLUDE_DIRS "${prefix}/include/SDL2")
set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} -lSDL2")
@feresr
feresr / CMakeLists.txt
Created April 18, 2020 16:57
Link SDL statically
cmake_minimum_required(VERSION 3.16)
project(smb)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
add_executable(smb src/main.cpp)
target_link_libraries(smb ${SDL2} ${SDL2_IMAGE})
@feresr
feresr / shaders.cpp
Created August 31, 2020 23:30
Simple openGL GLSL vertex+fragment shader
void checkCompileErrors(unsigned int object, std::string type) {
int success;
char infoLog[1024];
if (type != "PROGRAM") {
glGetShaderiv(object, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(object, 1024, NULL, infoLog);
std::cout << "| ERROR::SHADER: Compile-time error: Type: " << type << "\n"
<< infoLog << "\n -- --------------------------------------------------- -- "
<< std::endl;
// `dependencies.gradle`
def jumio_version = "3.7.2"
jumio = [
core : "com.jumio.android:core:${jumio_version}@aar",
netverify : "com.jumio.android:nv:${jumio_version}@aar",
face : "com.jumio.android:face:${jumio_version}@aar",
auth : "com.jumio.android:auth:${jumio_version}@aar",
zoom_authentication: "com.facetec:zoom-authentication:8.12.1@aar"
]
@feresr
feresr / Test.kt
Last active November 12, 2020 10:59
// One of the strenghts of MVI is testing!
// 1) I'd love to use the VM API `viewModel.startOnBoarding()` instead of `handleIntents` :(
// 2) Why do we need to `handleIntent` before we can subscribe to the VM, how do I test a sequence of intenets?
@Test
fun `start onBoarding`() {
val testSubscriber = TestSubscriber<Any>() // Why <ANY> we shold be getting states?