Thursday, November 13, 2008

13 useful graphing solutions for web developers

Many a web application can be enhanced with a decent graph to show data. Unfortunately out of the programming languages / frameworks that we have available to us, none seem to be very forthcoming with decent graph components, and it is left up to third party solutions to provide the necessary. From my hunts around the web the following showcases some of the better options. I’ve tried to keep these limited to the open source / free options.

LibChart

http://naku.dohcrew.com/libchart/pages/introduction/

Libchart is a simple PHP charting component, and it is totally free free free! The project is an ongoing one - with the last release in April 2008. If you are a PHP coder, you’ll love its simplicity.

Currently supports:

  • Bar charts (horizontal or vertical).
  • Line charts.
  • Pie charts.
  • Single or multiple data sets.
  • Compatibility with PHP 5.

PlotKit

http://media.liquidx.net/js/plotkit-doc/PlotKit.QuickStart.html

Primarily for Barcharts and Piecharts, plotkit uses some fancy Javascript, SVG and Canvas to do some wonderous things. Both these formats are gaining traction in the javascript community, and with implementations in major browser engines, we are deffo going to see more useful javascript drawing libraries cropping up over time.

FusionCharts Free

http://www.fusioncharts.com/free/

Fusioncharts offer some of the best animated flash charting components on the web, and luckily for us they also offer free components. Not only are they used commercial with clients such as Oracle, Microsoft and Dell amongst others, so you’d be in good company. FusionCharts Free can be distributed for free with your free or commercial softwares, irrespective of whether they’re open source or closed source. Hurray!

Chartpart

http://chartpart.com/

Google’s chart drawing API is pretty useful. More so when a little website generates and previews a chart automatically for you. Mighty useful.

Simile Widgets

http://code.google.com/p/simile-widgets/

The Simile project at MIT stands for Semantic Interoperability of Metadata and Information in unLike Environments, with alot of their work focused on visualising digital assets. Luckily for us, they have open sourced some useful widgets on Google code. The timeline is of particular interest, as it allows you to plot events as well as data, which can give some pretty cool results.

Simple Accessible Charts

http://grassegger.at/xperimente/charts-daten-semantik-css/

Inspired by some of the work done by ThinkVitamin - Out of all of the graphing solutions presented here, this is by far the simplest. HTML and CSS charts. Great if you are short on time, and need an easy bar chart.

AmCharts

http://www.amcharts.com/

Created by the talented Antanas Marcelionis Amcharts offer both a commercial charting solution and also offer a free linked version of their flash charting components. The project backups great components with even better documentation, with data (as you would expect) being pulled in via an XML file. They aso offer easy to use server side ASP.NET controls - which make the implementation even simpler for those of us who use the framework.

Features:

  • Stock
  • Column and Bar chart
  • Line and Area chart
  • Pie & Donut
  • Scatter and Bubble chart
  • Radar and Polar

JFreeChart

http://www.jfree.org/jfreechart/

If you develop on the java platform JFreechart is a 100% Java library that is used extensively in existing projects. Established eight years ago, the project has gone from strength to strength, and is now used by 40,000+ Java developers.

The library includes support for multiple chart types including gauges - common in many dashboard applications.

Charting Component Dojo Framework

http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/

We covered Dojo as one of the Javascript frameworks worth taking a serious look at. Dojo has a similar implementation of graphing via Canvas that we seen used in Plotkit. It is more extensive in its offering however, with cleaner lines generated overall.

Open Flash Chart

http://teethgrinder.co.uk/open-flash-chart-2/

Open Flash chart instead of XML as its datasource uses JSON, which in my opinion, opens it up for further expansion via javascript interaction. Now running on Flash Actionscript 3.0 model - open flash chart is one of the most impressive open source charting ciomponents on the Web today.

Zedgraph

http://zedgraph.org

Written in C# on the .NET framework, ZedGraph is a class library, user control, and web control for .net, for drawing 2D Line, Bar, and Pie Charts. You can easily implement the library in VB however with a binary download offered from SourceForge. Codeproject also offer a good example C# program for utilising the control.

Open source gauge component

http://www.digitaldarknet.net/flash/index.php?selector=dgauge

Gauge components are a new addition to many useful dashboards. These are open source flash swf files, and data passed in via javascript. Source files are not included, but these may be useful for small scale data display. There’s also a JS canvas sample available via the above link.

XML/SWF gauge

http://www.maani.us/gauge/

XML/SWF gauge is a simple, yet powerful tool to create attractive web gauges and dials from dynamic data.

Create an XML source to describe a gauge, then pass it to this tool’s flash file to generate the gauge. Type the XML source manually, or use any scripting language (PHP, Perl, ASP, CFML, etc.) to generate it automatically.

Wednesday, November 12, 2008

Khi nào và tại sao phải dùng Index trong Mysql

Một ngày kia bạn nhận ra rằng website của bạn chạy chậm đi, có thể là do đường truyền nhưng còn 1 nguyên nhân khác, đó là máy chủ server tính toán quá nhiều dẫn đến kết quả đưa ra chậm.

Khi số lượng record tăng lên thì thời gian tìm kiếm của bạn sẽ tăng đáng kể.
“Too many connections” không phải là hiếm gặp trong các website trên Internet.

Hãy xem xét ví dụ sau:

CREATE TABLE employee (
employee_number char(10) NOT NULL,
firstname varchar(40),
surname varchar(40),
address text,
tel_no varchar(25),
salary int(11),
overtime_rate int(10) NOT NULL
);

Và để tìm thông tin Lương của Nguyễn Nam (mã số 101802) , bạn sẽ query như sau:
SELECT salary FROM employee WHERE employee_number = ‘101832′;

MySQL biết rằng phải tìm ở table Employee nhưng nó sẽ không biết bắt đầu từ đâu. Thậm chí nó cũng không biết trước rằng có bao nhiêu kết quả . Do đó nó sẽ duyệt qua tất cả danh sách (vd Hơn 300000 người) để tìm thông tin về Nguyễn Nam.

Một trong những cách để giải quyết vấn đề là dùng Index cho table

Làm sao để quyết định Index cho những field nào hay làm index cho tất cả các field

===> Trả lời

- Index những field mà bạn thường xuyên dùng để làm tiêu chí search( ý nói ở đây là trong phần điều kiện where)
- Nên hạn chế index những field không cần thiết và thường xuyên bị update... vì DBMS cần thời gian để cập nhật cho file index.

Cách theo dõi "công việc tăng tốc" mà ta đang làm

Cú pháp: EXPLAIN Query;

Bằng lệnh này bạn sẽ nhận ra được với câu Query của bạn , điều gì đang xảy ra và kiểu kết hợp (Join) nào đang diễn ra bên trong.

mysql>> EXPLAIN SELECT employee_number,firstname,surname FROM employee WHERE employee_number= ‘10875′;
+———-+——-+—————+———+———+——-+——+——-+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+———-+——-+—————+———+———+——-+——+——-+
| employee | const | PRIMARY | PRIMARY | 10 | const | 1 | |
+———-+——-+—————+———+———+——-+——+——-+
Tốt hơn nhiều rồi , kiểu TYPE = Const có nghĩa rằng MYSQL hiểu ra chỉ có 1 hàng đúng với ý ta, và thể hiện qua cột Rows = 1 , kiểu key= PRIMARY được sử dụng và chiều dài key_len là 10.Chỉ tìm 1 hàng tất nhiên rằng tốt hơn nhiều so với tìm N hàng.

Vậy câu hỏi đặt ra là , nếu tôi muốn thêm Index cho những cột mà có thể có nhiều hơn 1 kết quả khi query thì sao? Vẫn add index như bình thường

Nhưng nên lưu ý vấn đề sau:
mysql>> ALTER TABLE employee ADD INDEX(surname,firstname);
mysql>> EXPLAIN SELECT overtime_rate FROM employee WHERE surname=’Nguyễn’ and firstname=”Nam”;
+——–+——+——————-+———+———+——-+——+———–+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+——–+——+——————-+———+———+——-+——+———–+
|employee| ref | surname,surname_2 | surname | 41 | const | 1 |where used |
+——–+——+——————-+———+———+——-+——+———–+

Tuy nhiên , nếu chỉ cần Firstname

mysql>> EXPLAIN SELECT overtime_rate FROM employee WHERE firstname=’Name’;
+———-+——+—————+——+———+——+——+————+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+———-+——+—————+——+———+——+——+————+
| employee | ALL | NULL | NULL | NULL | NULL | 9475| where used |
+———-+——+—————+——+———+——+——+————+
thì MySQL sẽ tìm hết vì không hề có Index cho Firstname mà chỉ có Index cho (Surname,Firstname)

Nếu chỉ muốn Index cho 1 phần??
Bạn không cần phải làm Index cho cả Field mà chỉ cần 1 phần. Giống như chi tiết Mục Lục của sách mà quá dài cũng làm bạn khá vất vả, do đó họ chỉ trích dẫn 1 tựa đề. Quay lại với table của chúng ta , Surname và Firstname chỉ maximum là 40 chars , nếu chúng ta index nó , chúng ta tạo ra mỗi record đến 80 chars . Có thể tiết kiệm bằng cách sau

mysql>> ALTER TABLE employee ADD INDEX(surname(20),firstname(20));


ĐIỀU KÌ DIỆU VỚI OPTIMIZE VÀ ANALYZE

“Ma thuật” của MySQL là biết cách chọn khoá (key) nào để query(nếu có). Quá trình này gọi là “query optimizer”, nó sẽ “liếc” qua những Index đang có để quyết định sẽ dùng Index nào để tìm. Hãy tưởng tượng bạn đang tìm 1 dĩa CD của “Maria Carrey” có tên là “I Love You” , có nghĩa là có 2 Indexes ở đây , 1 cho tên tác giả và 1 cho tên CD. Bạn nhận thấy rằng danh mục có 20000 tên tác giả và 400000 tên Album. Một cách đơn giản ,bạn sẽ tìm theo tên tác giả. Khi có được , bạn lại thấy rằng “Maria Carrey” có 50 CDs và CD “I Love You” bắt đầu bằng chữ I. Đơn giản và dễ dàng tìm ra cái mình muốn phải không ? MySQL cũng vậy nhưng …bạn phải chỉ cho nó bằng cách:

ANALYZE TABLE tablename;

Những lệnh DELETE và UPDATE để lại rất nhiều những khoảng trống (gaps) vô nghĩa cho table(Đặc biệt là khi bạn dùng kiểu varchar hay text/blob). Điều đó có nghĩa rằng MySQL cũng phải đọc và phân tích những thứ vô nghĩa đó khi query. Điều này được khắc phục khi bạn chạy

OPTIMIZE tablename;

Wednesday, October 22, 2008

Today, My problem is wrong character with Postgres

I must maintance a website that i dont know

Using primary key is character, but user input data by SHIFT-JIS. So when executeSQL ---> Bum

I suggest add new column to indentify that data.

MySQL versus PostgreSQL: Adding an Auto-Increment Column to a Table

Posted in Databases and Programming on Wednesday, the 5th of March, 2008.

The bulk of my database experience (almost eight years now) has been with the popular open-source MySQL database management system. MySQL has progressed significantly over the years, and has grown into a remarkable product. It finally has all the must-have features such as views, stored procs and referential integrity, coupled with the blistering performance for which MySQL has always been known. In short, it rocks.

But I digress. I've recently been having to get to grips with PostgreSQL (an old version of course - 7.1 or so - just to make life really interesting). It's largely intuitive, but there are quirks around most corners. This is my favourite so far: I recently needed to add an auto-incrementing integer "id" column to a table.
MySQL

This sort of thing will be second nature to MySQL developers:
ALTER TABLE mytable ADD myid INT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE;

One SQL command - not bad.
PostgreSQL

It turned out not to be so easy with our Postgres installation. For a start, there are no auto_increment columns. So, as with several other major RDBMSs, the solution is to create a "sequence", which is kind of like a pseudo-table which acts as a counter:
CREATE SEQUENCE mytable_myid_seq;

Next, we have to add our new column to the table, and specify that for each new row it should take its value from the sequence, using the NEXTVAL() function. For reasons best known to the Postgres guys, you can't do this in one step:
ALTER TABLE mytable ADD myid INT UNIQUE;

And then:
ALTER TABLE mytable ALTER COLUMN myid SET DEFAULT NEXTVAL('mytable_myid_seq');

We're getting there. We now have an auto increment column. The problem is that Postgres won't backfill this with values automatically: all pre-existing rows are currently null for this column. Let's change that:
UPDATE mytable SET myid = NEXTVAL('mytable_myid_seq');

Job done. Well, some time later, the job will be done. That final step is one of the slowest things you can possibly ask Postgres to do. For a mid-sized table (around 5,000,000 rows, with a handful of small numeric and text columns), that took about 2.5 hours on powerful hardware - so you'll want to leave this for a quiet time. Fortunately Postgres treats the UPDATE as an atomic transaction: nothing is committed until the command completes, so it will be difficult for you to leave the data in an inconsistent state.

Monday, October 20, 2008

TIP Convert latin1 to UTF-8 in MySQL

Today my problem is convert database from latin1 to utf-8 (with data is Shift-jis)

- Create new database, one table, input a lot fot record to test

Step by step:

Since MySQL 4.1, UTF-8 is the default charset. If you have an old database, containing data encoded in latin1, and you want upgrade to a newer MySQL server, than you have to do the following:

MySQL dump

First of all, we need to dump the old data into a file.


Code: Create a MySQL dump
 $ mysqldump -h host.com --user=frog -p --default-character-set=latin1 -c \
--insert-ignore --skip-set-charset dbname > dump.sql


Please mention, that you have to replace the user, the host and the dbname, otherwise it will result in an error :)


Convert dump

Next thing to do is, converting the characters in the MySQL dump from latin1 to UTF-8


Code: Convert dump
 $ iconv -f ISO-8859-1 -t UTF-8 dump.sql > dump_utf8.sql
$ perl -pi -w -e 's/CHARSET=latin1/CHARSET=utf8/g;' dump_utf8.sql


If you have another source charset, you need to replace the -f option with your local character set.


Drop and create

Now it's time to drop the old database and create a new one with UTF-8 support.


Code: Drop and Create
 $ mysql --user=frog -p --execute="DROP DATABASE dbname;
CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"

(MySql seems to recommend utf8_unicode_ci over utf8_general_ci for 5.1+, see http://dev.mysql.com/doc/refman/5.1/de/charset-unicode-sets.html)

Import dump to databse

Last but not least, we need to import the converted data back to the new database.


Code: Import dump
 $ mysql --user=frog --max_allowed_packet=16M -p --default-character-set=utf8 dbname <>  


The max_allowed_packet-option is sometimes important. If your import ends up with a "ERROR 1153 at line 42: Got a packet bigger than 'max_allowed_packet'", you need to increase the packet size. Please mention, that you also need to update /etc/mysql/my.cnf and set max_allowed_packet=16M under the [mysqld] directive

Done!!!Everything is okie

But I using upflow code, convert fail

Why???

Spent some of minute

There are some wrong character in table "member"

Clean table

Ping pong ping pong

Monday, September 29, 2008

How to integrate Appcelerator with CI

/*
* Author: tri_ngo83@yahoo.com
* Version: beta
* Requirement: PHP5.x, CI 1.6.3
*/

- Using one controller to make a delivery service class.
- Modify servicebroker to library serviceroker
- Modify file appcelerator.xml: servicebroker match to controller
<servicebroker poll="false" marshaller="application/json">@{rootPath}../index.php/service <servicebroker>
- Create new library: My_URI -- comment some lines in function _fetch_uri_string

File attachement:
system folder
index.php


contact mailto: tri_ngo83@yahoo.com

Sunday, September 14, 2008

Hoc Tieng Anh: basic

Mot so cau dam thoai thong dung:
Mot yeu cau thong thuong:

Is there a module out there or a way to allow the customer to upload a File?

For example I'm working on a T-Shirt printing business and I want the user to be able to upload a graphic for printing on the shirt.

do is there anything available with this type of capability?

Thursday, January 24, 2008

Wine cann't connect audio on Linux Fedora

- My Computer have a lot of problem about audio when restart computer. I think that this is error pulseaudio or haldaemon, but restart again is everything is Okie
- Because of Wine isn't running good.
Todo fixed this bug: you're restart Wine:
wineboot -r

Good luck to you

Friday, January 18, 2008

How to run httpd service automatically during startup

- How to run httpd service, or any other service automatically during startup
- I know its got something to do with the chkconfig command
- chkconfig --list
+ chkconfig [--level ]

- Example: If you want to off sendmail process when your system start up GUI, following line
chkconfig --level 5 sendmail off

How to enable superkey(Window key) in linux

Modify file X11/xorg.conf
Finding line
Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
Option "XkbOptions" "altwin:super_win"
EndSection

Good to you!

Saturday, December 29, 2007

Fefora la gi ho me

Title: Install fedora 7
Language: English and Vietnamese
Source: http://www.mjmwired.net/resources/mjm-fedora-f7.html

- Resize Partition from Hirent Boot CD
- From Disc DVD Fedora 7
Hoi bat ngo vi install hoi bi nhanh, DVD co khac.
- Update a lot of lib from update manager
- Install mplayer, plugin, gui from http://rpm.livna.org/rlowiki/
- Install driver cho cai AGP nvidia also from http://rpm.livna.org/rlowiki/
Yum install kmod-nvidia
- Install flash player
That su thi khong thich lam ... Because a lot of month ago dung no thi browser usually is suspend
- Install cai compiz-fusion from http://rpm.livna.org/rlowiki/
Dung la co tat hap tap voi vang nen lam sai hoi bi nhieu.
Phai dieu chinh mot so option in xorg thi moi enable Desktop Effect duoc.
- Install luon cai beryl-manager luon
- Install xvnkb nua chu
-------------------------------------------------------------------------------
Để thấy được phân vùng NTFS, bạn cần cài gói hỗ trợ NTFS của Fedora bằng lệnh sau
sudo yum install fuse fuse-libs ntfs-3g

* Fedora Repositories
- Import the GPG keys to these repositories:
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-livna
- Add reposity
sudo rpm -ivh http://rpm.livna.org/livna-release-7.rpm

* Install Nvidia Driver
- Recommends user install
3rd-party RPM packaged driver instead of using the installer from
Nvidia's website. Currently Livna provides a well packaged driver

* Rythmbox/Gstreamer - A simple audio application similar to iTunes layout.
- Most of Rythmbox and the Gstreamer system should be installed when installing Gnome (mentioned above). The missing components are just the MP3 (and other media) plugins.
- sudo yum install gstreamer-plugins-ugly gstreamer-plugins-bad
- Install het 11M

Monday, December 10, 2007

table with div

div.base-layer {
background: transparent;
/*border: solid #ccc 1px;*/
color: #000000;
margin: 0.5em 1px 0.5em 1px;
padding: 0px;
text-align: center;
width: auto;
}

div.table-row {
background:#FFFFCC none repeat scroll 0%;
border:1px solid #ccc;
color:#000000;
margin:0;
padding:0;
text-align: center;
width:99%;
}

div.left-layer10 {
border-right:1px solid #ccc;
float: left;
margin: 0;
padding: 2px;
width: 50px;
font-weight: bold;
}

div.left-layer11 {
border-right:1px solid #ccc;
float: left;
margin: 0;
padding: 2px;
width: 9%;
}

DIV.right-layer11 {
border: none;
float: right;
margin: 0;
padding: 2px;
width: 9%;
}

/* Watch out for this DIV... rule, it appears every now and then */

DIV.space-line {
clear: both;
margin: 0;
padding: 0;
width: auto;
}

Wednesday, November 21, 2007

Passwd

trinm --- Eil2Enga

s --- xeiWay7X

function check_all_box(obj, ids){
$$('input[id="' + ids + '"]').each(function(val){val.checked = obj.checked});
}

Wednesday, August 01, 2007

Expreience PHP (CI Session)

CodeIgniter: http://www.codeigniter.com/

- CI Session:

The Session class permits you maintain a user's "state" and track their activity while they browse your site. The Session class stores session information for each user as serialized (and optionally encrypted) data in a cookie. It can also store the session data in a database table for added security, as this permits the session ID in the user's cookie to be matched against the stored session ID. By default only the cookie is saved. If you choose to use the database option you'll need to create the session table as indicated below.

Note: The Session class does not utilize native PHP sessions. It generates its own session data, offering more flexibility for developers.

If The session was encrypt that config in config file. We can use serialize, unserialize and urlencode, urldecode to unencrypt.

Example:
$c = unserialize(urldecode('a%3A8%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22b4a94cbd5433e19108001ee784edc8fc%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A9%3A%22127.0.0.1%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A50%3A%22Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1185940671%3Bs%3A10%3A%22last_visit%22%3Bi%3A0%3Bs%3A6%3A%22zip_code%22%3Bs%3A8%3A%22132-5648%22%3B%7Ds%3A9%3A%22member_id%22%3Bs%3A2%3A%2241%22%3Bs%3A11%3A%22member_g_id%22%3Bs%3A1%3A%222%22%3B%7D'));
//$c = unserialize(urldecode('%3A2%3A%2241%22%3Bs%3A11%3A'));
$c['user_id'] = 'admin';
unset($c['member_id']);
unset($c['member_g_id']);
echo 'C = ' . urlencode(serialize($c));

Monday, January 29, 2007

Sữa plugin kalideoscope như thế nào

- The first time
- You phải download source của kalideoscope in sourceforge.com
- Error nằm ở

Thursday, November 30, 2006

Configuring xterm in Linux

xterm is a terminal which runs in X. In linux when you open xterm, you get a small window with a small - hard to read - font by default. Compared to the ordinary xterm, the gnome-terminal and konsole come loaded with lots of features and are good to view. So why would anybody use an xterm over the other two? The answer lies in its low memory foot print. While konsole takes a whooping 8MB and gnome-terminal over 3MB of memory, you can run xterm under 1MB which makes it blazingly fast even when your computer has only 64MB of RAM. Below I describe ways in which you could configure xterm to make it look good and easier to read with larger fonts.

# File : .Xresources
xterm*font: -*-fixed-medium-r-*-*-18-*-*-*-*-*-iso8859-*
xterm*font1: -*-*-*-*-*-*-2-*-*-*-*-*-*-*
xterm*font2: -misc-fixed-*-r-normal-*-8-*-*-*-*-*-iso8859-*
xterm*font3: -b&h-lucidatypewriter-bold-*-*-*-12-*-*-*-*-*-*-*
xterm*font4: -*-screen-bold-r-normal-*-16-*-*-*-*-*-iso8859-*
xterm*font5: -*-lucidatypewriter-medium-*-*-*-18-*-*-*-*-*-*-*
xterm*font6: -*-lucidatypewriter-medium-*-*-*-20-*-*-*-*-*-*-*
xterm*font7: -dec-terminal-bold-r-normal-*-14-*-*-*-*-*-iso8859-*

XTerm*background: white
XTerm*foreground: black
XTerm*pointerColor: red
XTerm*pointerColorBackground: black
XTerm*cursorColor: navy
XTerm*internalBorder: 3
XTerm*loginShell: true
XTerm*scrollBar: false
XTerm*scrollKey: true
XTerm*saveLines: 1000
XTerm*multiClickTime: 250

Friday, October 20, 2006

Học cách sử dụng SMBClient

- Phải tốn cả đống thời gian lên mạng tìm tutorial.
+ The first time, I try to read English tutorial, but I don't understand anything..
+ Nên đành đọc Tiếng Việt (may ra hiểu được một chút). Trang tham khảo http://www.danangpt.vnn.vn/htkh/thamkhao/hdh/hedh10.htm
Cấu hình
-# pico|vim /etc/samba/emb.conf

-Phần 1: Global setting:
-Phần 2: Sharing Setting

Chia sẻ file như thế nào:

Sau khi cấu hình phần global setting, chúng ta có thể tự tạo ra một thư mục chia sẻ và giới hạn truy cập theo nhóm hoặc người dùng có trên hệ thống.

Ví dụ: Để tạo thư mục chia sẻ hungpv trên máy Linux, chúng ta làm như sau :

Thêm vào vùng Sharing Setting những dòng dưới đây: .

[hungpv]
Comment: thu.muc cua hungpv
path=/home/hungpv
valid users =hungpv
browseable=yes
public=no
writeable=yes

Như vậy Samba sẽ tạo ra một thư mục chia sẻ hungpv trên máy chủ, do tham số browseable - yes nên thư mục này sẽ được nhìn thấy khi người dùng mở Windows Explorer, tuy nhiên do public = no và validusers = hungpv nên chỉ có User hungpv có thể đăng nhập. Ngoài việc phân cấp theo user, Samba cũng có thể thăng quyền truy cập cho cả nhóm người dùng, với nhóm chúng ta sử dụng dấu @ trước tên nhóm.


Kiểm tra cấu hình vừa thiết lập:

Sau khi thiết lập file cấu hình chúng ta nên kiểm tra lại, Samba cung cấp 2 công cụ là testparm và smbstatus. Để kiểm tra chính xác bạn phải đảm bảo máy trạm và máy chủ phải nối được với nhau (Kiểm tra bằng lệnh ping) .

1 Kiểm tra bằng công cụ Testparm:

Testparm là chương trình cho phép kiểm tra giá trị của thông số trong file cấu hình.

Cấu trúc của câu lệnh này là:

Testparm configfile [hobtnclmehostIP]

Configfile là đường dẫn và tên file cấu hình, mặc định nó lấy file smb.conf cất trong thư mục /etc/samba/smb.conf (từ redhat 7.0) và /etc/smb.conf (cho các phiên bản trước đó).

Hostname và HostIP là hai thông số không nhất thiết phải có, nó hướng dẫn Samba kiểm tra cả các dịch vụ đã liệt kê trong file smb.conf trên máy xác định bởi Hosmame và hostIP.

Ví dụ:

[root@mail /root] # teetparm /
etc/samba/smb.conf
imail.vitti.edu.vn
172.16.200.2000
Load smb config file from /etc/Samba/smb.conf
Procebsing section " [homes ] "
Proceeeing section " [printersl "
Loaded services file OK.
Allow counection from
imail.vitti.edu.vn
(172.16.200.2000) to homes
Allow connection from
imail.vitti.edu.vn
(172.16.200.2000) to printers

2. Kiểm tra bằng công cụ smbstatus:

Smbtatus là chương trình thông báo các kết nối hiện tại, cấu trúc của câu lệnh này như sau:

smbbtatus [-d] [-p] [-s configfile]

Tham số configfile mặc định được gán là /etc/samba/smb.conf. Tham số "-d" cho ra kết quả đầy đủ.

Chạy Samba server:

Sambaserver có hai tiến trình là smbd và nmbd.Tiến trình smbd cung cấp dịch vụ chia sẽ file và dữ liệu, tiến trình nmbd cung cấp khả năng hỗ trợ NETBIOS name. Cũng như các dịch vu khác, trên mạng Samba có 3 câu lệnh điều khiển là stop, start, restart. Cú pháp của chúng là :

/etc/init.d/smb start l stop l
restart

Sau khi cấu hình file smb.conf bạn phải khởi động dịch vụ Samba để máy linux đăng nhập vào workgroup, câu lệnh khởi động là:

#/etc/init.d/smb start

Sau khi khởi động dịch vụ máy Windows có thể truy cập đến máy Linux thông qua networkNeighborhood hoặc windows Explorer, máy Linux có thể dùng 2 câu lệnh smbclient smbmount để truy cập đến máy Windows và trên cả máy Linux khác có cài Samba.

Riêng đối với cái máy của tui thì lại khác(Slackware 10.0.2) thì phải mở file rc.samba rùi xem nó start gì thì start cái đó.

1. Sử dung câu lênh smbclient:

Smbclient cung cấp giao diện dòng lệnh gần giống như giao diện của FTP để truyền file qua mạng. Chi tiết về câu lệnh smbclient ban có thể tham khảo nhờ câu lệnh:

#man smbclient

Để liệt kê các thư mục chia sẻ có trên máy 172.16.200.203 bạn dùng smbclient với tham số -L:

#smbclient -L 172.16.200.203

Kết quả sẽ cho ra một số thư mục có trên máy 172.16.200.203, để vào một trong các thư mục trên bạn dùng lệnh smbclient với tham số -U tên user (tên user có quyền truy cập vào thư mục tương ứng) .

#Smbclient //172.16.200.203/
tên_thư_ mục -U tên_user

Sau khi gõ vào mật khẩu bạn sẽ nhận được dấu nhắc :

smh:\>

Tại dấu nhắc này bạn có thể dùng các câu lệnh như sau :

Ví dụ : Dùng smbclient nối đến máy Windows có địa chỉ IP là 172.16.4.53, để lấy file trên máy này ta phải làm lần lượt các bước sau:

Xác định các thư mục được chia sẻ trên máy 172.16.4.53: .

#smbchent -L 172.16.4.53 -U
tienna
added interface
ip=172.16.200.200
bcast=172.16.255.255
nmask=255.55.0.0
session request to 172.16.4.53
failed (Called name not present)
session request to 172 failed
(Called name not prebent)
Pabsword:
Domain=[STAFF.VITTI]
OS= [Windows 5.0 ]
Server= [Windows 2000 LAN Manager]

Sau khi nhập mật khẩu của tài khoản tienna (trên Windows) ta nhận được danh sách các thư mục share trên máy 172.16.4.53. Sau khi biết được các thư mục trên máy bạn phải dùng câu lệnh:

[root@backup /root)# smbchent /
/172.16.4.53/tienna -U tienna
Can't find include file /etc/Samba /smb.conf
.
added interface
ip 172.16.200.200
bcabt=172.16.255
.255
nmask:255.255.0.0
session request to 172.16.4.53
failed (Called name not present)
session request to 172 failed
(Called name not present)
Password :
Domain=[STAFF.VITTI ]
OS = [Windows 5.0 ]
Server=[Windows 2000 LAN Manager]
smb: \>

Tại dấu nhắc này bạn có thể xem các file bên trong thư mục tienna bằng lệnh Is, lấy nó về máy Linux bằng lệnh get hoặc mget:

smb: \> ls
.D 0 Fri Aug 24 00:02:24 2001
..D 0 Fri Aug 24 00:02:24 2001
ethereal-setup- 0.8.17.exe
A 6153372 Thu Apr 19 18:54:42
2001
gozilla39.exe A 1869172 Thu Jun 7 12:05:50 2001
smb:\> mget eth*
Get file ethereal-setup-
0 8.17.exe? y
getting file ethereal-setup-
0.8.17
.exe of
size 6153372 as ethereal-setup- 0.8.17.exe
(925.624 kb/s) (average 925.624 kb/s)
smb: \> ''

Sharename Type Comment
---------------- ------
E$ Disk
IPC$ IPC Remote
D$ Disk Default
tienna Disk
F$ Disk
ADMIN$ Disk Remote Admin
C$ Disk Deault share

Server Comment
--------- -------------

Workgroup Master
--------- -------------

Friday, October 13, 2006

Regular Expression in Javascript

Pattern Description
Escaping
\ Escapes special characters to literal and literal characters to special.

E.g: /\(s\)/ matches '(s)' while /(\s)/ matches any whitespace and captures the match.
Quantifiers
{n}, {n,}, {n,m}, *, +, ? Quantifiers match the preceding subpattern a certain number of characters. The subpattern can be a single character, an escape sequence, a pattern enclosed by parentheses or a character set.

{n} matches exactly n times.
{n,} matches n or more times.
{n,m} matches n to m times.
* is short for {0,}. Matches zero or more times.
+ is short for {1,}. Matches one or more times.
? is short for {0,1}. Matches zero or one time.

E.g: /o{1,3}/ matches 'oo' in "tooth" and 'o' in "nose".
Pattern delimiters
(pattern), (?:pattern) Matches entire contained pattern.

(pattern) captures match.
(?:pattern) doesn't capture match

E.g: /(d).\1/ matches and captures 'dad' in "abcdadef" while /(?:.d){2}/ matches but doesn't capture 'cdad'.

Note: (?:pattern) is very badly supported in older browsers.
Lookaheads
(?=pattern), (?!pattern) A lookahead matches only if the preceeding subexpression is followed by the pattern, but the pattern is not part of the match. The subexpression is the part of the regular expression which will be matched.

(?=pattern) matches only if there is a following pattern in input.
(?!pattern) matches only if there is not a following pattern in input.

E.g: /Win(?=98)/ matches 'Win' only if 'Win' is followed by '98'.

Note: Support for lookaheads is lacking in most but the newest browsers.
Alternation
| Alternation matches content on either side of the alternation character.

E.g: /(a|b)a/ matches 'aa' in "dseaas" and 'ba' in "acbab".
Character sets
[characters], [^characters] Matches any of the contained characters. A range of characters may be defined by using a hyphen.

[characters] matches any of the contained characters.
[^characters] negates the character set and matches all but the contained characters

E.g: /[abcd]/ matches any of the characters 'a', 'b', 'c', 'd' and may be abbreviated to /[a-d]/. Ranges must be in ascending order, otherwise they will throw an error. (E.g: /[d-a]/ will throw an error.)
/[^0-9]/ matches all characters but digits.

Note: Most special characters are automatically escaped to their literal meaning in character sets.
Special characters
^, $, ., ? and all the highlighted characters above in the table. Special characters mean characters that match something else than what they appear as.

^ matches beginning of input (or new line with m flag).
$ matches end of input (or end of line with m flag).
. matches any character except a newline.
? directly following a quantifier makes the quantifier non-greedy (makes it match minimum instead of maximum of the interval defined).

E.g: /(.)*?/ matches nothing or '' in all strings.

Note: Non-greedy matches are not supported in older browsers such as Netscape Navigator 4 or Microsoft Internet Explorer 5.0.
Literal characters
All characters except those with special meaning. Mapped directly to the corresponding character.

E.g: /a/ matches 'a' in "Any ancestor".
Backreferences
\n Backreferences are references to the same thing as a previously captured match. n is a positive nonzero integer telling the browser which captured match to reference to.

/(\S)\1(\1)+/g matches all occurrences of three equal non-whitespace characters following each other.
/<(\S+).*>(.*)<\/\1>/ matches any tag.

E.g: /<(\S+).*>(.*)<\/\1>/ matches '
text
' in "text
text
text".
Character Escapes
\f, \r, \n, \t, \v, \0, [\b], \s, \S, \w, \W, \d, \D, \b, \B, \cX, \xhh, \uhhhh \f matches form-feed.
\r matches carrriage return.
\n matches linefeed.
\t matches horizontal tab.
\v matches vertical tab.
\0 matches NUL character.
[\b] matches backspace.
\s matches whitespace (short for [\f\n\r\t\v\u00A0\u2028\u2029]).
\S matches anything but a whitespace (short for [^\f\n\r\t\v\u00A0\u2028\u2029]).
\w matches any alphanumerical character (word characters) including underscore (short for [a-zA-Z0-9_]).
\W matches any non-word characters (short for [^a-zA-Z0-9_]).
\d matches any digit (short for [0-9]).
\D matches any non-digit (short for [^0-9]).
\b matches a word boundary (the position between a word and a space).
\B matches a non-word boundary (short for [^\b]).
\cX matches a control character. E.g: \cm matches control-M.
\xhh matches the character with two characters of hexadecimal code hh.
\uhhhh matches the Unicode character with four characters of hexadecimal code hhhh.

Usage

Now, knowing how a RegExp is written is only half the game. To gain anything from them you have to know how to use them too. There are a number of ways to implement a RegExp, some through methods belonging to the String object, some through methods belonging to the RegExp object. Whether the regular expression is declared through an object constructor or a literal makes no difference as to the usage.

Description Example
RegExp.exec(string)
Applies the RegExp to the given string, and returns the match information. var match = /s(amp)le/i.exec("Sample text")

match then contains ["Sample","amp"]
RegExp.test(string)
Tests if the given string matches the Regexp, and returns true if matching, false if not. var match = /sample/.test("Sample text")

match then contains false
String.match(pattern)
Matches given string with the RegExp. With g flag returns an array containing the matches, without g flag returns just the first match or if no match is found returns null. var str = "Watch out for the rock!".match(/r?or?/g)

str then contains ["o","or","ro"]
String.search(pattern)
Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not. var ndx = "Watch out for the rock!".search(/for/)

ndx then contains 10
String.replace(pattern,string)
Replaces matches with the given string, and returns the edited string. var str = "Liorean said: My name is Liorean!".replace(/Liorean/g,'Big Fat Dork')

str then contains "Big Fat Dork said: My name is Big Fat Dork!"
String.split(pattern)
Cuts a string into an array, making cuts at matches. var str = "I am confused".split(/\s/g)

str then contains ["I","am","confused"]
Liorean is a twenty one years old medical student and hobbyist web designer mostly working with JavaScript and CSS, DOM and the newest html standards available. His personal dwelling on the net can be found at liorean@web-graphics.com.

JavaScript String Replace All

The JavaScript function for String Replace replaces the first occurrence in the string. The function is similar to the php function str_replace and takes two simple parameters. The first parameter is the pattern to find and the second parameter is the string to replace the pattern with when found. The javascript function does not Replace All...

JavaScript:
  1. str = str.replace(”find”,”replace”)

To ReplaceAll you have to do it a little differently. To replace all occurrences in the string, use the g modifier like this:

JavaScript: str = str.replace(/find/g,”replace”)

Thursday, October 12, 2006

Đôi khi nhìn lại chính mình

  1. Đôi khi, bạn cần phải chạy thật xa và bạn có thể thấy ai sẽ chạy theo bạn...
  2. Đôi khi, bạn cần phải nói nhỏ hơn để thấy được ai đang nghe mình...
  3. Đôi khi bân cần có một quyết định sai lầm chỉ để thấy được ai sẽ ở đó để giúp bạn sữa chữa nó...
  4. Đôi khi bạn cần để người bạn yêu đi khỏi để thấy được họ có đủ yêu bạn để trở về bên bạn...

Tuesday, October 10, 2006

Sưu tập (Cách xin việc)

Tập dượt để phỏng vấn thành công

Một thực tế là hầu hết các ứng viên không có thói quen thực hành kỹ năng phỏng vấn trước khi lên "đấu trường". Hệ quả là họ sẽ chịu những thất bại cay đắng một cách lãng nhách chỉ vì không chịu thực hành trước các kỹ năng

Vì thế, theo lời khuyên của các chuyên gia, trước khi tham dự phỏng vấn, hãy dành một chút thời gian chuẩn bị trước những điều cần nói bằng một cuộc phỏng vấn giả. Bạn có thể tập trả lời một số câu hỏi của những cuộc phỏng vấn thông thường đại loại như là "Tại sao bạn lại chọn công việc này?", hay "điểm yếu của bạn là gì?". Khi đã thành thạo, nhuần nhuyễn bạn sẽ có đủ tự tin để bước vào cuộc phỏng vấn thật với những suy nghĩ liền mạch, thông suốt.

Sai một ly đi một dặm

Giống như tất cả những ứng viên đi xin việc khác, bạn thường phải trải qua vô số thời gian nỗ lực và tập trung để tạo ấn tượng với một bức thư xin việc và một bản lý lịch hoàn hảo. Vì vậy, hãy dành thời gian chuẩn bị kỹ lưỡng đơn xin việc và bản lí lịch vì như đã nói ở trên, đây là bước quan trọng đầu tiên để các nhà tuyển dụng chú ý đến bạn. Đừng vì những lý do không đâu mà làm mất thành quả của cả một quá trình. Sai một ly đi một dặm.

Không lạm dụng hiểu biết

Mối công việc, mỗi nghề nghiệp đều có những từ chuyên ngành và liên tục thay đổi. Do đó khi viết đơn xin việc bạn không thể tuỳ tiện sủ dụng từ như thế nào cũng được. Vậy làm cách nào để có thể sử dụng đúng những từ chuyên môn của ngành nghề mà bạn đăng tuyển?

Câu trả lời rất đơn giản. Trước hết hãy tham dự vào các tổ chức chuyên ngành và đọc những cuốn sách có liên quan. Sau đó, thường xuyên lướt web. Bạn sẽ thấy các từ đó thường xuyên xuất hiện.

Tuy nhiên cũng phải cẩn thận khi sử dụng chúng. Đó là con dao hai lưỡi. Đừng lạm dụng từ chuyên ngành "bóng bẩy" quá vì mọi điều trên bản lý lịch trích ngang của bạn đều được kiểm chứng bằng những chuyên gia có kinh nghiệm!

Tập trung trước khi vào "trường đấu"

Trong hầu hết các buổi phỏng vấn, nhà tuyển dụng sẽ gọi lần lượt các ứng viên. Tuy nhiên, nhiều ứng viên lại gây mất thiện cảm với nhà tuyển dụng ngay từ giai đoạn này. Vì vậy, tốt nhất trong lúc chờ đến lượt mình, nên tránh nói chuyện, tán dóc, nghe nhạc hoặc nghe những đoạn clip hài vì nó có thể gây mất thiện cảm ngay lập tức với các nhà tuyển dụng.

Biểu lộ sự thông minh trong bản lý lịch

Khi viết đơn xin việc, đừng bao giờ viết "xem trong bản lý lịch" vào đơn. Bởi bản lý lịch trích ngang không có giá trị pháp lý. Tuy nhiên, trong rất nhiều trường hợp, đơn xin việc lại có. Do đó, thông thường nhà tuyển dụng thường yêu cầu bạn điền đầy đủ thông tin vào đơn xin việc, dù ngay trước đó họ đã nhận được lý lịch trích ngang của bạn.

Hãy tỏ ra thông minh bằng cách đọc kỹ các câu hỏi và tìm cách trả lời sao cho đầy đủ thông tin nhất và sáng tạo nhất.

Cũng cần chú ý khi viết lý lịch, hãy sử dụng các từ khoá chuyên ngành quan trọng bởi nay hầu hết các công ty đều sử dụng những phần mềm đặc biệt để đọc hồ sơ của bạn. Và biết đâu nó sẽ chỉ nhặt những từ quan trọng nhất trong lý lịch của bạn.

Tham khảo kinh nghiệm

Trước khi chấp nhận một vị trí công việc nào đó, hãy tham khảo ý kiến của những người đi trước, những người đã từng làm trong lĩnh vực tương tự. Họ sẽ là người cho bạn rất nhiều kinh nghiệm để đưa ra sự lựa chọn tốt nhất. Tuy nhiên điều này sẽ phản tác dụng nếu như bạn hỏi phải một người "láu cá", không những không có lợi mà còn có hại cho công việc của bạn sau này.