Skip to content

Instantly share code, notes, and snippets.

Avatar

Zac Sweers ZacSweers

View GitHub Profile
View DiscussionGuidelines.md

Guidelines

To keep the arguments and examples to the point there are few helpful rules:

  • No abstract examples/arguments. These cause the discussion to lose focus and make examples harder to follow. The example/argument must be traceable to a real-world problem - ___ is intended to solve real problems, not imaginary ones.
  • Examples must show the full complexity of the problem domain. Simplified examples trivialize the problems and the solutions intended to solve those simplified examples may not work for the complex problems.
  • Examples of problematic ___ code must be the “best way” of writing the code in ___ - if it can be improved then the improved version should be used instead.
  • Arguments must be straight to the point and as concise as possible.
  • Arguments should take the point of view of an average programmer - not the über-programmer who doesn’t make design mistakes.
@ZacSweers
ZacSweers / BlurrinessDetection.kt
Last active Oct 12, 2020
Demo implementation of client-side image blurriness detection on Android using renderscript.
View BlurrinessDetection.kt
/*
* Copyright (c) 2018. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ZacSweers
ZacSweers / MoshiBugReport.java
Last active Oct 7, 2020
Sample bug report for Moshi
View MoshiBugReport.java
package test;
import static com.google.common.truth.Truth.assertThat;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
import org.junit.Test;
import java.io.IOException;
public class MoshiBugReport {
@ZacSweers
ZacSweers / crashcourse.md
Last active Sep 4, 2020
Python Reddit bot on Heroku
View crashcourse.md

A crash course in setting up your Python Reddit bot on Heroku

You'll need to do the following:

  • You need to make your bot a python app. Do this by making another directory (can be the same name as the regular one) and put all your python code in that, and make an empty file called __init__.py in it as well. See how I structured mine if this isn't clear. In your base directory, create two files: "requirements.txt" and "runtime.txt". The requirements.txt file should be the output of pip freeze (you can run the command "pip freeze > requirements.txt"). If you're not using virtualenv, you'll need to go through after and delete all the lines with packages your code doesn't actually use. Check out mine to see what I mean. Runtime.txt just specifies with python version for heroku to use. Mine just has the line "python-2.7.4" in it. All of this will tell heroku to recognize your bot as a python app.

  • Make a heroku account and

@ZacSweers
ZacSweers / 1-Before.txt
Last active Jun 21, 2020
Dagger new error messages output comparison
View 1-Before.txt
/Users/zsweers/dev/android/personal/CatchUp/app/build/generated/source/kapt/debug/io/sweers/catchup/app/CatchUpApplication_HiltComponents.java:188: error: [Dagger/DuplicateBindings] androidx.activity.ComponentActivity is bound multiple times:
public abstract static class ApplicationC implements ApplicationComponent,
^
@org.jetbrains.annotations.NotNull @io.sweers.catchup.injection.scopes.PerActivity @Binds androidx.activity.ComponentActivity io.sweers.catchup.injection.ActivityModule.provideComponentActivity(T)
@org.jetbrains.annotations.NotNull @io.sweers.catchup.injection.scopes.PerActivity @Binds androidx.activity.ComponentActivity io.sweers.catchup.ui.about.AboutActivity.Module.provideComponentActivity(io.sweers.catchup.ui.about.AboutActivity)
@org.jetbrains.annotations.NotNull @io.sweers.catchup.injection.scopes.PerActivity @Binds androidx.activity.ComponentActivity io.sweers.catchup.ui.activity.MainActivity.ServiceIntegrationModule.provideComponentActivity(io
@ZacSweers
ZacSweers / ExponentialBackoff
Last active Apr 14, 2020 — forked from jerrellmardis/ExponentialBackoff
Exponential Backoff using Rx.retryWhen() I DON'T KNOW WHY THIS HAS HIGH SEO I JUST FORKED IT TO SAVE A COPY
View ExponentialBackoff
// retries up to 3 times while exponentially backing off with each retry
.retryWhen(errors ->
errors
.zipWith(
Observable.range(1, MAX_RETRIES), (n, i) -> i
)
.flatMap(
retryCount -> Observable.timer((long) Math.pow(4, retryCount), TimeUnit.SECONDS)
)
)
@ZacSweers
ZacSweers / WeakMutableSet.kt
Created Oct 25, 2019
A weak Set & MutableSet implementation in Kotlin.
View WeakMutableSet.kt
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* glassfish/bootstrap/legal/CDDLv1.0.txt or
* https://glassfish.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
View Complex.kt
@JsonClass(generateAdapter = true)
data class Foo<T>(
@Json(name = "barString") val bar: String,
val defaultValue: Int = 0,
val nullableString: String?,
val typeParam: T? = null,
val tList: List<T>
)
// Generated by Moshi Kotlin Code Gen
View InlineMask.kt
// Code generated by moshi-kotlin-codegen. Do not edit.
package com.squareup.moshi.kotlin.codgen
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.internal.Util
import java.lang.NullPointerException
You can’t perform that action at this time.