Skip to content

Instantly share code, notes, and snippets.

import Data.List (foldl', intercalate)
import Test.HUnit (Test(..), runTestTT, (~=?))
process :: String -> String
process = intercalate "," . map show . take 10 . foldl' transf [1..]
isSquare n = let x = sqrt (fromIntegral n) in x - fromIntegral (floor x) == 0
--isCube n = let x = (fromIntegral n) ** (1 / 3) in x - fromIntegral (floor x) == 0
isCube n = round (fromIntegral n ** (1 / 3)) ^ 3 == n
Inductive term : Type :=
| Ttrue : term
| Tfalse : term
| Tifthenelse : term -> term -> term -> term.
Inductive evaluate : term -> term -> Prop :=
| Eiftrue : forall t2 t3, evaluate (Tifthenelse Ttrue t2 t3) t2
| Eiffalse : forall t2 t3, evaluate (Tifthenelse Tfalse t2 t3) t3
| Eif : forall t1 t1' t2 t3, evaluate t1 t1' -> evaluate (Tifthenelse t1 t2 t3) (Tifthenelse t1' t2 t3).
Inductive term : Type :=
| Ttrue : term
| Tfalse : term
| Tifthenelse : term -> term -> term -> term.
Inductive evaluate : term -> term -> Prop :=
| Eiftrue : forall t2 t3, evaluate (Tifthenelse Ttrue t2 t3) t2
| Eiffalse : forall t2 t3, evaluate (Tifthenelse Tfalse t2 t3) t3
| Eif : forall t1 t1' t2 t3, evaluate t1 t1' -> evaluate (Tifthenelse t1 t2 t3) (Tifthenelse t1' t2 t3).
Inductive term : Type :=
| Ttrue : term
| Tfalse : term
| Tifthenelse : term -> term -> term -> term.
Inductive evaluate : term -> term -> Prop :=
| Eiftrue : forall t2 t3, evaluate (Tifthenelse Ttrue t2 t3) t2
| Eiffalse : forall t2 t3, evaluate (Tifthenelse Tfalse t2 t3) t3
| Eif : forall t1 t1' t2 t3, evaluate t1 t1' -> evaluate (Tifthenelse t1 t2 t3) (Tifthenelse t1' t2 t3).
@takeouchida
takeouchida / Main.scala
Created January 22, 2015 14:08
spray-client proxy example based on a code in spray repository
package clientwithproxy
import akka.util.Timeout
import spray.can.Http.ClientConnectionType
import scala.util.{Success, Failure}
import scala.concurrent.duration._
import akka.actor.ActorSystem
import akka.pattern.ask
import akka.event.Logging
@takeouchida
takeouchida / log.py
Created June 25, 2015 02:22
A way to log
import os
import traceback
# Write a message to /var/log/hoge.log
os.system("echo `date '+%Y/%m/%d %H:%M:%S.%N'` 'Some message' >> /var/log/hoge.log")
# Write a traceback to /var/log/hoge.log
os.system("echo `date '+%Y/%m/%d %H:%M:%S.%N'` '" + traceback.format_exc() + "' >> /var/log/hoge.log")
@takeouchida
takeouchida / json.hs
Created September 9, 2011 15:03
Tiny JSON Parser
import Control.Applicative ((<$>), (<$), (<*>), (<*), (*>))
import Prelude hiding (null)
import Text.Parsec hiding (string)
import Text.Parsec.Language (javaStyle)
import qualified Text.Parsec.Token as P
data Value = S String | N Double | O [(String, Value)] | A [Value] | B Bool | Null deriving Show
lexer = P.makeTokenParser javaStyle
symbol = P.symbol lexer
@takeouchida
takeouchida / Lookup.hs
Created December 3, 2011 05:32
An example of missing some kinds of type constraints.
module Lookup where
import Prelude hiding (lookup)
lookup :: a -> [(a, b)] -> Maybe b -- valid if the type a is a kind of Eq instances
lookup k [] = Nothing
lookup k ((k', v):ls) = if k == k' then Just v else lookup k ls
@takeouchida
takeouchida / state.dump-asm
Created February 26, 2012 15:33
A code snippet using Strict State Monad
_Main_mainzuzdszdwa_info:
Lc2q2:
addq $40,%r12
cmpq 144(%r13),%r12
ja Lc2q7
cmpq $100,%r14
jg Lc2qb
movq %rsi,%rax
addq %r14,%rax
incq %r14
@takeouchida
takeouchida / div2_double.v
Created March 26, 2012 15:19
x * 2 / 2 = x
Require Import Div2.
Theorem div2_double : forall x, div2 (double x) = x.
intro x.
induction x.
reflexivity.
unfold double.
unfold double in IHx.
rewrite plus_Sn_m.