Skip to content

Instantly share code, notes, and snippets.

@shogonir
shogonir / ApiCaller.java
Created June 4, 2016 03:26
api caller with okhttp
import android.os.Handler;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
* Created by shogo on 2016/06/04.
*/
public class BookmarkApiCaller extends ApiCaller {
private TextView mTextView;
public BookmarkApiCaller (TextView textView) {
mTextView = textView;
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.shogonir.android_individual.MainActivity">
@shogonir
shogonir / SelfSample
Created October 3, 2016 13:34
Self type sample code implemented with Scala.
package SelfSample
/**
* Created by shogo on 2016/10/03.
*/
trait MiddleValue {
def middle (list: List[Double]): Double
}
package process
import scala.sys.process._
/**
* Created by shogo on 2016/10/19.
*/
object ProcessSample {
def main(args: Array[String]) {
@shogonir
shogonir / ProcessSample2.scala
Created October 18, 2016 16:06
check data dog-agent is running
package process
import scala.sys.process._
/**
* Created by shogo on 2016/10/19.
*/
object ProcessSample {
def main(args: Array[String]) {
@shogonir
shogonir / SysEnv.scala
Created November 1, 2016 14:56
Read environmental variable with Scala.
object SysEnv {
def main(args: Array[String]) {
sys.env.getOrElse("USER", "default") match {
case value: String =>
println(value)
case _ =>
println("not string")
}
}
@shogonir
shogonir / sleep.html
Created November 4, 2016 13:09
sleep with JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Web Worker 99</title>
</head>
<body>
<script type="text/javascript">
def drawLine (point1, point2) :
points = []
try :
slope = 1.0 * (point2.y - point1.y) / (point2.x - point1.x)
if abs(slope) > 1.0 :
top, bottom = (point1, point2) if point1.y > point2.y else (point2, point1)
for y in range(bottom.y, top.y + 1) :
progress = 1.0 * (y - bottom.y) / (top.y - bottom.y)
x = int(bottom.x + progress * (top.x - bottom.x))
points.append(Vector2(x, y))