pymssql first coding
กันยายน 5, 2007
import pymssql
con = pymssql.connect( user = “sa”, password = “”, host = “127.0.0.1″, database = “master”)
q = con.cursor ()
q.execute (“SELECT SYSTEM_USER”)
for row in q.fetchall ():
print row
python module
กันยายน 5, 2007
PyGame ทำ เกมส์ 2D
Panda3D ทำเกมส์ 3D
WxPython ทำ GUI Windows และแบบ API 32 ของ Windows
pyWin32 ก้อเรียกใช้ COM Object ของ Windows มาใช้ได้
Py2Exe compile เป็น windows execute file
Zope ทำ Application Server ขนาดใหญ่ได้
pycron ทำ cron job (crontab) บน Windows
BtTracker ทำ Bittorrent Server/Tracker
Bittorrent, Bittornado ทำ client ของ bittorrent ตัวนึง
mod_python เรียกใช้ผ่าน Apache
from : http://www.citecclub.org/forum/lofiversion/index.php/t2803.html
Add and Remove HTML elements dynamically with Javascript
กรกฎาคม 25, 2007
++++++ add element ++++++++
function addElement() {
var ni = document.getElementById(‘myDiv’);
var numi = document.getElementById(‘theValue’);
var num = (document.getElementById(‘theValue’).value -1)+ 2;
numi.value = num;
var newdiv = document.createElement(‘div’);
var divIdName = ‘my’+num+’Div’;
newdiv.setAttribute(‘id’,divIdName);
newdiv.innerHTML = ‘Element Number ‘+num+’ has been added! <a href=’#’ onclick=’removeElement(‘+divIdName+’)'>Remove the div “‘+divIdName+’”</a>’;
ni.appendChild(newdiv);
}
++++++ remove element ++++++++
function removeElement(divNum) {
var d = document.getElementById(‘myDiv’);
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
detect plugin
กรกฎาคม 10, 2007
//This script detects the following: //Flash //Windows Media Player //Java //Shockwave //RealPlayer //QuickTime //Acrobat Reader //SVG Viewer
var agt=navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);
var ns = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);
if (ie && win) { pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") +
detectIE("SWCtl.SWCtl.1","Shockwave Director") +
detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") +
detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") +
detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") +
detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") +
detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
nse = "";
for (var i=0;i<navigator.mimeTypes.length;i++)
nse += navigator.mimeTypes[i].type.toLowerCase();
pluginlist = detectNS("image/svg-xml","SVG Viewer") +
detectNS("application/x-director","Shockwave Director") +
detectNS("application/x-shockwave-flash","Shockwave Flash") +
detectNS("audio/x-pn-realaudio-plugin","RealPlayer") +
detectNS("video/quicktime","QuickTime") +
detectNS("application/x-mplayer2","Windows Media Player") +
detectNS("application/pdf","Acrobat Reader");
}
function detectIE(ClassID,name)
{ result = false;
document.write('<SCRIPT LANGUAGE=VBScript>
n on error resume next n
result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>n');
if (result) return name+','; else return ''; }
function detectNS(ClassID,name) {
n = "";
if (nse.indexOf(ClassID) != -1)
if (navigator.mimeTypes[ClassID].enabledPlugin != null)
n = name+","; return n; } pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0)
pluginlist = pluginlist.substring(0,pluginlist.length-1);
//SAMPLE USAGE- detect "Flash" //if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")
clipbord
กรกฎาคม 9, 2007
function CutToClipboard()
{
CutTxt = document.selection.createRange();
CutTxt.execCommand(”Cut”);
}
function CopyToClipboard()
{
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand(”Copy”);
}
function PasteFromClipboard()
{
document.Form1.txtArea.focus();
PastedText = document.Form1.txtArea.createTextRange();
PastedText.execCommand(”Paste”);
}
</script>
set font thai สำหรับ Jpgraph2
กรกฎาคม 8, 2007
DEFINE(“FF_ANGSA”,18); ลงไปใน ไฟล์ jpgraph.php
และ ใน ไฟล์ เดียว กัน นำ function นี้ ไป แทน ที่ ของ เดิม
function TTF() {this->style_names=array(FS_NORMAL=>’normal’,FS_BOLD=>’bold’,FS_ITALIC=>’italic’,FS_BOLDITALIC=>’bolditalic’);
// File names for available fonts
$this->font_files=array(
FF_COURIER => array(FS_NORMAL=>’cour.ttf’, FS_BOLD=>’courbd.ttf’, FS_ITALIC=>’couri.ttf’, FS_BOLDITALIC=>’courbi.ttf’ ),
FF_GEORGIA => array(FS_NORMAL=>’georgia.ttf’, FS_BOLD=>’georgiab.ttf’, FS_ITALIC=>’georgiai.ttf’, FS_BOLDITALIC=>” ),
FF_TREBUCHE =>array(FS_NORMAL=>’trebuc.ttf’, FS_BOLD=>’trebucbd.ttf’, FS_ITALIC=>’trebucit.ttf’, FS_BOLDITALIC=>’trebucbi.ttf’ ),
FF_VERDANA => array(FS_NORMAL=>’verdana.ttf’, FS_BOLD=>’verdanab.ttf’, FS_ITALIC=>’verdanai.ttf’, FS_BOLDITALIC=>” ),
FF_TIMES => array(FS_NORMAL=>’times.ttf’, FS_BOLD=>’timesbd.ttf’, FS_ITALIC=>’timesi.ttf’, FS_BOLDITALIC=>’timesbi.ttf’ ),
FF_COMIC => array(FS_NORMAL=>’comic.ttf’, FS_BOLD=>’comicbd.ttf’, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_ARIAL => array(FS_NORMAL=>’arial.ttf’, FS_BOLD=>’arialbd.ttf’, FS_ITALIC=>’ariali.ttf’, FS_BOLDITALIC=>’arialbi.ttf’ ) ,
FF_VERA => array(FS_NORMAL=>’Vera.ttf’, FS_BOLD=>’VeraBd.ttf’, FS_ITALIC=>’VeraIt.ttf’, FS_BOLDITALIC=>’VeraBI.ttf’ ),
FF_VERAMONO => array(FS_NORMAL=>’VeraMono.ttf’, FS_BOLD=>’VeraMoBd.ttf’, FS_ITALIC=>’VeraMoIt.ttf’, FS_BOLDITALIC=>’VeraMoBI.ttf’ ),
FF_VERASERIF => array(FS_NORMAL=>’VeraSe.ttf’, FS_BOLD=>’VeraSeBd.ttf’, FS_ITALIC=>”, FS_BOLDITALIC=>” ) ,
FF_SIMSUN => array(FS_NORMAL=>’simsun.ttc’, FS_BOLD=>’simhei.ttf’, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_CHINESE => array(FS_NORMAL=>CHINESE_TTF_FONT, FS_BOLD=>”, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_MINCHO => array(FS_NORMAL=>MINCHO_TTF_FONT, FS_BOLD=>”, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_PMINCHO => array(FS_NORMAL=>PMINCHO_TTF_FONT, FS_BOLD=>”, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_GOTHIC => array(FS_NORMAL=>GOTHIC_TTF_FONT, FS_BOLD=>”, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_PGOTHIC => array(FS_NORMAL=>PGOTHIC_TTF_FONT, FS_BOLD=>”, FS_ITALIC=>”, FS_BOLDITALIC=>” ),
FF_MINCHO => array(FS_NORMAL=>PMINCHO_TTF_FONT, FS_BOLD=>”, FS_ITALIC=>”, FS_BOLDITALIC=>” ) ,
FF_ANGSA => array(FS_NORMAL=>’angsa.ttf’, FS_BOLD=>’angsab.ttf’, FS_ITALIC=>’angsai.ttf’, FS_BOLDITALIC=>’angsaz.ttf’ ) ,
);
}
** ข้อมูล ภาษา ไทย ต้องเป็น UTF8
PHP tips
กรกฎาคม 8, 2007
check ตัวอักษร 0-9 a-Z และ ก-ฮ
Function preg_match
if( preg_match(“/^[0-9A-Zก-ฮ]$/”, $msg) ) {
do something
} else {
exit or do something
}
—————————————————————————————–
cache
$cacheDir = dirname(__FILE__) . ‘/cache/’;
if (isset($_GET['id'])) {
$cacheFile = $cacheDir . ‘_’ . $_GET['id'] . ‘.html’;
} else {
$cacheFile = $cacheDir . ‘index.html’;
}
if (file_exists($cacheFile))
{
header(“Content-Type: text/html”);
readfile($cacheFile);
exit;
}
// … more code coming
*** if your file to create cache is store in c:/webroot/
folder cache is c:/webroot/cache/
Streaming MP3
กรกฎาคม 6, 2007
Streaming MP3
To stream MP3’s on a page you will need to have an MP3 player like WinAmp, Windows Media Player, or Real Audio Player. The MP3 will stream as it loads on the page and will allow for longer larger sound files to be played.
1. Save your MP3 file to the same directory where you will be playing the sound from, or a sound directory which you know the URL for already,
2. Open up a notepad by clicking Start => Programs => Accessories => Notepad
3. Type in only the exact Address or URL of your MP3 file.
Type it in as simple as this:
http://www.domain.com/sound/music.mp3
where the domain is your domain, the sound folder is where you placed your MP3, and the music.mp3 is your mp3 file.
Save this file as music.m3u . Upload this file into the directory where you will place your sound.
4. Open your page up in an editor such as Notepad that will allow you to edit the code on the page.
5. Insert the following code into the HTML code of your page for a clickable link to stream by using this:
Clickable player and doawnload this file by right clicking it and save to yur directory:
<a href=”music.m3u” mce_href=”music.m3u”><img border=”0″ src=”mp3.gif” mce_src=”mp3.gif” width=”41″ height=”25″></a>
Or you can embed with this:
<EMBED src=”music.m3u” mce_src=”music.m3u” autostart=true hidden=true>
Or you can embed for both IE and Netscape with this:
<!This code for IE>
<EMBED SRC=”http://yourdomian.com/sound/music.m3u” HIDDEN=”true” AUTOSTART=”true” width=”128″ height=”128″>
<!This code for Netscape>
<OBJECT ID=”MediaPlayer”
classid=”CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95″
CODEBASE=”http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715“
standby=”Loading Microsoft Windows Media Player components…”
TYPE=”application/x-oleobject” width=”239″ height=”179″>
<PARAM NAME=”FileName” VALUE=”http://server/path/your-file.asx“>
<PARAM NAME=”AnimationatStart” VALUE=”false”>
<PARAM NAME=”TransparentatStart” VALUE=”true”>
<PARAM NAME=”AutoStart” VALUE=”true”>
<PARAM NAME=”ShowControls” VALUE=”0″>
<Embed TYPE=”application/x-mplayer2″
pluginspage=”http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&”
SRC=”http://Yourdomain.com/sound/music.m3u“
Name=MediaPlayer
ShowControls=0
Width=2
Height=2
</embed>
</OBJECT>
Simple Calendar
มิถุนายน 27, 2007
<HTML>
<BODY>
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
var week = new Array(“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”);
var monthdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var today = new Date();
var month = today.getMonth();
var day = today.getDay();
var dayN = today.getDate();
var days = monthdays[month];
if (month == 1) {
var year = today.getYear();
if (year%4 == 0) days = 29;
}
document.write(“<table border=’0′ cellspacing=’0′ cellpadding=’0′>”);
document.write(“<tr>”);
for (var i=0; i<7; i++) {
document.write(“<td width=’30′ height=’30′>”);
document.write(“<div align=’center’>” + week[i] + “</div>”);
document.write(“</td>”);
}
document.write(“</tr>”);
var jumped = 0;
var inserted = 1;
var start = day – dayN%7 + 1;
if (start < 0) start += 7;
var weeks = parseInt((start + days)/7);
if ((start + days)%7 != 0) weeks++;
for (var i=weeks; i>0; i–) {
document.write(“<tr>”);
for (var j=7; j>0; j–) {
document.write(“<td>”);
if (jumped<start || inserted>days) {
document.write(“<div align=’center’></div>”);
jumped++;
}
else {
if (inserted == dayN) document.write(“<div align=’center’>[" + inserted + "]</div>”);
else document.write(“<div align=’center’>” + inserted + “</div>”);
inserted++;
}
document.write(“</td>”)
}
document.write(“</tr>”);
}
document.write(“</table>”);
// End –>
</script>
</BODY>
</HTML>
file size
มิถุนายน 25, 2007
วิธีเข้าถึงขนาดของไฟล์ที่ input type=”file” โดยใช้ javascript +ActiveX
<html>
<head>
<script language=”JavaScript”>
function A()
{
var oas = new ActiveXObject(“Scripting.FileSystemObject”);
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + ” bytes”);
}
</script>
</head>
<body>
<form name=”a”>
<input type=”file” name=”b”>
<input type=”button” name=”c” value=”SIZE” onClick=”A();”>
</form>
</body>
</html>