Skip to content

Instantly share code, notes, and snippets.

@totem3
totem3 / get
Created December 3, 2011 14:06
GetのResponseどうやって受け取れば。。(´・ω・`)
import java.io._
import java.net._
import sun.net.www.protocol.http.HttpURLConnection
val url = new URL("http://api.tabelog.com/Ver2.1/RestaurantSearch/?key=value")
val http = url.openConnection.asInstanceOf[HttpURLConnection]
http.setRequestMethod("GET")
@totem3
totem3 / foo.html
Created December 15, 2011 01:08
ajaxButtonのためのビュー
<lift:surround with="default" at="content">
<lift:Foo.foo>
<foo:button />
<div id="set-here" />
</lift:Foo.foo>
</lift:surround>
@totem3
totem3 / Foo.scala
Created December 15, 2011 01:09
ajaxButtonのためのSnippet
class Foo {
def foo(xhtml:NodeSeq):NodeSeq = {
bind("foo", xhtml,
"button" -> ajaxButton("PressMe!", //ボタンに表示される文字列
()=>SetHtml("set-here", Text("FooBarBaz!")) //クリック時の処理。ここではidがset-hereのdiv要素に"FooBarBaz!"をセットする
)
)
}
}
@totem3
totem3 / AjaxText.scala
Created December 16, 2011 03:36
ajaxText
class AjaxTextTest {
def greeting(xhtml:NodeSeq):NodeSeq = {
bind("greeting", xhtml,
"text" -> ajaxText("YourName", (s:String)=> SetHtml("here", Text("Hello, " + s + "!")))
)
}
def greeting2(xhtml:NodeSeq):NodeSeq = {
bind("greeting", xhtml,
"text" -> ajaxText("YourName", true, (s:String)=> SetHtml("here2", Text("Hello, " + s + "!")))
@totem3
totem3 / CssSelectorTest.scala
Created December 16, 2011 15:03
CSS Selector便利。。
class CssSelectorTest {
val alert = Run("alert('まじかよ!')")
val unitToAlert = () => alert
val strToAlert = (s:String) => alert
def selector = {
".text" #> <p>文字列でも?</p> &
"#button" #> ajaxButton("ボタンも置けるの?", unitToAlert) &
"@input" #> ajaxText("これも??", (s:String) => alert) &
".text2 *+" #> "置き換わっちゃうのもこうすれば!!" &
"button" #> "元ボタンです" &
@totem3
totem3 / :info Int
Created February 4, 2012 09:05
てへぺろ(・ω<)(ghciでutf-8の表示の仕方が分からなかったので妥協)
data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in GHC.Types
instance Bounded Int -- Defined in GHC.Enum
instance Enum Int -- Defined in GHC.Enum
instance Eq Int -- Defined in GHC.Base
instance Integral Int -- Defined in GHC.Real
instance Num Int -- Defined in GHC.Num
instance Ord Int -- Defined in GHC.Base
instance Read Int -- Defined in GHC.Read
instance Real Int -- Defined in GHC.Real
instance Show Int -- Defined in GHC.Show
@totem3
totem3 / prac_ch4.hs
Created February 5, 2012 13:38
プログラミングHaskell第4章練習問題 むむむずい
--1
halve :: [a] -> ([a], [a])
halve xs = (take len xs, drop len xs)
where
len = fromIntegral (length xs) `div` 2
--2
-- if
safetail :: (Eq a) => [a] -> [a]
safetail xs = if xs == [] then [] else drop 1 xs
@totem3
totem3 / prac_ch5.hs
Created February 9, 2012 15:07
プログラミングHaskell第5章練習問題
-- 1
-- square = sum [x^2 | x <- [1 .. 100]
--2
replicate :: Int -> a -> [a]
replicate n x = [x | _ <- [1 .. n]]
--3
pyths :: Int -> [(Int,Int,Int)]
pyths n = [(x,y,z) | x <- [1..n], y<-[1..n], z<-[1..n], x^2+y^2==z^2]
@totem3
totem3 / prac_ch6.hs
Created February 10, 2012 06:21
プログラミングHaskell第6章練習問題 むむむむむ
--1
power :: Int -> Int -> Int
power m n | n < 0 = 0
| n == 0 = 1
| otherwise = m * power m (n-1)
{-
power 2 3
2 * ( power 2 2 )
2 * 2 * ( power 2 1)
2 * 2 * 2 * ( power 2 0)
@totem3
totem3 / prac_ch7.hs
Created February 11, 2012 23:42
プログラミングHaskell第7章練習問題(´;ω;`)ブワッ
-- 8, 9がわかりましぇん(´;ω;`)ブワッ
import Data.Char
--1
--[f x|x <- xs, p x]
--
--(map f).(filter p)
--2