繰り返し続くようなinputデータからJSONデータを作る

構造化されたデータをポストしたいときのメモ
HTMLが直接表示されやがる…バグ?

https://github.com/yokotaso/memo/blob/master/2013-08-25/structred_input/sample.html

昔のコードだといろいろやり方はあったけど、あまり具合が良くなかった。

<!-- 過去のコードのその1 -->
<select name="evaluationObject_1">...</select>
<select name="evaluationMethod_1">...</select>
<input name="matchData_1"/>
<!-- 以下、繰り返し -->

<!-- 過去のコードのその2 -->
<select name="condition[0][evaluationObject]">...</select>
<select name="condition[0][evaluationMethod]">...</select>
<input name="condition[0][matchData]"/>
<!-- 以下、繰り返し -->

サーバーでは、jsonをdecodeするだけにして、楽したいよねっていう

      (function(){
       "use strict";
           var conditions = [];
           jQuery(".conditions").each(function(index) {
             var eachCondition = {};
             var conditionSelector = ".conditions:eq(%index%)".replace("%index%",index);
             eachCondition.evaluationMethod 
                 = jQuery(conditionSelector + " > [name=evaluationObject]").val();
             eachCondition.evaluationObject 
                 = jQuery(conditionSelector + " > [name=evaluationObject]").val();
             eachCondition.matchData
                 = jQuery(conditionSelector + " > [name=matchData]").val();
             conditions.push(eachCondition);
             });
           console.log(JSON.stringify(conditions));
       })();

PHP5.3.9以降でmax_input_varsを超えるPOSTデータが失われる件

PHP5.3.9でhashdosの脆弱性の対応が入っているのですが、PHP5.3.9以降では、max_input_varsを
超えてしまうと、そこから後ろの$_POSTのデータがごっそり失われてしまう。
PHP5.3.9で改修が複数回行われていて、パッチあてて、再ビルドとかするといきなり動かなくなるかもしれない。
注意。

問題は、配列を使って、何かをPOSTしたとき
http://www.php.net/manual/ja/faq.html.php#faq.html.arrays

<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyOtherArray[]" />
<input name="MyOtherArray[]" />


これがHashDOSの攻撃の関係で、このときにボディに入ってくる値は4個としてカウントされる。
https://github.com/php/php-src/commit/282d3f20349b78eeed0173a2e55d311324faeb4d

ここのコミット以前は、ボディに入ってくる値のカウントとしては2個としてカウントされていた。

例えば、ユーザーを1000人突っ込むために

<input name="group[]" />
<input name="group[]" />
...
...
...
<input name="group[]" />

max_input_vars+1以降のパラメータの値が失われてしまう。

この仕様変更は
http://www.serverphorums.com/read.php?7,425749,426342#msg-426342

> Hi!
>
>
>> and different with the fix which was commited now, this patch count
>> the num vars in a global scope, that means if there are 2 elements
>> which both have 500 elements in post, the restriction will also
>> affect,
>
>
> Why? The point of the limitation is to avoid hash collisions and related
> performance problems, but if they are in different elements, what is the
> point of limiting them?
>
Hi, this patch is aim at a quick/simple fix than before, that is why I
proposal this patch.

actually, there might be no attack even a array has more than 1000 elements,

I mean, this is a simple / quick fix but works the same.

thanks

ここで議論されていて、立派な仕様変更だとおもうんだけど、適当すぎやろ!っていう叫びでした。

Programing in Haskell / Chapter.11

Programing in Haskell The countdown problem P.116-120
気がつけば6月、ちょっとサボってしまいました…

再帰のコードの書き方が今だにどういう発想でといていくのか理解できない。コードをみれば、どういう風に動いているかは追跡ができるんだけど…実際に自分で考えるとなると難しいですなー

subs :: [a] -> [[a]]
subs [] = [[]]
subs (x:xs) = yss ++ map (x:) yss
              where yss = subs xs

interleave :: a -> [a] -> [[a]]
interleave x []     = [[x]]
interleave x (y:ys) = (x:y:ys):map (y:) (interleave x ys)

perms :: [a] -> [[a]]
perms []     = [[]]
perms (x:xs) = concat (map (interleave x) (perms xs))

-- P.119のeがなかなか書くのがめんどくさいので定義しておきます
e = (App Mul (App Add (Val 1) (Val 50)) (App Sub (Val 25)  (Val 10)))

ちょっと更新頻度がんばりたいです。

Programing in Haskell / Chapter.9 Excsise(3)

Nimというゲームを作る。画面は割と簡単にできたけど、入力を受け付けてIntに変換ができない!!

> type Row                      = Int
> initialNim                    :: [Row]
> initialNim                    = [9,8,7,6,5,4,3,2,1]
>
> nimToStar                     :: Int -> String
> nimToStar n                   = take n (repeat '*')
>
> putStar                       :: (Pos, Int) -> IO ()
> putStar ((x, y), num)          = writeat (x, y) (nimToStar num)
>
>
> showNim                       :: [Row] -> IO ()
> showNim row                   =  do { cls
>                                     ; putLines pair
>                                     }
>                                     where
>                                       align         = ( (length row) + 30 ) `div` 10
>                                       pair          = zip [1..(length row)] row
>                                       putLines pair = case pair of
>                                                       [] -> return ()
>                                                       ((y, num):rest) -> do { writeat (1,     y) ((show y) ++ ":")
>                                                                             ; writeat (align, y)  (nimToStar num)
>                                                                             ; putLines rest
>                                                                             }