http://watson1978.github.com/MacRuby-DoJo/blog/2012/03/10/search_tweets/
tableviewの左側のnameをfrom_userに変更しています
# digit : 一桁の数字 | |
# roman : その桁の1, 5, 10を表す文字三文字 (ex: 'IVX') | |
def digit2roman(digit, roman) | |
a, b, c = roman.split(//) | |
case digit | |
when 0 then '' | |
when 1..3 then a * digit | |
when 4 then a + b | |
when 5 then b |
twitterにあったワンライナーを展開すると以下のようになる | |
> f = foldl io (return "go") [1,2,3] | |
> io io_x _ = do | |
> x <- io_x | |
> putStrLn x | |
> io_x | |
foldlの定義は以下の通り |
class AppDelegate | |
attr_accessor :window | |
def initialize | |
@contents = [ | |
{'name' => 'hoge', 'age' => '123'}, | |
{'name' => 'fuga', 'age' => '456'} | |
] | |
end |
http://watson1978.github.com/MacRuby-DoJo/blog/2012/03/10/search_tweets/
tableviewの左側のnameをfrom_userに変更しています
import System.Random (randomRIO) | |
import Data.List (subsequences) | |
import Control.Applicative ((<$>)) | |
import Control.Monad (replicateM) | |
main :: IO () | |
main = test 4 10 | |
test :: Int -> Int -> IO () |
if ! (( $+functions[_z] )); then | |
return | |
fi | |
function zaw-src-z() { | |
# <rank><space><dir> の組でくるので、そこからdirだけ抜き取る | |
: ${(A)candidates::=${${(f)"$(z -l | sort -n -r)"}##<->(.<->)# ##}} | |
actions=(zaw-src-z-cd) | |
act_descriptions=("cd") | |
} |
local ztarget | |
z-recommend() { | |
local datafile="${_Z_DATA:-$HOME/.z}" | |
LBUFFER+=$KEYS | |
fnd=$LBUFFER | |
ztarget="$(while read line; do | |
[ -d "${line%%\|*}" ] && echo $line | |
done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" ' | |
function frecent(rank, time) { |
dbname = "hoge" | |
access' action = do | |
pipe <- DB.runIOE $ DB.connect (DB.host "localhost") | |
DB.access pipe DB.master dbname action | |
mapFn = Bson.Javascript [] "function() {for(i in this.category) {emit(this.category[i], 1);}}" | |
reduceFn = Bson.Javascript [] "function(p, cur) {var c=0; for(i in cur){c+= cur[i];}; return c;}" | |
mapReduce = DB.mapReduce "Pkg" mapFn reduceFn |
import Control.Monad (mplus) | |
data Token = TInt Int | |
| Operator (Int -> Int -> Int) | |
sample :: String | |
sample = "10 4 3 + 2 * -" | |
calc :: String -> Int | |
calc = calc' [] . tokenize |
type Point = (Int, Int) | |
type Section = (Int, Int, Int) | |
data Label = A | B | C deriving Show | |
data Route = Route { path :: [(Label, Int)], distance :: Int } deriving Show | |
input :: [Section] | |
input = [(50, 10, 30), (5, 90, 20), (40, 2, 25), (10, 8, 0)] | |
zeroRoute :: Route | |
zeroRoute = Route { path = [], distance = 0 } |