Friday, 30 January 2009

HOWTO: disable horizontal scroll bar using CSS

<style>



overflow-x:hidden;



</style>



if you put this in <head> it will disable horizontal scrollbars

Thursday, 29 January 2009

#_, in mysql query, in Joomla

the database prefix can be entered in the form '#_' (hash-underscore),
in which case it will automatically be replaced by the database prefix
used by Joomla.

from: http://docs.joomla.org/Sql_parameter_type

Wednesday, 28 January 2009

(), round brackets, in Mysql

(T1, ...) RIGHT JOIN (T2,...) ON P(T1,...,T2,...) =
(T2, ...) LEFT JOIN (T1,...) ON P(T1,...,T2,...)

http://dev.mysql.com/doc/refman/5.0/en/outer-join-simplification.html


===========


mysql> SELECT cds.artist, cds.title, genres.genre
-> FROM cds, genres
-> WHERE (cds.genreID = genres.genreID);

{}, curly braces, in Php, not mysql

Variable parsing




When a string is specified in double quotes or with heredoc,
variables are parsed within it.




There are two types of syntax: a
simple one and a
complex one.
The simple syntax is the most common and convenient. It provides a way to
embed a variable, an array value, or an object
property in a string with a minimum of effort.




The complex syntax was introduced in PHP 4, and can be recognised by the
curly braces surrounding the expression.




Simple syntax



If a dollar sign ($) is encountered, the parser will
greedily take as many tokens as possible to form a valid variable name.
Enclose the variable name in curly braces to explicitly specify the end of
the name.






<?php
$beer 
'Heineken';
echo 
"$beer's taste is great"// works; "'" is an invalid character for variable names
echo "He drank some $beers";   // won't work; 's' is a valid character for variable names but the variable is "$beer"
echo "He drank some ${beer}s"// works
echo "He drank some {$beer}s"// works
?>







Similarly, an array index or an object property
can be parsed. With array indices, the closing square bracket
(]) marks the end of the index. The same rules apply to
object properties as to simple variables.






<?php
// These examples are specific to using arrays inside of strings.
// When outside of a string, always quote array string keys and do not use
// {braces}.

// Show all errors
error_reporting(E_ALL);

$fruits = array('strawberry' => 'red''banana' => 'yellow');

// Works, but note that this works differently outside a string
echo "A banana is $fruits[banana].";

// Works
echo "A banana is {$fruits['banana']}.";

// Works, but PHP looks for a constant named banana first, as described below.
echo "A banana is {$fruits[banana]}.";

// Won't work, use braces.  This results in a parse error.
echo "A banana is $fruits['banana'].";

// Works
echo "A banana is " $fruits['banana'] . ".";

// Works
echo "This square is $square->width meters broad.";

// Won't work. For a solution, see the complex syntax.
echo "This square is $square->width00 centimeters broad.";
?>








For anything more complex, you should use the complex syntax.


->, Objects and references, in Php

A PHP reference is an alias, which allows two different variables to write
to the same value. As of PHP5, an object variable doesn't contain the object
itself as value anymore. It only contains a object identifier which allows
object accessors to find the actual object. When an object is sent by
argument, returned or assigned to another variable, the different variables
are not aliases: they hold a copy of the identifier, which points to the same
object.


Example #1 References and Objects




<?php
class {
    public 
$foo 1;
}  

$a = new A;
$b $a;     // $a and $b are copies of the same identifier
             // ($a) = ($b) = <id>
$b->foo 2;
echo 
$a->foo."\n";


$c = new A;
$d = &$c;    // $c and $d are references
             // ($c,$d) = <id>

$d->foo 2;
echo 
$c->foo."\n";


$e = new A;

function 
foo($obj) {
    
// ($obj) = ($e) = <id>
    
$obj->foo 2;
}

foo($e);
echo 
$e->foo."\n";

?>




The above example will output:



2<br />2<br />2<br />



=>, in Php

paring arry keys and values.


Example #1 Ejemplo de array()




<?php
$frutas 
= array (
    
"frutas"  => array("a"=>"naranja""b"=>"plátano""c"=>"manzana"),
    
"números" => array(123456),
    
"hoyos"   => array("primero"=> "segundo""tercero")
);
?>








Example #2 Índice automático con array()




<?php
$array 
= array(1111,  1=> 1,  => 119=> 13);
print_r($array);
?>




El resultado del ejemplo seria:



Array<br />(<br />    [0] => 1<br />    [1] => 1<br />    [2] => 1<br />    [3] => 13<br />    [4] => 1<br />    [8] => 1<br />    [9] => 19<br />)<br />



::, Scope Resolution Operator, in Php


The Scope Resolution Operator (also called Paamayim Nekudotayim) or in
simpler terms, the double colon, is a token that allows access to
static,
constant, and overridden
members or methods of a class.




When referencing these items from outside the class definition, use
the name of the class.


Example #1 :: from outside the class definition




<?php
class MyClass {
    const 
CONST_VALUE 'A constant value';
}

$classname 'MyClass';
echo 
$classname::CONST_VALUE// As of PHP 5.3.0

echo MyClass::CONST_VALUE;
?>






And, Static properties cannot be accessed through the object using the arrow
operator ->.

http://uk2.php.net/language.oop5.static


%, as Wildcard Usage, in Mysql



For example '2%' would match the following: 20, 25, 2000000, 2avkldj3jklsaf, and 2!

$result = mysql_query("SELECT * FROM example WHERE age LIKE '2%' ")
or die(mysql_error());

&, ampersand, in php

in the following piece of code:

$a=10 ; //(1010b)
$b = 0; // (0000b)

if ($a & $b)

is different from

if ($a && $b)

The first one is true and the second if false.

When
we use only one & it means bit-by-bit and operation, so $a &
$b=10 (1010b), while when you use && it means and operator of
clauses and in this case $a && $b = 0, cause $b=0.

Beware of the signs. This FAQ is also valid for the or operator ('|').

how Virtuemart present the shop page

1) virtuemart.php:
if( file_exists( PAGEPATH.$modulename.".".$pagename.".php" )) {
...
include( PAGEPATH.$modulename.".".$pagename.".php" );
// this file is: administrator/components/com_virtuemart/html/shop.index.php

2) shop.index.php:
$tpl = new $GLOBALS['VM_THEMECLASS']();
...
$tpl->set( 'categories', $category_childs );
...
$tpl->set('ps_product',$ps_product);
...
echo $tpl->fetch( 'common/shopIndex.tpl.php');
// to theme the output, the template file, components/com_virtuemart/themes/default/templates/common/shopIndex.tpl.php, is needed.

3) shopIndex.tpl.php:

you can remove the shop description/the word of 'categories',
or remove the featured prodcuts in codes, but this also can be done in admin-components-virtuemart-admin-configuration-site-layout-Select the theme for your Shop-default-configuration)

if( $this->get_cfg( 'showFeatured', 1 )) {
/* featuredproducts(random, no_of_products,category_based) no_of_products 0 = all else numeric amount
edit featuredproduct.tpl.php to edit layout */
echo $ps_product->featuredProducts(true,10,false);
}
// ./featuredproduct.tpl.php will determine the layout for featured products.

Monday, 26 January 2009

Jython and Matlab do jobs for java

Java codes:
======================
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyExample
implements ActionListener {

public void actionPerformed(ActionEvent e) {
System.out.println("Ouch!");
}

public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setSize(300,300);
JButton button = new JButton("Push Me!");
ActionListener listener = new MyExample();
button.addActionListener(listener);
frame.getContentPane().add(button);
frame.setVisible(true);
}
}


Jython:
======================
import javax.swing as swing

def printMessage(event):
print "Ouch!"

frame=swing.JFrame("my frame")
frame.setSize(300,300)
button=swing.JButton("Push Me!")
button.actionPerformed=printMessage
frame.getContentPane().add(button)
frame.setVisible(True) #frame.visible=1


Matlab:
=======================
import javax.*;

frame = swing.JFrame('my frame');
frame.setSize(300,300);
button = swing.JButton('Push Me!');

set(button,'ActionPerformedCallback',@printMessage);

frame.getContentPane.add(button);
frame.setVisible(true);

%code for sub function:
function printMessage(handle,event)
disp('ouch');
end

Tuesday, 20 January 2009

mysql user management

准备:更改root的密码 (mysql安装后,root是没有密码的)
@>mysqladmin -uroot password YOURNEWPASSWORD

1.新建用户。

//登录MYSQL
@>mysql -u root -p
@>密码
//创建用户
mysql> insert into mysql.user(Host,User,Password) values("localhost","cross",password("1234"));
//刷新系统权限表
mysql>flush privileges;
这样就创建了一个名为:cross 密码为:1234 的用户。

然后登录一下。

mysql>exit;
@>mysql -u cross -p
@>输入密码
mysql>登录成功

2.为用户授权。

//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录.
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(joomla1)
mysql>create database joomla1;
//授权phplamp用户拥有phplamp数据库的所有权限。
>grant all privileges on joomla1.* to 'cross'@localhost identified by '1234';
//刷新系统权限表
mysql>flush privileges;
mysql>其它操作

/*
如果想指定部分权限给一用户,可以这样来写:
mysql>grant select,update on phplampDB.* to 'phplamp'@localhost identified by '1234';
//刷新系统权限表。
mysql>flush privileges;
*/

3.删除用户。
@>mysql -u root -p
@>密码
mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost";
mysql>flush privileges;
//删除用户的数据库
mysql>drop database phplampDB;

4.修改指定用户密码
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";
mysql>flush privileges;

Tuesday, 13 January 2009

javascript: enter to execute


<html>

<head>

<script type="text/javascript">

    function getrefno(reno, helperMsg){

        if(reno.value.length == 0){

            alert(helperMsg);

            elem.focus();

            return false;

        }else{

            window.location = "http://www.gigibride.co.uk/gallery/category/image-galleries/"+reno.value;

            return true;

        }

    }





function entertoget(e){

var code;

if (!e) var e = window.event;

if (e.keyCode) code = e.keyCode;

else if (e.which) code = e.which;



var character = String.fromCharCode(code);



if(code==13){

var refn=document.getElementById('ref');

var address = refn.value;

alert(address);

}



}



</script>

</head>

<body>





<form>



Reference: <input type='text' id='ref' onkeypress="javascript:entertoget(event);" value='gigigallery' />



<input type='button' onclick="javascript:getrefno(document.getElementById('ref'), 'Please Enter Your Ref No.');" value='Get My Photos' />



</form>

</body>

</html>

Saturday, 10 January 2009

HOWTO: make “the java plugin” work on Firefox in Fedora 10 / Linux Distro?

1) locate the file named libjavaplugin_oji.so on your box by issuing the following command at the prompt:


[dkd903@dkd903-laptop ~]$ locate libjavaplugin_oji.so


you`ll find that the file libjavaplugin_oji.so is available in the /usr/java/jre1.6.0_07/plugin/i386/ directory.


2) Then what you need to do is just link the .so file symbolically to the mozilla plugins folder, and you are done:


[dkd903@dkd903-laptop ~]$ sudo   ln  -s  
/usr/java/jre1.6.0_07/plugin/i386/ns7/libjavaplugin_oji.so  
/usr/lib/mozilla/plugins/libjavaplugin_oji.so

Sunday, 4 January 2009

炝拌土豆丝

用料:土豆一个,葱花若干,辣椒面,麻椒(赶成面,市场上卖的麻椒都不是太麻,我直接用了几次都没什么味,还是赶成面味道大香),糖,香菜,鸡精,盐


做法:1   大土豆一个(2人份)土豆这东西很出数的,所以不用切很多


           2   土豆切丝,大家如果刀法和我一样不是很到位的话,就慢点切吧,即使切大点也没关系,反正自己家人吃嘛,呵呵


            3   将刚切好的土豆丝放在凉水中,这样土豆丝就不会变黑了


            4   将土豆丝放如开水中抄一下,不要用很长时间,这要根据你切土豆丝的粗细决定


            5   将抄好的土豆丝放入凉水中过3变,去掉淀粉,让土豆丝更脆,把土豆丝放入盘中


            6   将2勺油放入马勺中烧开,在土豆丝上放上葱花。糖少许,蒜要多些,鸡精,盐,芝麻,赶过的麻椒面,辣椒面,将烧开的油倒上去,拌好放香菜即可。


注意:这道菜的关键是要让土豆丝够脆,所以第5步很关键,再有,拌好的土豆丝也容易变色,所以得尽快吃掉!

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter