Skip to content

Instantly share code, notes, and snippets.

@anolivetree
anolivetree / RecyclerViewUtil.kt
Last active August 24, 2021 13:57
Callback to notify the current page is changed on RecyclerView + PagerSnapHelper.
package com.example.util
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
/**
* Call listener when the current page is changed.
* Use this with LinearLayoutManager and PagerSnapHelper.
*
* Whether the listener is called at first might depend on the version of RecyclerView.
@anolivetree
anolivetree / LiveDataUtil.kt
Created August 9, 2018 14:26
Zip multiple LiveData
package com.example.util
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MediatorLiveData
import android.arch.lifecycle.Observer
fun <T1,T2> zipLiveData(src1: LiveData<T1?>, src2: LiveData<T2?>): LiveData<Pair<T1?,T2?>> {
val merged = MediatorLiveData<Pair<T1?,T2?>>()
var flag: Int = 0
@anolivetree
anolivetree / bdiff.go
Created July 25, 2018 03:29
Show binary diff of two files
package main
import (
"bufio"
"bytes"
"fmt"
"os"
)
func main() {
@anolivetree
anolivetree / CursorObserverLiveData.kt
Last active April 23, 2018 05:02
LiveData which observes cursor
package com.example
import android.arch.lifecycle.LiveData
import android.database.ContentObserver
import android.database.Cursor
import android.os.Handler
import android.os.Looper
import kotlinx.coroutines.experimental.channels.ActorJob
import kotlinx.coroutines.experimental.channels.actor
@anolivetree
anolivetree / core.clj
Created February 21, 2018 03:24
kibelaに投稿するプログラム
; 使い方
; (def session (make-session))
; (signin session "チーム名" "ユーザー名" "パスワード") ; チーム名は、xxx.kibe.laのxxxの部分
; (post-wiki session "タイトル" "中身" "カテゴリ")
(ns kibela.core
(:require [net.cgrand.enlive-html :as html])
(:require [clj-http.cookies])
(:require [clj-http.client :as http])
@anolivetree
anolivetree / integer.java
Created January 17, 2018 14:44
(a == 1 && a == 2) in Java
package com.company;
import java.lang.reflect.Field;
public class Main {
public static void main(String[] args) {
// fill the cache with the same value
try {
@anolivetree
anolivetree / widenscrollbar.js
Last active November 1, 2017 14:13
Widen the scrollbar on Google developer sites.
// ==UserScript==
// @name scrollbar widen
// @namespace https://developer.android.com/
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://developer.android.com/*
// @include https://developers.google.com/*
// @grant GM_addStyle
// ==/UserScript==
@anolivetree
anolivetree / clojure.clj
Created October 3, 2017 11:57
上のコードをみて、下のコードをみて、再度上のコードを見ると、Lispの括弧が気にならなくなる(かもしれない)
(defn gray-encode [x]
(bit-xor x (unsigned-bit-shift-right x 1)))
(defn gray-decode [x]
(loop [mask 0x80000000
b 0]
(if (= mask 0)
b
(recur (unsigned-bit-shift-right mask 1)
(bit-or b
@anolivetree
anolivetree / README
Last active July 14, 2016 09:14
IntelliJ-like key binding for Eclipse
File->Import->General->Preferences->Import Keys Preferences
// (column1=0 OR column=1) AND (column2=3)
TODO_Selector a = orma.selectFromTODO().column1Eq(0).or().column1Eq(1);
Cursor cursor = orma.selectFromTODO()
.where(a).and().column2Eq(3)