Skip to content

Instantly share code, notes, and snippets.

@kohendrix
kohendrix / search.cpp
Last active April 24, 2018 08:55
search algorithms for c++
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int linearSearch(int arr[], int s, int target);
int binarySearch(int arr[], int first, int last, int target);
int blockSearch(int arr[], int size, int target);
@kohendrix
kohendrix / index.js
Last active February 2, 2019 04:45
firebase cloud functions sample
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firestoreSettings = { timestampsInSnapshots: true };
admin.initializeApp(functions.config().firebase);
const firestore = admin.firestore();
firestore.settings(firestoreSettings);
/**
* http request triggers the function
@kohendrix
kohendrix / promise_array_test.js
Created November 30, 2018 07:33
Simple tests of the Promise array execution order.
'use strict';
var p = console.log;
var FS = require('fs');
// fs appendFile Promise wrapper
function write(path, data){
return new Promise((res, rej) => FS.appendFile(path, data, err =>
err ? rej(err) : res(p(data, 'is done!'))
));
@kohendrix
kohendrix / NotDialogFragment.kt
Last active December 27, 2018 00:59
Android Fragment that shows a dialog but not a DialogFragment
class NotDialogFragment : Fragment() {
private var reserveDismiss = false // resume時にこのdialogを閉じる
private var reserveShow = false // resume時に表示
private lateinit var dialogMain: LinearLayout
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater?.inflate(R.layout.fragment_load, container, false)?.apply {
dialogMain = findViewById<FrameLayout>(R.id.dialog_main_layout).also {
it.visibility = View.GONE
@kohendrix
kohendrix / ReproApplication.kt
Last active January 25, 2019 07:47
Implementing Repro SDK for Android
import android.app.Application
import android.util.Log
import io.repro.android.Repro
import org.xmlpull.v1.XmlPullParser
import java.lang.Exception
class ReproApplication : Application() {
companion object {
private const val REPRO_TOKEN_KEY = "repro_sdk_token"
}
@kohendrix
kohendrix / ReproTrigger.kt
Created January 25, 2019 09:04
triggers Repro events
import io.repro.android.Repro
class ReproTrigger {
companion object {
private var instance: ReproTrigger? = null
fun getInstance(): ReproTrigger {
if (instance == null)
instance = ReproTrigger()
return instance!!
}
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.example.koheiando.reprosample.DeepLinkTargetTWOActivity.Companion.EXTRA_TEXT
/**
* does not have UI, just start the right activity requested from a browser
*/
@kohendrix
kohendrix / HttpRequest.kt
Created February 1, 2019 03:42
HttpRequest client using Volley and Coroutines
import android.util.Log
import com.android.volley.Response
import com.android.volley.VolleyError
import com.android.volley.toolbox.JsonObjectRequest
import com.example.koheiando.twittervolleysample.TvsApplication
import kotlinx.coroutines.suspendCancellableCoroutine
import org.json.JSONObject
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import org.json.JSONObject
abstract class HttpResponse {
companion object {
const val HEADER_KEY = "header"
const val RESPONSE_KEY = "response"
}
internal abstract fun parseJson(json: JSONObject): HttpResponse
}
@kohendrix
kohendrix / HttpRequestQueue.kt
Created February 1, 2019 03:43
Volley RequestQueue singleton
import android.content.Context
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.toolbox.Volley
/**
* Singleton
*/
class HttpRequestQueue constructor(context: Context) {