Skip to content

Instantly share code, notes, and snippets.

@tsuharesu
tsuharesu / words_from_the_heart.slackworkflow
Last active November 3, 2020 20:51
A simple workflow to send some kind anonymous words for your colleagues.
{
"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 July 2, 2019 15:01
Rotate image after saving with CameraX
/** 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()
}
override fun start() {
program.accept(LoadLabelsMsg)
program.accept(LoadAccountsMsg)
}
override fun resume() {
}
override fun destroy() {
programDisposable.dispose()
@tsuharesu
tsuharesu / AccountActivity.kt
Last active January 15, 2016 13:02
ViewBinder usage
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 January 9, 2016 17:20
Kotlin ViewBinder for Android
/**
* 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
}
Verifying that +tsuharesu is my blockchain ID. https://onename.com/tsuharesu

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 June 8, 2024 07:30
Handle Cookies easily with Retrofit/OkHttp
/**
* 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 {
@tsuharesu
tsuharesu / stream_fibonacci.exs
Created March 23, 2015 22:21
Fibonacci via Stream
# 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 March 19, 2015 01:10
Fizzbuzz in Elixir
# 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