Skip to content

Instantly share code, notes, and snippets.

View tfcporciuncula's full-sized avatar

Fred Porciúncula tfcporciuncula

View GitHub Profile
@tfcporciuncula
tfcporciuncula / another-cas-auth.js
Last active November 26, 2015 18:01
A temporary CAS authentication script for ZAP that should work with SSO disabled
// The authenticate function is called whenever ZAP requires to authenticate for a Context for which this script
// was selected as the Authentication Method. The function should send any messages that are required to do the authentication
// and should return a message with the authenticated response.
//
// NOTE: Any message sent in the function should be obtained using the 'helper.prepareMessage()' method.
//
// Parameters:
// helper - a helper class providing useful methods: prepareMessage(), sendAndReceive(msg)
// paramsValues - the values of the parameters configured in the Session Properties -> Authentication panel.
// The paramsValues is a map, having as keys the parameters names (as returned by the getRequiredParamsNames()
@tfcporciuncula
tfcporciuncula / BooksViewModel.kt
Created July 15, 2018 04:22
mediator-live-data-gist-1
class BooksViewModel(bookDao: BookDao) : ViewModel() {
// to make things simpler here, let's skip the repository layer
val books = bookDao.books()
}
@tfcporciuncula
tfcporciuncula / BooksViewModel.kt
Created July 17, 2018 17:54
mediator-live-data-gist-2
class BooksViewModel(bookDao: BookDao) : ViewModel() {
// the LiveData from Room won't be exposed to the view...
private val dbBooks = bookDao.books()
// ...because this is what we'll want to expose
val books = MediatorLiveData<List<Book>>()
private var currentOrder = ASCENDING
@tfcporciuncula
tfcporciuncula / ApplicationInjection.kt
Created August 19, 2018 10:20
ApplicationComponent-with-builder
@Singleton
@Component(modules = [YourModule::class, ThatOtherModule::class])
interface ApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance fun applicationContext(applicationContext: Context): Builder
fun build(): ApplicationComponent
}
}
@tfcporciuncula
tfcporciuncula / DaggerComponentProvider.kt
Created August 31, 2018 08:31
DaggerComponentProvider
interface DaggerComponentProvider {
val component: ApplicationComponent
}
val Activity.injector get() = (application as DaggerComponentProvider).component
@tfcporciuncula
tfcporciuncula / ViewModelFactory.kt
Created November 29, 2018 22:42
ViewModelFactory
class ViewModelFactory<VM : ViewModel> @Inject constructor(
private val viewModel: Lazy<VM>
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>) = viewModel.get() as T
}
@tfcporciuncula
tfcporciuncula / BestPostActivity.kt
Created November 29, 2018 23:04
BestPostActivity
class BestPostActivity : AppCompatActivity() {
private val viewModel by lazy {
ViewModelProviders
.of(this, injector.bestPostViewModelFactory())
.get(BestPostViewModel::class.java)
}
...
}
@tfcporciuncula
tfcporciuncula / BestPostFinder.kt
Created November 30, 2018 08:18
BestPostFinder
@Reusable
class BestPostFinder @Inject constructor() {
...
}
@Module
object PostModule {
@JvmStatic @Provides @Reusable
fun provideBestPostFinder() = BestPostFinder()
}
@tfcporciuncula
tfcporciuncula / ApplicationInjection.kt
Created December 14, 2018 20:09
ApplicationComponent-with-module
@Singleton
@Component(modules = [ApplicationModule::class, YourModule::class, ThatOtherModule::class])
interface ApplicationComponent
@Module
class ApplicationModule(private val applicationContext: Context) {
@Provides fun provideApplicationContext(): Context = applicationContext
}