Skip to content

Instantly share code, notes, and snippets.

@ishikota
ishikota / _first_page.html.haml
Created October 25, 2020 04:30
kaminari templates for bulma css
-# Link to the "First" page
-# available local variables
-# url: url to the first page
-# current_page: a page object for the currently displayed page
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote, class: 'pagination-previous'
@ishikota
ishikota / appsync-reconnection.log
Created July 27, 2018 07:34
appsyncでnetwork再接続時に、subscription復帰までにかかる時間をログからサンプル取る
07-27 16:03:28.481 4932-6983/com.cookpad.android.cookpad_tv.debug D/AppSync: Internet DISCONNECTED.
...
07-27 16:03:44.981 4932-7001/com.cookpad.android.cookpad_tv.debug E/AppSyncSubscriptionObservable$Listener: com.apollographql.apollo.exception.ApolloNetworkExceptio
...
07-27 16:03:52.887 4932-6983/com.cookpad.android.cookpad_tv.debug D/AppSync: Internet connected.
...
07-27 16:06:20.771 4932-4932/com.cookpad.android.cookpad_tv.debug D/MqttSubscriptionClient: com.amazonaws.mobileconnectors.appsync.subscription.mqtt.MqttSubscriptionClient@35d6f77 Attempt to subscribe to topic 789035092620/5jyo7raq7rdelhyksqssk5ivaq/onPutComment/4a0cee12967714dd78123c6ca77e568ffd5579776b80b0884ab46df7fdb05b3a
com.amazonaws.mobileconnectors.appsync.subscription.mqtt.MqttSubscriptionClient@35d6f77 Attempt to subscribe to topic 789035092620/5jyo7raq7rdelhyksqssk5ivaq/onPutHeart/4a0cee12967714dd78123c6ca77e568ffd5579776b80b0884ab46df7fdb05b3a
07-27 16:06:20.772 4932-4932/com.cookpad.android.cookpad_tv.debug D/MqttSubscription
fun savePrivateString(key: String, value: String) {
prefs.edit().putString(key, encrypt(key, value)).apply()
}
fun getPrivateString(key: String): String {
val encrypted = prefs.getString(key, "")
return decrypt(key, encrypted)
}
private fun encrypt(alias: String, plain: String): String {
companion object {
private const val ALGORITHM = "AES"
private const val MODE = "CBC"
private const val PADDING = "PKCS5Padding"
}
fun savePrivateString(key: String, value: String) {
prefs.edit().putString(key, encrypt(value)).apply()
}
import okhttp3.Authenticator
class MyAppAuthenticator(private val preference: SharedPreferences): Authenticator {
// This callback is called when api request failed in 401.
override fun authenticate(route: Route?, response: Response?): Request? {
val currentRefreshToken = preference.getString("REFRESH_TOKEN_KEY", "")
val (newAccessToken, newRefreshToken) = requestNewTokensToServer(currentRefreshToken).blockingGet() // TODO error handling
preference.edit().putString("ACCESS_TOKEN_KEY", newAccessToken).apply()
preference.edit().putString("REFRESH_TOKEN_KEY", newRefreshToken).apply()
return attachNewTokenOnRequest(response.request(), newAccessToken)
}
@ishikota
ishikota / code1.kt
Created July 5, 2018 09:22
Medium post for Getting along with credentials in android
val config = TwitterConfig.Builder(context)
.twitterAuthConfig(TwitterAuthConfig("TODO consumer key comes here", "TODO consumer secret comes here"))
.build()
Twitter.initialize(config)
python setup.py register
python setup.py sdist bdist_egg upload
This file has been truncated, but you can view the full file.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Setup"
]
},
{
@ishikota
ishikota / KerasTutorial.ipynb
Created June 29, 2016 07:41
Simple sin fitting by Keras
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ishikota
ishikota / gist:6016bdf0aaa0cd483b187ffc1d851aa9
Last active June 6, 2016 13:57
listをi番目が先頭になるように並び替えたい

ex.

  • lst = [A,B,C], i=0 => ans = [A,B,C]
  • lst = [A,B,C], i=1 => ans = [B,C,A]
  • lst = [A,B,C], i=2 => ans = [C,A,B]

sorted(lst, key=lambda e: i-lst.index(e))みたいにして,iに近い程前に来るみたいにしたかったけど,
iより前にある値の評価が負になって上手く並び替えられなかった.
=> [lst[(i+j)%len(lst)] for j in range(len(lst))] で実装することにした.

以下実装をきれいにできないものか...