Skip to content

Instantly share code, notes, and snippets.

View taisukeoe's full-sized avatar

Taisuke Oe taisukeoe

  • Japan Scala Association, Inc.
  • Tokyo
  • X @OE_uia
View GitHub Profile
@taisukeoe
taisukeoe / gist:6343272
Last active December 21, 2015 17:49
awscala.ec2.Instanceに、単純なssh/scpをscala-ssh非依存で実行させてみるてすつ。
def process(command: String, keyPairFile: File, sshOption: String = "-o StrictHostKeyChecking=no -t -t"): Either[String, String] = {
import sys.process._
try {
Right(s"echo ${command}" #&& "echo exit" #> s"ssh ${sshOption} -i ${keyPairFile.getAbsolutePath} ec2-user@${publicDN}" !!)
} catch { case e: Exception => Left(e.toString) }
}
def scp(file: File, keyPairFile: File, scpOption: String = "-o StrictHostKeyChecking=no"): Either[String, String] = {
import sys.process._
try {
@taisukeoe
taisukeoe / UIDemoActivity.scala
Last active April 16, 2017 05:01
How to force to execute Future callback function in Android UIThread.
import scala.concurrent._
import ExecutionContext.Implicits.global
import android.util.Log
import android.widget.TextView
class UIDemoActivity extends Activity {
override def onCreate(bundle: Bundle) {
super.onCreate(bundle)
val tv = new TextView(this)
@taisukeoe
taisukeoe / gist:052a252bcb3aeda5f853
Created June 5, 2014 06:15
Xcode 6 beta crash report in opening .sks file
Process: Xcode [742]
Path: /Applications/Xcode6-Beta.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 6.0 (6194.21)
Build Info: IDEFrameworks_KLONDIKE-6194021000000000~12
Code Type: X86-64 (Native)
Parent Process: launchd [172]
Responsible: Xcode [742]
User ID: 502
@taisukeoe
taisukeoe / Calculator.scala
Created September 1, 2014 15:43
某勉強会の予定を調整さんに投げる用プロジェクト
import com.github.nscala_time.time.Imports._
import annotation.tailrec
import org.joda.time.DateTimeConstants
object Calculator extends App{
val start = nextMonday(DateTime.now.toLocalDate)
val days = start :: Stream.iterate(start + 1.day)(_ + 1.day).takeWhile(_.getDayOfWeek != DateTimeConstants.MONDAY).toList
val result = days.map {
@taisukeoe
taisukeoe / dna.scala
Last active August 29, 2015 14:10
for rosalind
package hemplant.rosalind.dna
sealed abstract trait Nucleotide{
def complementary:Nucleotide = Nucleotide.complementary(this)
}
case object A extends Nucleotide
case object T extends Nucleotide
case object G extends Nucleotide
case object C extends Nucleotide
@taisukeoe
taisukeoe / pattaernMatch.scala
Created February 21, 2015 13:36
パターンマッチの網羅性チェックとifガード節
scala> def func(s:Option[String]) = s match{case Some(x) if x.size > 0 => x}
func: (s: Option[String])String
scala> def func(s:Option[String]) = s match{case Some(x) => x}
<console>:7: warning: match may not be exhaustive.
It would fail on the following input: None
def func(s:Option[String]) = s match{case Some(x) => x}
^
func: (s: Option[String])String
@taisukeoe
taisukeoe / build.sbt
Created April 20, 2015 14:21
FizzBuzzのbench
jmhSettings
@taisukeoe
taisukeoe / callback2func.scala
Last active August 29, 2015 14:25
Break down Callback which has two ore more functions into the same number of PartialFunction
trait Callback{
def onSet(s:Set[String]):Unit
def onList(l:List[String]):Unit
}
def funcWithCallback(s:String,callback:Callback):Unit = ???
def funcAsFuture(s:String):Future[Traversable[String]] = {
val p = Promise[Traversable[String]]()
val f = p.future
funcWithCallback(s,new Callback{
@taisukeoe
taisukeoe / scalaz-streams-Task-es.scala
Last active August 29, 2015 14:26
scalaz-streamsのTask.startは、既存のTaskの実行Threadも変更できそう
import streams._
import util._
implicit val s = Strategy.fromExecutionContext(scala.concurrent.ExecutionContext.Implicits.global)
val t = Task(println(Thread.currentThread.getName))
// Exiting paste mode, now interpreting.
import streams._
import util._
s: streams.util.Strategy = streams.util.Strategy$$anon$1@60d8175
@taisukeoe
taisukeoe / projection.scala
Last active September 2, 2015 05:09
Row wise operations got weired
scala> val ndArray = (1d to 8d by 1).mkNDArray(Array(2,2,2),NDOrdering.C)
ndArray: org.nd4j.linalg.api.ndarray.INDArray =
[[[1.00,2.00]
[3.00,4.00]]
[[5.00,6.00]
[7.00,8.00]]]
scala> ndArray.sliceP.map(s => s.rowP.map(r => r*r))
res12: org.nd4j.linalg.api.ndarray.INDArray =
[[[1.00,2.00]