Skip to content

Instantly share code, notes, and snippets.

@yamamotoj
yamamotoj / stack_machine.kt
Created February 4, 2016 01:14
Stack Machine in kotlin
class Stack(val value:Int, val succ:Stack?){
fun push(i:Int) = Stack(i, this)
fun apply(op:(Int, Int) -> Int):Stack = succ?.let{
Stack(op(value, it.value), succ.succ)
} ?: throw IllegalArgumentException()
}
fun solution(s:String):Int =s.fold<Stack?>(null){ stack , char -> when(char){
'0','1','2','3','4','5','6','7','8','9' -> stack?.let {it.push(char - '0')} ?: Stack(char- '0', null)
'+' -> stack?.let { it.apply{ x1, x2 -> x1 + x2 } } ?: throw IllegalArgumentException()
//: Playground - noun: a place where people can play
import UIKit
class Pole{
let left:Int
let right: Int
init(_ left:Int, _ right:Int){
self.left = left
self.right = right
@yamamotoj
yamamotoj / file0.txt
Last active August 29, 2015 14:15
String.Indexを使った文字列処理 ref: http://qiita.com/boohbah/items/795501495e1aeab6231e
let str = "ABCDEF"
let startIndex = str.startIndex // 文字列の最初のIndexを取得
let endIndex = str.endIndex // 文字列中の最後のIndexを取得
@yamamotoj
yamamotoj / file0.txt
Created February 12, 2015 16:43
Swift 1.2のif let複数宣言と例外処理 ref: http://qiita.com/boohbah/items/84e9d76a8ceaf9f56077
func getA()->String?{
return "A"
}
func getB()->String? {
return "B"
}
func getC()->String?{
@yamamotoj
yamamotoj / CalcParser.hs
Last active May 16, 2016 23:54
Programming in Haskell Chapter9
module CalcParser where
import Data.Char
type Parser a = String -> [(a, String)]
return' :: a -> Parser a
return' v = (\inp -> [(v, inp)])
item :: Parser Char
item = (\inp -> case inp of [] -> []
@yamamotoj
yamamotoj / parser.hs
Last active August 29, 2015 14:11
Programming in Haskell Chapter 8
import Prelude hiding(return, (>>=), (>>))
import Data.Char
type Parser a = String -> [(a, String)]
return :: a -> Parser a
return v = (\inp -> [(v, inp)])
item :: Parser Char
item = (\inp -> case inp of [] -> []
from evernote.api.client import EvernoteClient
import evernote.edam.type.ttypes as Types
import sys
import hashlib
import time
import mimetypes
# dev_token = "S=s1:U=90bdf:E=1544ee17084:C=14cf7304108:P=1cd:A=en-devtoken:V=2:H=e20c8d80dd09580a5fb802a77d1c0eb8"
dev_token="S=s1:U=90bdf:E=154519873c0:C=14cf9e746d0:P=81:A=jyamamoto:V=2:H=bf7a268d7243962ccf4d49e520b21049"