This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Data.List.Split | |
type Pair = (Int, Int) | |
-- | | |
-- >>> set (0, 0) 1 2 | |
-- (2,0) | |
set :: Pair -> Int -> Int -> Pair | |
set (n1, n2) 1 x = (x, n2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{Actor, Props, ActorSystem} | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
import scala.util.{Success,Failure} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
case class Message(val msg: String) | |
case class Reply(val content: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.annotation._ | |
object Factorial { | |
// @tailrec | |
def fact(n: Int) : BigInt = n match { | |
case n if n <= 1 => 1 | |
case _ => n * fact(n - 1) | |
} | |
@tailrec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Free | |
data Result s = Get s | Fail deriving Show | |
instance Functor Result where | |
fmap f (Get x) = Get (f x) | |
fmap f Fail = Fail | |
liftF' :: Functor f => f r -> Free f r | |
liftF' cmd = Free (fmap Pure cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.App | |
import scala.collection.breakOut | |
object ImplicitTest extends App { | |
val TIME = 10000 | |
case class Hoge(val id: Long, val name: String) | |
implicit class MappedList(val list: Seq[Hoge]) extends AnyVal { | |
def get(id: Long): Option[Hoge] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.App | |
object View extends App { | |
def now = System.currentTimeMillis | |
val NUM = 1000000 | |
var start = now | |
var end = now | |
println("Start not view") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
import scipy.spatial.distance as dis | |
import scipy.sparse as sp | |
import numpy as np, scipy.io as io | |
import math | |
def sparse_distance(v1, v2): | |
"""1*Nのベクトル間のユークリッド距離を求める | |
args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.{postfixOps, reflectiveCalls} | |
// https://twitter.github.io/scala_school/advanced-types.html#structural | |
// http://twitter.github.io/effectivescala/#Object%20oriented%20programming-Structural%20typing | |
object DuckTyping extends App { | |
sealed abstract class AwesomeData(id: Int) | |
case class Nice(id: Int) extends AwesomeData(id) { | |
def size: Int = id * 100 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# -*- encoding:utf-8 -*- | |
'''YahooApiを用いた検索エンジン | |
''' | |
from urllib import quote | |
from urllib2 import build_opener | |
import cgi | |
from split_result import split_result | |
import cgitb | |
cgitb.enable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding:utf-8 -*- | |
import re | |
result_pattern = '<Result>(.+?)</Result>' | |
link_pattern = '<Url>(.*?)</Url>' | |
title_pattern = '<Title>(.*?)</Title>' | |
summary_pattern = '<Summary>(.*?)</Summary>' | |
strip_pattern = r'\\n|\s' | |
catch_result = re.compile(result_pattern, re.S) | |
catch_link = re.compile(link_pattern, re.S) | |
catch_title = re.compile(title_pattern, re.S) |