Skip to content

Instantly share code, notes, and snippets.

View pfmaggi's full-sized avatar

Pietro F. Maggi pfmaggi

View GitHub Profile
@pfmaggi
pfmaggi / AppComponent.kt
Created March 31, 2020 17:36
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Singleton
@Component(modules = [AppModule::class])
interface AppComponent {
@Component.Factory
interface Factory {
fun create(@BindsInstance context: Context): AppComponent
}
@pfmaggi
pfmaggi / MyWorkerFactory.kt
Created March 31, 2020 17:34
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Singleton
class MyWorkerFactory @Inject constructor(
service: DesignerNewsService
) : DelegatingWorkerFactory() {
init {
addFactory(myWorkerFactory(service))
// Add here other factories that you may need in your application
}
@pfmaggi
pfmaggi / MyApplication.kt
Created March 31, 2020 17:29
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyApplication : Application(), Configuration.Provider {
override fun getWorkManagerConfiguration(): Configuration {
val myWorkerFactory = DelegatingWorkingFactory()
myWorkerFactory.addFactory(MyWorkerFactory(service))
// Add here other factories that you may need in your application
return Configuration.Builder()
@pfmaggi
pfmaggi / MyWorkerFactory.kt
Created March 31, 2020 16:31
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyWorkerFactory(private val service: DesignerNewsService) : WorkerFactory() {
override fun createWorker(
appContext: Context,
workerClassName: String,
workerParameters: WorkerParameters
): ListenableWorker? {
@pfmaggi
pfmaggi / MyApplication.kt
Created March 31, 2020 16:27
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyApplication : Application(), Configuration.Provider {
override fun getWorkManagerConfiguration(): Configuration =
Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.DEBUG)
.setWorkerFactory(MyWorkerFactory(DesignerNewsService))
.build()
...
}
@pfmaggi
pfmaggi / MyWorkerFactory.kt
Last active April 19, 2021 08:48
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyWorkerFactory(private val service: UpvoteStoryHttpApi) : WorkerFactory() {
override fun createWorker(
appContext: Context,
workerClassName: String,
workerParameters: WorkerParameters
): ListenableWorker? {
// This only handles a single Worker, please don’t do this!!
@pfmaggi
pfmaggi / AndroidManifest.xml
Last active March 31, 2020 16:03
Code for the Medium article: "Customizing WorkManager"
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<application
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
tools:node="remove" />
</application>
@pfmaggi
pfmaggi / UpvoteStoryWorker.kt
Last active April 1, 2020 12:40
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class UpvoteStoryWorker(
appContext: Context,
workerParams: WorkerParameters,
private val service: UpvoteStoryHttpApi)
: CoroutineWorker(appContext, workerParams) {
override suspend fun doWork(): Result {
@pfmaggi
pfmaggi / gist:898f97a5026821f8a54baaa4c3751563
Created August 25, 2019 08:53 — forked from TobiasWooldridge/gist:22f0cdca75190b9a473f
How to Unbrick a Kindle Paperwhite

How to unbrick an Amazon Kindle Paperwhite™

This guide instructs you in how to unbrick an Amazon Kindle Paperwhite. The consequences of following it are your own responsibility. This method (opening the Kindle and using the serial interface) should be a last resort and should only be considered if other methods fail

The Guide

  1. Pry open Kindle using a prying tool
  2. Unscrew the screen and remove it from the base. Note that there's a screw hidden under the adhesive at the top in the middle
  3. Solder tin wire to serial ports on the bottom
  4. Attach tin wire to USB TTY device (order is ground, RX, TX, from the kindle's perspective, where GND is the smallest pad) and plug USB TTY device into your computer
  5. Open Putty on your computer in serial mode, with the serial port specified as your USB device and baud configured to 115200
@pfmaggi
pfmaggi / ffmpeg-build.sh
Created March 20, 2019 19:39
ffmpeg-build.sh - glinux version
#!/bin/bash
if [ -z "$ANDROID_NDK" ]; then
echo "Please set ANDROID_NDK to the Android NDK folder"
exit 1
fi
#Change to your local machine's architecture
# HOST_OS_ARCH=darwin-x86_64
HOST_OS_ARCH=linux-x86_64