Candy Box Cheats

just drop this cose inside browser’s developer console 😛

//give 10000 per second
candies.candiesPerSecond = 10000;

//set how many lollipos have been planted
farm.lollipopsPlanted = 100000000;

//set max lollipos per day limit
farm.maxLollipopsPerDay = 100000000;

//add 1000000 candies
candies.setNbrOwned(candies.nbrOwned+1000000);
//add 1000000 lollipops
lollipops.setNbrOwned(lollipops.nbrOwned+1000000);

//show potions buttons (each kind)
potions.list.health.shown = 1;
potions.list.escape.shown = 1;
potions.list.berserk.shown = 1;
potions.list.fireScroll.shown = 1;
potions.list.acidRainScroll.shown = 1;
potions.list.teleportScroll.shown = 1;
potions.list.earthquakeScroll.shown = 1;
potions.list.impInvocationScroll.shown = 1;
potions.list.majorHealth.shown = 1;
potions.list.invulnerability.shown = 1;
potions.list.turtle.shown = 1;
potions.list.jelly.shown = 1;
potions.list.seed.shown = 1;
potions.list.cloning.shown = 1;
potions.list.superman.shown = 1;
potions.list.gmooh.shown = 1;
potions.updateOnPage();

//set 999 potions (each kind)
potions.list.health.nbrOwned = 999;
potions.list.escape.nbrOwned = 999;
potions.list.berserk.nbrOwned = 999;
potions.list.fireScroll.nbrOwned = 999;
potions.list.acidRainScroll.nbrOwned = 999;
potions.list.teleportScroll.nbrOwned = 999;
potions.list.earthquakeScroll.nbrOwned = 999;
potions.list.impInvocationScroll.nbrOwned = 999;
potions.list.majorHealth.nbrOwned = 999;
potions.list.invulnerability.nbrOwned = 999;
potions.list.turtle.nbrOwned = 999;
potions.list.jelly.nbrOwned = 999;
potions.list.seed.nbrOwned = 999;
potions.list.cloning.nbrOwned = 999;
potions.list.superman.nbrOwned = 999;
potions.list.gmooh.nbrOwned = 999;
potions.updateOnPage();

//hack assign "almost infinite" invulnerability potions
quest.beginInvulnerability = function(){
	this.invulnerability = true;
	this.invulnerabilityCountdown = 99999999999999999999999999;
	this.things[this.getCharacterIndex()].text = "G0D";
};

//hack assign "almost infinite" berserk potions
quest.beginBerserk = function(){
	this.berserk = true;
	this.berserkCountdown = 99999999999999999999999999;
	this.speed = this.getSpeed();
	this.things[this.getCharacterIndex()].text = "@_@";
};

Wucca.it is born!

Hi everybody! Last year I started to work to a personal project called ColtivareOrto.it with a couple of friends. Actually the project is already online and in continous development. So we decided to open a (sort of) devlog in Italian language, called Wucca.it to talk about the project itself and web developing in general. I just ended to write the first article about implement and customize a jQueryUI slider, so I’ll be glad to see some of you the new site!

Thank you!.

Caching Modules on PrestaShop

Let’s see an important examples: the category tree block (/modules/blockcategories.php)

i will show only the function that does the sql queries (that we are going to cache!).
Watch out for the Tools::getCache and Tools::setCache!

function hookLeftColumn($params)
{
	global $smarty, $cookie;

	/*  ONLY FOR THEME OLDER THAN v1.0 */
	global $link;

	//cache
	if (!$catOldTheme=Tools::getCache('blockCatOldTheme'.((!is_null($cookie->id_lang))?'_'.$cookie->id_lang:''))) //read cache
	{
		$catOldTheme=Category::getHomeCategories(intval($params['cookie']->id_lang), true);
		Tools::setCache('blockCatOldTheme'.((!is_null($cookie->id_lang))?'_'.$cookie->id_lang:''),$catOldTheme); //set cache
	}


	$smarty->assign(array(
		'categories' => $catOldTheme,
		'link' => $link
	));
	/* ELSE */

	$id_customer = intval($params['cookie']->id_customer);
	$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');

	//cache
	if (!$result=Tools::getCache('blockCatNewTheme'.((!is_null($cookie->id_lang))?'_'.$cookie->id_lang:''))) //read cache
	{
		$result=Db::getInstance()->ExecuteS('
		SELECT DISTINCT c.*, cl.*
		FROM `'._DB_PREFIX_.'category` c
		LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.intval($params['cookie']->id_lang).')
		LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
		WHERE 1'
		.(intval($maxdepth) != 0 ? ' AND `level_depth` <= '.intval($maxdepth) : '').'
		AND (c.`active` = 1 OR c.`id_category`= '.Configuration::get('PS_DB_macroCatIdHome').')
		AND cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
		ORDER BY `level_depth` ASC, cl.`name` ASC');
		Tools::setCache('blockCatNewTheme'.((!is_null($cookie->id_lang))?'_'.$cookie->id_lang:''),$result); //set cache
	}


	if (!$result)
		return;
	$resultParents = array();
	$resultIds = array();

	foreach ($result as $row)
	{
		$row['name'] = Category::hideCategoryPosition($row['name']);
		$resultParents[$row['id_parent']][] = $row;
		$resultIds[$row['id_category']] = $row;
	}

	$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
	$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
	$smarty->assign('isDhtml', $isDhtml);

	$this->currentCategoryId = NULL;
	if (isset($_GET['id_category']))
	{
		$cookie->last_visited_category = intval($_GET['id_category']);
		$this->currentCategoryId = intval($_GET['id_category']);
	}
	if (isset($_GET['id_product']))
	{
		if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category))))
		{
			$product = new Product(intval($_GET['id_product']));
			if (isset($product) AND Validate::isLoadedObject($product))
				$cookie->last_visited_category = intval($product->id_category_default);
		}
		$this->currentCategoryId = intval($cookie->last_visited_category);
	}

	$htmlOutput = $this->htmlTree($blockCategTree);
	$smarty->assign('htmlOutput', $htmlOutput);
	return $this->display(__FILE__, 'blockcategoriesnew.tpl');
}

with the first call, the getCache, we are checking if there is cached content on disk, and if it’s true, the cached content will be returned inside the $result variable.
If there is no cache content, the prestashop’s original code will run and the saved to disk with setCache method! easy uh?
The only thing that is missing is the deleting of this cached content (needed to update cached content with updated database data). I found to way to do this.

  • crontab: put a script that directly delete cached file on disk every hour/day (as you like)
  • right after database changes: put a delCache call inside postProcess() method definition on administration class (the ones that extends AdminTab) eg.: /admin/tabs/AdminCategories.php (we will see that more in details on last caching tutorial)
  • manually: delete cache manually when you have updated the interested records (in this example, the categories tables)

See you on next post to learn how cache modules!

Caching PrestaShop

hello everybody. actually i’m working for a webagency and i used prestashop to develop an ecommerce with over 3700 products and over 250 categories. pretty huge uh?

well prestashop it’s easy to develop and extend, but it’s not so optimized.. so it’s easy to run into slow queries and server freezes with over 1300 visitors per day. So i had to cache some of biggest queries, like categories tree and subcategories, blocks and products. With those expedients i lowered the number of queries from 200 per page to nearly 40 (there are a lot, i know.. but it’s prestashop, not my fault.)
so let’s start with the fixes! 🙂

first of all, let’s define two variable for our caching system, like the directory path of our cached content. open defines.inc.php and declare a variable, like i did

define('_SQL_CACHING_',  true); //set it to true to enable caching!
define('_PS_CACHE_DIR_',  __PS_BASE_URI__.'cache/'); //cache path!

then make that directory and give it write permissions.

then, let’s introduce some cache functions inside the Tools class file.

	static public function setCache($var,$data,$dir='sql/')
	{
		if (!_SQL_CACHING_) return;

		$path=_PS_CACHE_DIR_;

		$dir.=($var%100).'/'.$var.'/';
		$data=serialize($data);

		$path.=$dir;
		@mkdir($path,0777,true);
		@chmod($path,0777);
		$file=$path.$var.'.cache';

		@file_put_contents($file,$data);
		@chmod($file,0777);
	}

	static public function getCache($var,$dir='sql/')
	{
		if (!_SQL_CACHING_) return false;

		$path=_PS_CACHE_DIR_;

		$dir.=($var%100).'/'.$var.'/';
		$path.=$dir;
		$file=$path.$var.'.cache';

		if (file_exists($file))
		{
			$data=@file_get_contents($file);
			return unserialize($data);
		}
		else return false;
	}

	static public function delCache($var,$dir='sql/')
	{
		if (!_SQL_CACHING_) return false;

		if(!function_exists('rmdirr'))
		{
			function rmdirr($dir)
			{
				if (@file_exists($dir))
				{
					if (@is_dir($dir))
					{
						foreach(glob($dir."/*") as $obj)
							@is_dir($obj)? rmdirr($obj) : @unlink($obj);
						@rmdir($dir);
					}
					else @unlink($dir);
				}
			}
		}

		$path=_PS_CACHE_DIR_.$dir.($var%100).'/'.$var.'*';
		foreach(glob($path) as $filename)
			rmdirr($filename);
	}

let’s examine that functions.. we have:

  • setCache($var,$data,$dir=’sql/’): write cached data to disk
  • getCache($var,$dir=’sql/’): read cached data from disk
  • delCache($var,$dir=’sql/’): delete cached data from disk

how to use those function (parameters explaination)

  • $var: it’s the variable/file-on-disk name. it must be unique or a cached content will replace another one!
  • $data: it’s the data that we want to cache. it can be anything: simple variable, array, object..
  • $dir: it’s the subdirectory of cache path. I use it to differentiate caching path of blocks from main pages, for example.

where to use those functions?
well we have exactly three points where to use these functions: modules (on blocks), pages, single objects.

  • modules: we have to act inside the module files. normally the main file (same name of module’s directory)
  • pages: we have to act inside the files of prestashop’s root, like product.php or category.php and interact with smarty (the template engine)
  • objects: we have to act inside the ObjectModel class

On next posts i will show some examples that describes how to apply these kind of cache!

How to install latest nsmiracle.

nsmiracle is apparently stuck at version 1.2.2 published in 11-07-2008 as shown on his official website.

but that’s not true because is still in development and a currently updated version can be retrieved by using subversion (svn).

let’s see how to proceed.

1) install subversion if miss it and litbool too. libtool is an automated tool that create makefile and configures. open terminal and type

sudo apt-get install subversion libtool

2) download the latest version (actually rev 97) from nsmiracle repository

svn co --username nsmiracle-dev-guest --password nsmiracleguest https://telecom.dei.unipd.it:/tlcrepos/nsmiracle-dev/trunk

3) go inside trunk: main is the nsmiracle latest release and inside addon folder there are sandbox, umts, wimax and other supplementary modules
4) copy main folder and paste wherever you want (i put it inside ns-allinone directory). i suggest to rename main folder to something that you can easily remember (“nsmiracle” for example)
5) open terminal and inside nsmiracle directory type in order (configure need your actually paths. i left mine just for example)

$ ./autogen.sh
$ ./configure --with-ns-allinone=/home/lotti/Scrivania/ns/ns-allinone-2.34 --prefix=/home/lotti/Scrivania/ns/ns-allinone-2.34 --disable-static --with-dei80211mr=/home/lotti/Scrivania/ns/ns-allinone-2.34/dei80211mr-1.1.4
$ make
$ make install

6) now you’re ready to use nsmiracle

if you need to use also addons here there is an example

1) copy the wanted addon directory inside nsmiracle directory
2) open a terminal and go to the addon freshly pasted directory
3) type (always use your actual paths!):

$ ./autogen.sh
$ ./configure --with-ns-allinone=/home/lotti/Scrivania/ns/ns-allinone-2.34 --with-nsmiracle=/home/lotti/Scrivania/ns/ns-allinone-2.34/nsmiracle
$ make

that’s all.

run some samples to check if everything works. (some samples are broken – most errors are on loading libraries because of wrong paths)

Install ns-allinone-2.34 on ubuntu karmic koala 9.10 and ubuntu lucid lynx 10.04

i wrote this tutorial because official ns installation problems website actually return a blank useless page. all the credits goes to nsnam.isi.edu people.
the googled cache copy of the page is here.

WARNING: apply point 3-4 only if you noticed the error while installing ns-allinone-2.34 the first time.

 otcl.o: In function `OTclDispatch':
 /home/ns/ns-allinone-2.34/otcl/otcl.c:495: undefined reference to `__stack_chk_fail_local'
 otcl.o: In function `Otcl_Init':
 /home/ns/ns-allinone-2.34/otcl/otcl.c:2284: undefined reference to `__stack_chk_fail_local'
 ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
 ld: final link failed: Nonrepresentable section on output
 make: *** [libotcl.so] Error 1

otcl-1.13 has some compatibility issues with latest g++ (>=4.4) but ns-allinone-2.34 need it.

all you have to do to fix issues and make a successfull installation is:

0)

sudo apt-get install build-essential autoconf automake libxmu-dev

1) extract ns-allinone wherever you want. open directory, go to otcl-1.13.

2) open configure file (the one without extension)

3) search for:

    Linux*)
        SHLIB_CFLAGS=&quot;-fpic&quot;
        SHLIB_LD=&quot;ld -shared&quot;
        SHLIB_SUFFIX=&quot;.so&quot;
        DL_LIBS=&quot;-ldl&quot;
        SHLD_FLAGS=&quot;&quot;
        ;;

and replace it with

    Linux*)
        SHLIB_CFLAGS=&quot;-fpic&quot;
        SHLIB_LD=&quot;gcc -shared&quot;
        SHLIB_SUFFIX=&quot;.so&quot;
        DL_LIBS=&quot;-ldl&quot;
        SHLD_FLAGS=&quot;&quot;
        ;;

4) save configure file

5) go back to ns-allinone-2.34 main directory and launch install.

6) remember to add to your .bash file (hided inside your home directory) with path variables. here there are mine for example

# LD_LIBRARY_PATH
OTCL_LIB=/home/lotti/Scrivania/ns/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/lotti/Scrivania/ns/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/home/lotti/Scrivania/ns/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/lotti/Scrivania/ns/ns-allinone-2.34/bin:/home/lotti/Scrivania/ns/ns-allinone-2.34/tcl8.4.18/unix:/home/lotti/Scrivania/ns/ns-allinone-2.34/tk8.4.18/unix
NS=/home/lotti/Scrivania/ns/ns-allinone-2.34/ns-2.34/
NAM=/home/lotti/Scrivania/ns/ns-allinone-2.34/nam-1.13/
PATH=$PATH:$XGRAPH:$NS:$NAM

7) test it: close actual terminal and open a new one (to reload changed .bash file) and type “ns”. if a % appear, your actually on ns2 console.

Finish!

hackme!

download

hackme is a test-program: i figured out a way to protect variables from hacking and now i need some tester 🙂

the program is really simple: 1 dynamic text, 1 buttons.
the dynamic text contains the output of the variable.
the “update” button refresh the dynamic text with the content of the variable.

you (the hacker) have to hack my variable (with cheatengine, for example) injecting “1337” value in the variable, then press “update” button 🙂
obviously, hack the dynamic text doesn’t mean hack my variable.

send comments or opinion to lotti *A.T* fastwebnet *D.O.T* it or reply to this post

thanks.

jquery: igoogle box-set like script

hello world! (sounds familiar..)

lr1 parser is complete! woooah. it takes me 3 weeks of work and now i will have a printed permanent smile on my face for at least 1 month. well i will post source codes, but not for now :).

today i’d like to show you a nice work made with jquery, a powerful javascript library that i discovered two days ago.

This is a tutorial that will show how to make a simple but nice customizable blocks-made interface/homepage, with jquery. the script is based on this other tutorial.

Here it is the demo: http://www.valerioriva.it/jquery/lotti-block.html
how to use the demo: you will see 6 blocks. click on the wrench to enter customization mode, a dialog will appear. click on every boxes’ icon (click and drag to move blocks with 4 arrow cross) and customize your layout. save or restore states/order/everything if you don’t like the customization.

features:

  • movable blocks
  • closable blocks
  • minimizable blocks
  • save blocks’ state and order into cookies

let’s start with the html template.

build your html layout.. with divs! made 1 or 2 or 3 or how many you need div “columns”. i’ll choose 3. then, you have to put inside each columns some divs that will be acting as boxes with some simply css commands.

here it is my example [remember to include always jquery library, jquery cookie plugin, jquery ui theme script and of course, my script (lotti-block)]
there is also a css example for people that doesn’t know how to make divs act as blocks

download the demo files!

<html>
 <head><title>Demo</title>
 <link type="text/css" href="css/demo/jquery-ui-1.7.2.demo.css" rel="stylesheet" />
 <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
 <script type="text/javascript" src="js/jquery.cookie.js"></script>
 <script type="text/javascript" src="js/jquery-ui-1.7.2.demo.min.js"></script>
 <script type="text/javascript" src="js/lotti-block.js"></script>
 <style>
 #left { width: 20%; float:left; }
 #center { width: 58%; float: left; margin-right:1%; margin-left:1%; }
 #right { width: 20%; float:right; }
 .box { background-color:#eef3f8; border:1px solid #d5dde5; border-bottom:4px solid #d5dde5; padding:10px; margin-bottom:15px; overflow:hidden; }
 .box h3{ background:#d5dde5; color:#1d3652 }
 .portlet-header .ui-icon { float: right; }
 .placeholder { border: 1px dotted black; visibility: visible !important; background-color: #0066CC; color: #FFFFFF; font-weight: bold; }
 .placeholder * { visibility: hidden; }
 .ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 100px !important; }
 .ui-sortable-placeholder * { visibility: hidden; }
 </style>
 </head>
 <body>
 
<div id="customize-dialog" title="Reset Layout Page">
<p>Now you can customize your page.<br /> Move boxes from column to another, minimize/close them or get back to default settings by clicking on these buttons:</p>
</div>


<div id="left">
 <div align="center">PLACEHOLDER</div>
 <div id="b1"><h3>Block 1</h3>
 <div>Block 1</div>
 </div>
 <div id="b2"><h3>Block 2</h3>
 <div>Block 2</div>
 </div>
</div>
<div id="center" >
 <div align="center">PLACEHOLDER</div>
 <div id="b3"><h3>Block 3</h3>
 <div>Block 3</div>
 </div>
 <div id="b4"><h3>Block 4</h3>
 <div>Block 4</div>
 </div>
</div>
<div id="right" >
 <div align="center">PLACEHOLDER</div>
 <div id="b5"><h3>Block 5</h3>
 <div>Block 5</div>
 </div>
 <div id="b6"><h3>Block 6</h3>
 <div>Block 6</div>
 </div>
</div>


 </body>
</html>

ok. now let’s examine this page. every column (they have IDs: left, center and right) must have the class identifier “sortable” and each block must have a different ID (in this example from b1 to b6). then placeholder divs (class=”placeholder”) blocks are used only to facilitate boxes drag’n’drop inside each column.
Every box have some special class that are: customizer, movable, minimizable, closable. each of those words adds an ability to the block. There must be at least 1 customizer (and preferably it doesn’t have to be closeable). you can use every combinations of those class identifier.

Then, a box is defined, as you can see, by this code (for example, i took the last block)

<div id="b3"><h3>Block 3</h3>
 <div>Block 3</div>
 </div>

REMEMBER! there must be a tag with class identifier “portlet-header” (i used h3 but it could be a div too) and another tag (preferably a div) with class identifier “portlet-content”

there is a “dialog” div too (it will act as a dialog box) that will appear when the customizer icon is clicked. it contains buttons to save or restore the homepage configuration/style.

now let’s see something about the js code

//configurable variables
var cookiename='demo';
var cookie_options = { path: '/', expires: 10 };

function resetCookie() //delete cookie
{
jQuery.cookie(cookiename, null, cookie_options);
}

function resetCookieState() //delete only blocks' states from cookie
{
var cookie = jQuery.cookie(cookiename);
if (!cookie) return;

var cookie=cookie.split("|");

var savedBlocks = cookie[0];
var savedState = cookie[1];

jQuery.cookie(cookiename, savedBlocks+'|', cookie_options);
}

function resetCookieOrder() //delete only blocks' order from cookie
{
var cookie = jQuery.cookie(cookiename);
if (!cookie) return;

var cookie=cookie.split("|");

var savedBlocks = cookie[0];
var savedState = cookie[1];

jQuery.cookie(cookiename, '|'+savedState, cookie_options);
}

function getCookie() //read the cookie and restore blocks' order and states
{
var cookie = jQuery.cookie(cookiename);
if (!cookie) return;

var cookie=cookie.split("|");

var savedBlocks;
var savedStates;

if (cookie[0]) savedBlocks = cookie[0];
if (cookie[1]) savedStates = cookie[1];

//order
if (savedBlocks)
{

        var orders = savedBlocks.split(";");

//below you need to be replace with your columns id!!
        jQuery("#left").sortable('toArray');
        jQuery("#center").sortable('toArray');
        jQuery("#right").sortable('toArray');

//here too!!
        if(orders[0]) restoreOrder('#left',orders[0]);
        if(orders[1]) restoreOrder('#center',orders[1]);
        if(orders[2]) restoreOrder('#right',orders[2]);
  }

//states
if (savedStates)
{
        var states = savedStates.split(",");
        var blocks_id = new Array();
        var blocks_state = new Array();
        var i=0;
        for (i=0; i<states.length; i++)
        {
            var temp = states[i].split("=");
            blocks_id[i]=temp[0];
            blocks_state[i]=temp[1];
        }

        for (i=0; i<states.length; i++)
        {
        	 var item=blocks_id[i];
        	 var state=blocks_state[i];
           if (state==1)
             jQuery("#"+item).find(".portlet-content").hide();
           else if (state==2)
             jQuery("#"+item).hide();
        }
   }
}

function setCookie() //save the blocks' order and states inside a single cookie
{
  var s="";
  var i=0;
  var n=0;

 //order
//below you need to be replace with your columns id!!
        if (jQuery("#left").sortable('toArray')!="undefined")		s+=jQuery("#left").sortable('toArray')+";"
if (jQuery("#center").sortable('toArray')!="undefined")		s+=jQuery("#center").sortable('toArray')+";"
if (jQuery("#right").sortable('toArray')!="undefined")		s+=jQuery("#right").sortable('toArray')+";"

  s=s.substr(0,s.length-1);

  s+='|';

  //states
  			var blocks_minimized = new Array();
  			var blocks_closed = new Array();

  			n=jQuery('.portlet-content:hidden').size();
  			for (i=0; i<n; i++)
     			s+=jQuery('.portlet-content:hidden').eq(i).parent('.minimizable').attr('id')+"=1,";

  			n=jQuery('.closable:hidden').size();
  			for (i=0; i<n; i++)
    			s+=jQuery('.closable:hidden').eq(i).attr('id')+"=2,";

  if (n!=0) s=s.substr(0,s.length-1);

  if (s.length>0) jQuery.cookie(cookiename, s, cookie_options);
  else jQuery.cookie(cookiename, null);
}

function restoreOrder(list,order)  //restore blocks' order for each column
{
var list = jQuery(list);
if (list == null) return

// make array from saved order
var IDs = order.split(",");

for (var i = 0, n = IDs.length; i<n; i++)
        {
var item = IDs[i];

 	   // select the item from the proper column
var child = jQuery("div.ui-sortable").children("#" + item);

// make a copy of the item
var savedOrd = jQuery("div.ui-sortable").children("#" + item);

// remove the original item
child.remove();

           //insert the copy inside the ordered column
jQuery(list).append(savedOrd);
}
}

function removeButtons() //remove cutomization buttons
{
jQuery(".ui-icon-newwin").replaceWith('');
jQuery(".ui-icon-arrow-4").replaceWith('');
jQuery(".ui-icon-power").replaceWith('');
}

function addButtons() //adds customization buttons and actions
{
removeButtons();
jQuery(".minimizable").find(".portlet-header").append('<span class="ui-icon ui-icon-newwin"></span>')
jQuery(".movable").find(".portlet-header").append('<span class="ui-icon ui-icon-arrow-4"></span>')
jQuery(".closable").find(".portlet-header").append('<span class="ui-icon ui-icon-power"></span>')

jQuery(".minimizable").find(".portlet-header").find(".ui-icon-newwin").click(function() {
jQuery(this).parents(".minimizable").find(".portlet-content").toggle();
});

jQuery(".closable").find(".portlet-header").find(".ui-icon-power").click(function() {
                        jQuery(this).parents(".closable").hide();

});
}

function enableCustomization() //shows the dialog, the placeholders, makes columns item sortable and adds buttons
{
jQuery('#customize-dialog').dialog('open');
jQuery(".placeholder").show();
jQuery(".sortable").sortable({
    														handle: '.ui-icon-arrow-4',
    														tolerance: 'pointer',
items: '.movable',
    														connectWith: '.sortable',
    														update : function () { setCookie(); }
    										});
   											addButtons();
}

function disableCustomization() //remove buttons, set the cookie, hides the placeholders and block the columns
{
removeButtons();
   											setCookie();
jQuery(".placeholder").hide();
                				jQuery(".sortable").sortable('destroy');
}

jQuery(function() { //jQuery "Main"

jQuery('#customize-dialog').dialog({ //configure the dialog box
                         autoOpen: false, width: 400, buttons: {
                              "Everything": function() { //reset to normal page layout
                                jQuery(this).dialog("close"); //close the dialog
                                resetCookie(); //full reset
                                window.location.reload(); //refresh page to see changes
                              },
                              "States": function() { //reset only the states
                                jQuery(this).dialog("close"); //close the dialog
                                resetCookieState(); //partial reset, only states
                                window.location.reload(); //refresh page to see changes
                              },
                              "Order": function() { //reset only the order
                                jQuery(this).dialog("close"); //close the dialog
                                resetCookieOrder(); //partial reset, only order
                                window.location.reload(); //refresh page to see changes
                              },
                              "Save": function() { //save state and order
                                jQuery(this).dialog("close");  //close the dialog
                              }
                         },
   											 close: function(event, ui) { disableCustomization(); } //every time the dialog is closed.. disableCustomization is launched!
                });

    jQuery('.placeholder').hide(); //hides the placeholders

jQuery('.customizer').find('.portlet-header').append('<span class="ui-icon ui-icon-wrench"></span>') //adds the customization button on customizer boxes..

jQuery('.customizer').find('.portlet-header').find('.ui-icon-wrench').click(function() { //and add his action
enableCustomization();
});

jQuery('.sortable').sortable({ //instiate columns as sortable to fetch order from cookie
    				handle: '.ui-icon-arrow-4',
    				tolerance: 'pointer',
items: '.movable',
    				connectWith: '.sortable',
    });

 		getCookie(); //read the cookie

jQuery('.sortable').sortable( 'refresh' ) //refresh columns status
 		jQuery('.sortable').sortable('destroy'); //lock columns

});

well, i commented every function, i hope you will understand. if not, go to jQuery documentation or view the linked tutorials on top of this post.
however, inside the cookie the order is save with strings like this: b1,b2;b3,b4;b5,b6 where the ; stands for “end of column” so it is most important to put ids in the correct order inside getCookie e setCookie functions. the blocks’ state is saved like this: b1=1,b2=2,b4=1 where 1 stands for minimized and 2 for closed. no need to save “normal state” because we already have it by default (everytime you load the page, every is on default order/state). that’s all. hope you liked! feel free to ask questions!

Projects that kept (and keep) me busy in these months

Hi everybody! I don’t know why i keep update this wordpress release but not post something new.. maybe i lack of inspiration or i just think that people don’t care (and me too). So, this is the first 2009 update, let’s start.

  1. NeXtRL.it FanZine
    I was six years old when i bought and read my first magazine, console magazine, and now i’m a sort of publisher of a community-made magazine, the NeXtRL.it Fanzine (started on December 2008). Here are the published issues.
    I made a lot of experience with both amateur (publisher 2007) and professional (quarkxpress) press software and i studied some way to share works (the written articles) and simplify human interactions with a “nothing-can-go-wrong” module (see point (2)). Now i’m working on the third issue of the fanzine and i’d like to do it with adobe indesign (another pro app) because i didn’t enjoy my experience with quarkxpress – complicated also on easy tasks like pick the right tool from the panel and no color picker!
  2. NeXtRL.it – Form to submit articles for the FanZine
    It’s a simple form with some javascript  that uses a validation engine (in javascript too) found on this tutorial. People can enter various type of articles, filling in the different fields that the chosen type of article requires. Then they can modify, delete or send (to themselves or to publisher – me) their ready-to-print articles. Then the articles arrive on my google docs account so i can share them with my collaborators that check for grammar errors and i finally i can paginate the final articles.
    I made it with php, mysql and IPB API because nextrl.it uses IPB Forum. So here it is the link, but you can’t access if you’re not logged in – and it’s all written in italian, too.
    Source code not available because i made it just for nextrl.it
  3. NeXtRL.it – Tournament script
    Here, i enanched an old script that i made adhoc for nextrl.it a year ago. It was messy and hardcoded, now it’s more flexible and still a bit messy 😛 I think i need to switch my php’s habits to OOP and start comment while (and not after) coding.
    Now the script can handle more than one tournament and of various type: ladders, points, victories. I rewritten quite the 95% of the code and it took me a week. This is the link and, also there, you can’t access if you’re not logged in and it’s in italian too.
    Source code not available because i made it just for nextrl.it
  4. Automata & Languages: Cocke-Younger-Kasami Parser
    I made this parser in a month for university purpose. I will post and explain the code when i will pass the related exam, so here there are some info form wikipedia. Basically, i did a program that manipulate a context-free grammar to eliminate epsilon production, unit production, put it in chomsky normal form and last parse a word with CYK algorithm and say if it belong, or not, to the given grammar.
    Made with Java (instead of C++) for it’s wide library of string manipulation functions.
  5. ns2/nsmiracle
    I started to study about my thesis: understand how ns2 and nsmiracle modules are written to implement specific ones. Next monday (the 18th of May 2009) i will know more about those modules.
  6. WWTBAFM: new release?
    I though two times about release a new version of wwtbafm: two separated homebrew, one to play and the other to update questions. when i’ll have time and i will get my nds back i would give it a try, now that palibs are fixed to work with latest ndslib

That’s all, let’s hope more updates soon 🙂

UPDATE: oh, well, i forgot to mention that i have also build a simple rs232-ttl interface to mod my x360. I will post schema and how-to on next post 🙂