Saturday, December 08, 2012

[JavaScript]


str = 'things';
str = str.slice(0,1).toUpperCase()+str.slice(1);


if (confirm("") ) { alert("Good choice"); } else { alert(" 那你就留在原地"); }
Create an Array
An array can be created in three ways.

The following code creates an Array object called myCars:

1: Regular:

var myCars=new Array(); 
myCars[0]="Saab";       
myCars[1]="Volvo";
myCars[2]="BMW";
2: Condensed:

var myCars=new Array("Saab","Volvo","BMW");
3: Literal:

var myCars=["Saab","Volvo","BMW"];
[JQUERY] SELECTOR
Attribute Equals Selector [name="value"]

Monday, December 03, 2012

Error Code: 1175 You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

FROM HERE
http://justalittlebrain.wordpress.com/2010/09/15/you-are-using-safe-update-mode-and-you-tried-to-update-a-table-without-a-where-that-uses-a-key-column/


YOU ARE USING SAFE UPDATE MODE AND YOU TRIED TO UPDATE A TABLE WITHOUT A WHERE THAT USES A KEY COLUMN

Error Code: 1175
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
Every found that kind of error when trying to update rows in mysql? It’s because you tried to update a table without a WHERE that uses a KEY column (err …).
Anyway, The quick fix is to add SET SQL_SAFE_UPDATES=0; before your update query. Here’s the example:
SET SQL_SAFE_UPDATES=0;
DELETE FROM people WHERE person_status = 'deceased';

Tuesday, November 20, 2012

本文來源
http://caterpillar.onlyfun.net/Gossip/Python/WithAs.html
作者

From Gossip@caterpillar

Python Gossip: 使用 with as




在 try、raise 陳述句 中有個讀取檔案的範例:
 file = open('demo.py', 'r', encoding='UTF-8')
try:
    for line in file:
        print(line, end='')
except:
    print('讀取檔案發生錯誤')
finally:
    file.close()

為了要處理檔案讀取過程中發生的例外,並且最後確定檔案一定會關閉,你使用了try..except...finally語句,實際上,在Python 3(或2.6)中,你可以使用with as語句來簡化程式的撰寫:
 with open('demo.py', 'r', encoding='UTF-8') as file:
    for line in file:
        print(line, end='')

with之後的運算式傳回的物件,可以使用as指定給變數來參考,在上面的例子中,file所參考到的物件,最後會被自動關閉,即使在with as的區塊中發生了例外,最後一定會關閉file所參考的物件。

實際上,只要物件支援環境管理協定(Context Management Protocol),就可以使用with as語句。支援環境管理協定的物件,必須實作__enter__()與__exit__()兩個方法,這樣的物件稱之為環境管理員(Context Manager)。

with陳述句一開始執行,就會進行__enter__()方法,該方法傳回的物件,可以使用as指定給變數(如果有的話),接著就執行with區塊中的程式碼。

如果with區塊中的程式碼發生了例外,則會執行__exit__()方法,並傳入三個引數,這三個引數,與 再看 try、raise 中所提到的 sys.exc_info() 傳回的三個值是相同的,也就是例外的類型、例 外訊息以及traceback物件。此時__exit__()方法若傳回False,則例外會被重新丟出,否則例外就停止傳播,通常__exit__()會傳回False以在with之外還可以處理例外。

如果with區塊中沒有發生例外而執行完畢,則也是執行__exit__()方法,此時__exit__()的三個參數都接收到None。

所以,假設你要自行實作一個可以自動關閉檔案的物件,則可以如下:
 class FileReader:
    def __init__(self, filename):
        self.filename = filename
   
    def __enter__(self):
        self.file = open(self.filename, 'r', encoding='UTF-8')
        return self.file
   
    def __exit__(self, type, msg, traceback):
        if type:
            print(msg)       # 作你的例外處理
        self.file.close()
        return False

接下來你就可以在FileReader物件上使用with as語句。例如:
with FileReader('demo.py') as file:
    for line in file:
        print(line, end='')

Friday, November 09, 2012

DHTMLX

PHP
explode
javascript callback function && object oreinted


DHTML
http://docs.dhtmlx.com/doku.php?id=dhtmlxwindows:initializing_dhtmlxwindows
WINDOWS CONTROL

http://www.filecrop.com/data-structures-and-algorithms-in-c-pdf.html

when use json between server PHP AND client javascript

In javascript

var report = JSON.parse(response)

In PHP

header('Content-type: text/json');

Monday, November 05, 2012

MYSQL ERROR:1442

MYSQL
ERROR:
Can't update table 'xxx' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Trigger:

CREATE
DEFINER=`jhhh`@`%`
TRIGGER `dxxx`.`pxxx_insert2_dxxx`
BEFORE INSERT ON `dxxx`.`pxxx`
FOR EACH ROW
begin


REPLACE INTO pxxx_sxxx (pxxx_cxxx)
VALUES(NEW.pxxx_cxxx);
SELECT pxxx_id INTO @temp_pxxx_id
        FROM pxxx_sku WHERE pxxx_code = NEW.pxxx_code;

SET NEW.pxxx_id = @temp_pxxx_id;

end$$


Friday, November 02, 2012

funny

MYSQL REG EX

hello world
Regular Expression //it's fail because security reason. DELETE FROM xxxt_dxxxx.dxxxx WHERE nameid REGEXP '[a-Z]'; //it's passed SELECT * FROM xxxt_dxxxx.dxxxx WHERE nameid REGEXP '[a-Z]';

Thursday, November 01, 2012

MYSQL trigger


CREATE
    [DEFINER = { user | CURRENT_USER }]
    TRIGGER trigger_name trigger_time trigger_event
    ON tbl_name FOR EACH ROW trigger_body

trigger_name = customize name
trigger_time = after || before
trigger_event = insert || delete || update || loaddata || replace
trigger_body = BEGIN ..... END

[BEGIN ..... END] 
procedural SQL

Exaple:
--------------------------------------------------------------------------------
-- Trigger DDL Statements
DELIMITER $$

USE `development_deploy`$$
CREATE
DEFINER=`et`@`%`
TRIGGER `xxxment_deploy`.`item_delete2_deploy`
AFTER DELETE ON `xxxment_deploy`.`ixxx`
FOR EACH ROW
begin
 replace into deploy
 values('Wxx','Sxx',OLD.sxx,NOW(),'','','','','','') ;
end$$
-------------------------------------------------------------------------------

Tuesday, October 30, 2012

regexp regular expression
php 5:
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

JS:

/\d{4}-\d{2}-\d{2}/.test('2007-01-25');     // true
'2007-01-25'.match(/\d{4}-\d{2}-\d{2}/);    // true

DHTMLX 在使用treegrid的方式宣告出grid表格會造成一些原有的onclick事件失效,例如checkbox在裡面他是用自己的方式寫,事用onclick事件去驅動BOX改變,在onclick事件失效後,checkbox變成只能固定不能更改。
CSS special use

shadow

      -webkit-box-shadow: 2px 2px 3px #222222;
      -moz-box-shadow: 2px 2px 3px #222222;
      box-shadow: 2px 2px 3px #222222;

radius
/* support Safari, Chrome */
-webkit-border-radius: 5px;
/* support firefox */
-moz-border-radius: 5px;
border-radius: 5px;

http://www.cbflabs.com/book/cce/cce.htm

Monday, October 22, 2012


Q1.
1.1me = $('#win_content_copy').find('#categoryname');
alert(me.value).text();

[ans:]its worng. text() alert-method response undefined.

1.2alert(me.text());
[ans:]its working

1.3alert(me.val());
[ans:]when we use input marksigned ,have to

Q2.time control

//sleep(4000);
//setInterval("categoryname_keydown();", 3000);
//event.timeStamp;
//setTimeout("alert ('called from setTimeout()');",4000);
Q3.when you clone a DOM element

window_content_copy = $('#window_content').clone();
window_content_copy.attr('id','win_content_copy');
window_content_copy.appendTo('#body');

is html inside script syntax
onclick='function(this)'  (<---wrong)
onclick='function($(this))'   (<---right)



Thursday, October 18, 2012


PDO使用時要注意
使用prepare
在execute若有LIKE條件時
%必須放到excute參數內
放在原始$sql會出錯

 $sql = "SELECT id,full_xxxx_name
                       FROM xxxx
                       WHERE full_xxxx_name LIKE :xxxx_name;";

        $statement = $connection->prepare($sql);

        $statement->execute(array(':xxxx_name' => $inputname."%"));

取消表單輸入時的自動完成


<form>
    <input type="password" name="Password" autocomplete="off">
</form>


or

<form autocomplete="off">
    <input type="password" name="Password" >
</form>


//JavaScript
//HTML
//function onchange() test

<input type="text" onkeydown="myFunction()">


Tuesday, October 16, 2012


black ground:

  <div id="mask" style="filter: Alpha(opacity=30); -moz-opacity: 0.3; -khtml-opacity: 0.3;
  opacity: 0.3; background-color: #000; width: 100%; height: 100%; z-index: 5px;
  position: absolute; left: 0; top: 0; display: none; overflow: hidden;">
  </div>

jqurey
 $('#blackmask').show("slow") ;


Wednesday, July 18, 2012

GRAFIC libraries

2012/07/19
做一個匯入3D模型之簡易動畫。

GRAFIC is a set of libraries of C and C++ callable routines for programming interactive
graphics applications on workstations and personal computers. Versions of the GRAFIC library are
available for workstations running X Windows™, Apple Macintosh™ PowerPC personal
computers, and Intel compatible personal computers running Microsoft Windows 95, 98 and NT.
Except for minor differences, the same source code will function as expected for these platforms
simply by re-compiling and linking with the appropriate GRAFIC library. The GRAFIC package
was developed to provide basic, cross-platform, multi-language support for programming windowbased
raster graphics applications without the complexities and language dependencies typical of
window graphics systems. The libraries can be accessed at URL www.cadlab.ecn.purdue.edu.
The next sections introduce the basic concepts for GRAFIC programming, followed by
descriptions of the routines. Information specific to programming using the Windows and
Macintosh versions of GRAFIC is provided in the closing sections.

1.
http://hungming.ct.ntust.edu.tw/
GRAFIC 是用來控制視窗,
利用GLUT需要設定步驟,
GLUT現在已經改為freeglut因此以前教學中glut32.lib全部要改為freeglut.lib,一些相關的連結檔案也要注意。

2.
已經可以跑出畫面,現在開始找功能強大以及可以匯入3DS模組的函式庫,
http://code.google.com/p/lib3ds/
可惜lib3DS說明文件太少,本身也未附帶函式之說明文件。

3.
嘗試使用開放源碼之3D引擎ORGE作為匯入3DS及建置場景之工具。
參考此篇網路文章所得ORGE之訊息
http://www.programmer-club.com/showSameTitleN/game/3494.html
以下ORGE首頁
http://www.ogre3d.org/
一篇中文教學網誌
http://chia0418.wordpress.com/2009/03/11/%E8%88%87ogre%E5%85%B1%E8%88%9E%EF%BC%9A%E7%AC%AC%E4%B8%80%E6%AD%A5%EF%BC%8C%E5%AE%89%E8%A3%9D-ogre-161-%E4%BD%BF%E7%94%A8-vc-20052008/

4.
授權分為BSD、MIT、GNU、GPL等等,ORGE是較為寬鬆的MIT license可以用

5.
匯入3DS失敗了,改成匯入OBJ檔案,先將3DS轉檔成OBJ
WINGS3D
匯入方法有以下教學
http://www.programmer-club.com/showsametitlen/opengl/1144.html
http://www.gamelife.idv.tw/viewtopic.php?t=211
http://lawlietmoon.pixnet.net/blog/post/27177462-%E8%AE%80obj%E6%AA%94(opengl,visual-c%2B%2B6.0)
貼出匯入範例程式檔如下

/////////////////////////
// glutTest08.cpp
//
// Created by Gary Ho, ma_hty@hotmail.com, 2005
//


#include <stdio.h>
#include <math.h>

#include "glut.h"

#include "glm.h"

#define G_PI 3.14159265358979323846f

void prepare_lighting();
void display();
void keyboard(unsigned char key, int x, int y);

float theta, phi;

GLuint list_id;

void main()
{
  theta = G_PI/2;
  phi = -G_PI/2;

  glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
  glutInitWindowSize( 640, 640 );
  glutCreateWindow( "glutTest08" );

  glutDisplayFunc(display);
  glutKeyboardFunc( keyboard );

  {
    GLMmodel *glm_model;
     glm_model= glmReadOBJ( "castle.obj" );
     glmUnitize( glm_model );
     glmScale( glm_model, .1 );
     glmFacetNormals( glm_model );
     glmVertexNormals( glm_model, 90 );

     list_id = glmList( glm_model, GLM_MATERIAL | GLM_SMOOTH );

     glmDelete( glm_model );
  }

  prepare_lighting();

  glutMainLoop();
}

void keyboard(unsigned char key, int x, int y)
{
  switch( key )
  {
    case 'w':
     theta -= .05;
     prepare_lighting();
     glutPostRedisplay();
    break;

    case 's':
     theta += .05;
     prepare_lighting();
     glutPostRedisplay();
    break;

    case 'a':
     phi -= .05;
     prepare_lighting();
     glutPostRedisplay();
    break;

    case 'd':
     phi += .05;
     prepare_lighting();
     glutPostRedisplay();
    break;
  };
}


void display()
{
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluPerspective( 20, 1, 0.1, 10 );

    glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     gluLookAt(
     0,0,1,
     0,0,0,
     0,1,0 );

    glEnable( GL_LIGHTING );
    glEnable( GL_DEPTH_TEST );
 
    glCallList( list_id );

  glutSwapBuffers();
}

void prepare_lighting()
{
  theta = fmodf( theta, 2*G_PI );
  phi = fmodf( phi, 2*G_PI );

  float light_diffuse[4] = {1.0, 1.0, 1.0, 1.0};
  float mat_diffuse[4] = {1.0, 1.0, 1.0, 1.0};
  float light_position[4] = { sinf(theta) * cosf(phi), cosf(theta), -sinf(theta) * sinf(phi), 0 };

  //glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  glEnable( GL_LIGHT0 );
}

6.弳度或弧度




單位弧度定義為圓弧長度等於半徑時的圓心角

7.發現一個很容易查GLUT函式的網站
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318369(v=vs.85).aspx

8.