<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: magic code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 12:07:30 GMT</pubDate>
    <description>DZone Snippets: magic code</description>
    <item>
      <title>Remove magic quotes on GPC data</title>
      <link>http://snippets.dzone.com/posts/show/5257</link>
      <description>Removes magic quotes on $_GET, $_POST, $_COOKIE, $_FILES and $_REQUEST, when they are enabled.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;// remove magic_quotes&lt;br /&gt;if(get_magic_quotes_gpc())&lt;br /&gt;{&lt;br /&gt;  function undo_magic_quotes_array($array)&lt;br /&gt;  {&lt;br /&gt;    return is_array($array) ? array_map('undo_magic_quotes_array', $array) : str_replace("\\'", "'",&lt;br /&gt;							                                                               str_replace("\\\"", "\"",&lt;br /&gt;                                                                             str_replace("\\\\", "\\",&lt;br /&gt;                                                                             str_replace("\\\x00", "\x00", $array))));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  $_GET = undo_magic_quotes_array($_GET);&lt;br /&gt;  $_POST = undo_magic_quotes_array($_POST);&lt;br /&gt;  $_COOKIE = undo_magic_quotes_array($_COOKIE);&lt;br /&gt;  $_FILES = undo_magic_quotes_array($_FILES);&lt;br /&gt;  $_REQUEST = undo_magic_quotes_array($_REQUEST);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 19 Mar 2008 15:31:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5257</guid>
      <author>albert006 (Albert Peschar)</author>
    </item>
    <item>
      <title>Remove magic quotes on GPC data</title>
      <link>http://snippets.dzone.com/posts/show/5256</link>
      <description>Removes magic quotes on $_GET, $_POST, $_COOKIE, $_FILES and $_REQUEST, when they are enabled.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;// remove magic_quotes&lt;br /&gt;if(get_magic_quotes_gpc())&lt;br /&gt;{&lt;br /&gt;  function undo_magic_quotes_array($array)&lt;br /&gt;  {&lt;br /&gt;    return is_array($array) ? array_map('undo_magic_quotes_array', $array) : str_replace("\\'", "'",&lt;br /&gt;							                                                               str_replace("\\\"", "\"",&lt;br /&gt;                                                                             str_replace("\\\\", "\\",&lt;br /&gt;                                                                             str_replace("\\\x00", "\x00", $array))));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  $_GET = undo_magic_quotes_array($_GET);&lt;br /&gt;  $_POST = undo_magic_quotes_array($_POST);&lt;br /&gt;  $_COOKIE = undo_magic_quotes_array($_COOKIE);&lt;br /&gt;  $_FILES = undo_magic_quotes_array($_FILES);&lt;br /&gt;  $_REQUEST = undo_magic_quotes_array($_REQUEST);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 19 Mar 2008 15:31:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5256</guid>
      <author>albert006 (Albert Peschar)</author>
    </item>
    <item>
      <title>magic square demo</title>
      <link>http://snippets.dzone.com/posts/show/1155</link>
      <description>&lt;code&gt;&lt;br /&gt;REBOL [&lt;br /&gt;    Title:  "Magic Square program"&lt;br /&gt;    Author: "Gregg Irwin"&lt;br /&gt;    Comment: {&lt;br /&gt;        Credit to Bob Kurosaka and Martin Gardener for inspiration.&lt;br /&gt;    }&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;get-size: has [result] [&lt;br /&gt;    print "Enter the size of the square's side."&lt;br /&gt;    print ""&lt;br /&gt;    result: to-integer ask "It must be an odd number larger than 1 : "&lt;br /&gt;    if any [(result &lt; 3) (even? result)] [get-size]&lt;br /&gt;    result&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;edge-guard: does [&lt;br /&gt;    if row &lt; 1    [row: row + side]&lt;br /&gt;    if col &gt; side [col: col - side]&lt;br /&gt;    if row &gt; side [row: row - side]&lt;br /&gt;    if col &lt; 1    [col: col + side]&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;print-square: func [square side] [&lt;br /&gt;    print ["Magic Square, Order " side]&lt;br /&gt;    print ["Each row, col, and Diagonal add up to " side * (side ** 2 + 1) / 2]&lt;br /&gt;    print ""&lt;br /&gt;    repeat row side [&lt;br /&gt;        repeat col side [&lt;br /&gt;            prin [pick square/:row col tab]&lt;br /&gt;        ]&lt;br /&gt;        print ""&lt;br /&gt;    ]&lt;br /&gt;    print ""&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;magic-square: func [/size sz [integer!]] [&lt;br /&gt;    side: either size [sz][get-size]&lt;br /&gt;    row: 1&lt;br /&gt;    col: (side + 1) / 2         ;Locate the starting cell&lt;br /&gt;    square: array/initial reduce [side side] 0&lt;br /&gt;    poke square/:row col 1      ;Initialize the first value&lt;br /&gt;&lt;br /&gt;    for i 2 to-integer (side ** 2) 1 [&lt;br /&gt;        row: row - 1&lt;br /&gt;        col: col + 1                  ;Northeast move&lt;br /&gt;        edge-guard&lt;br /&gt;        if 0 &lt;&gt; pick square/:row col [&lt;br /&gt;            row: row + 1              ;otherwise retreat&lt;br /&gt;            col: col - 1&lt;br /&gt;            row: row + 1              ;Break move&lt;br /&gt;            edge-guard&lt;br /&gt;        ]&lt;br /&gt;        poke square/:row col i&lt;br /&gt;    ]&lt;br /&gt;    print-square square side&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;;-- 0 based version --&lt;br /&gt;&lt;br /&gt;; print-square: func [square side] [&lt;br /&gt;;     print ["Magic Square, Order " side]&lt;br /&gt;;     print ["Each row, col, and Diagonal add up to " side * (side ** 2 + 1) / 2  - side]&lt;br /&gt;;     print ""&lt;br /&gt;;     repeat row side [&lt;br /&gt;;         repeat col side [&lt;br /&gt;;             prin [pick square/:row col tab]&lt;br /&gt;;         ]&lt;br /&gt;;         print ""&lt;br /&gt;;     ]&lt;br /&gt;;     print ""&lt;br /&gt;; ]&lt;br /&gt;; &lt;br /&gt;; magic-square: func [/size sz [integer!]] [&lt;br /&gt;;     side: either size [sz][get-size]&lt;br /&gt;;     row: 1&lt;br /&gt;;     col: (side + 1) / 2         ;Locate the starting cell&lt;br /&gt;;     square: array/initial reduce [side side] none&lt;br /&gt;;     poke square/:row col 0      ;Initialize the first value&lt;br /&gt;; &lt;br /&gt;;     repeat i to-integer (side ** 2) - 1 [&lt;br /&gt;;         row: row - 1&lt;br /&gt;;         col: col + 1                  ;Northeast move&lt;br /&gt;;         edge-guard&lt;br /&gt;;         if none &lt;&gt; pick square/:row col [&lt;br /&gt;;             row: row + 1              ;otherwise retreat&lt;br /&gt;;             col: col - 1&lt;br /&gt;;             row: row + 1              ;Break move&lt;br /&gt;;             edge-guard&lt;br /&gt;;         ]&lt;br /&gt;;         poke square/:row col i&lt;br /&gt;;     ]&lt;br /&gt;;     print-square square side&lt;br /&gt;; ]&lt;br /&gt;&lt;br /&gt;;-- End 0 based version --&lt;br /&gt;&lt;br /&gt;magic-square&lt;br /&gt;;magic-square/size 5&lt;br /&gt;&lt;br /&gt;halt&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Jan 2006 04:29:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1155</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
