Skip to content

Instantly share code, notes, and snippets.

@tsuharesu
tsuharesu / words_from_the_heart.slackworkflow
Last active Nov 3, 2020
A simple workflow to send some kind anonymous words for your colleagues.
View words_from_the_heart.slackworkflow
{
"source_id": "302598399050397860",
"version": "1",
"workflow": {
"name": "Words from the Heart",
"blueprint": {
"version": "1",
"trigger": {
"type": "channel_action",
"id": "4bde8971-a75a-4310-b5ec-efceeea0a91a",
@tsuharesu
tsuharesu / rotation.kt
Created Jul 2, 2019
Rotate image after saving with CameraX
View rotation.kt
/** Define callback that will be triggered after a photo has been taken and saved to disk */
private val imageSavedListener = object : ImageCapture.OnImageSavedListener {
override fun onError(error: ImageCapture.UseCaseError, message: String, exc: Throwable?) {
exc?.printStackTrace()
}
override fun onImageSaved(photoFile: File) {
lifecycle.coroutineScope.launch {
rotateImageCorrectly()
}
View dontwork.kt
override fun start() {
program.accept(LoadLabelsMsg)
program.accept(LoadAccountsMsg)
}
override fun resume() {
}
override fun destroy() {
programDisposable.dispose()
View AccountActivity.kt
class AccountActivity : AccountView {
lateinit var presenter: AccountPresenter
// Using the ViewBinder is simple
override var accountView: AccountViewModel by ViewBinder {
txt_username.text = it.userName
txt_company.text = it.company
txt_contact_email.text = it.email
txt_contact_phone.text = it.phone
@tsuharesu
tsuharesu / Binding.kt
Last active Jan 9, 2016
Kotlin ViewBinder for Android
View Binding.kt
/**
* View binder with nullable types support
*/
class ViewBinder<M>(val function: (M) -> Unit) : ReadWriteProperty<Any, M> {
private var mValue: M? = null
override fun getValue(thisRef: Any, property: KProperty<*>): M {
return mValue as M
}
View gist:2a84a39baaac99b72470
Verifying that +tsuharesu is my blockchain ID. https://onename.com/tsuharesu
View keybase.md

Keybase proof

I hereby claim:

  • I am tsuharesu on github.
  • I am tsuharesu (https://keybase.io/tsuharesu) on keybase.
  • I have a public key whose fingerprint is 9162 DB1A A33A 0618 1F39 78F1 C177 7945 5C25 595B

To claim this, I am signing this object:

@tsuharesu
tsuharesu / AddCookiesInterceptor.java
Last active Nov 2, 2022
Handle Cookies easily with Retrofit/OkHttp
View AddCookiesInterceptor.java
/**
* This interceptor put all the Cookies in Preferences in the Request.
* Your implementation on how to get the Preferences MAY VARY.
* <p>
* Created by tsuharesu on 4/1/15.
*/
public class AddCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
View stream_fibonacci.exs
# Generate a stream
Stream.unfold({0, 1}, fn {a, b} -> {a, {b, a + b}} end)
# Take the first 15 numbers
|> Enum.take(15)
@tsuharesu
tsuharesu / fizzbuzz.exs
Created Mar 19, 2015
Fizzbuzz in Elixir
View fizzbuzz.exs
# This is a exercise in Programming Elixir from Pragmatic Bookshelf
fizzbuzz_check = fn
(0, 0, _) -> "FizzBuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, c) -> c
end
fizzbuzz = fn(n) -> fizzbuzz_check.(rem(n, 3), rem(n, 5), n) end