<?php
$my_array = array(5, "abc", null, 2.5, NULL, 0, "", false, 8);
print_r($my_array);
function is_notnull($v) {
return !is_null($v);
}
$remove_null_array = array_filter($my_array, "is_notnull");// remove null element
echo "<p>remove_null_array:<br />";
print_r($remove_null_array);
$reordered_array = array_values($remove_null_array);
echo "<p>reordered_array:<br />";
print_r($reordered_array); // reorder the array values
Saturday, November 28, 2009
Thursday, November 26, 2009
Wednesday, November 25, 2009
Inversion of control
Inversion of control, or IoC, is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming.
http://en.wikipedia.org/wiki/Inversion_of_control
http://caterpillar.onlyfun.net/Gossip/SpringGossip/IOC.html
http://msdn.microsoft.com/en-us/library/cc707904.aspx
http://en.wikipedia.org/wiki/Inversion_of_control
http://caterpillar.onlyfun.net/Gossip/SpringGossip/IOC.html
http://msdn.microsoft.com/en-us/library/cc707904.aspx
Tuesday, November 24, 2009
What does document.domain = document.domain do?
http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do
I encounter a domain problem today and finally get it work by
document.domain = document.domain
Also, if you press the back button, the onload event of iframe will be faster than that of the parent frame and may cause permission denied error. The solution to this is to setTimeout and use the try-catch loop.
I encounter a domain problem today and finally get it work by
document.domain = document.domain
Also, if you press the back button, the onload event of iframe will be faster than that of the parent frame and may cause permission denied error. The solution to this is to setTimeout and use the try-catch loop.
Monday, November 23, 2009
Wednesday, November 18, 2009
Database Connection Pool
In software engineering, a connection pool is a cache of database connections maintained by the database so that the connections can be reused when the database receives future requests for data. Connection pools are used to enhance the performance of executing commands on a database. Opening and maintaining a database connection for each user, especially requests made to a dynamic database-driven website application, is costly and wastes resources. In connection pooling, after a connection is created, it is placed in the pool and it is used over again so that a new connection does not have to be established. If all the connections are being used, a new connection is made and is added to the pool. Connection pooling also cuts down on the amount of time a user must wait to establish a connection to the database.
http://en.wikipedia.org/wiki/Connection_pool
http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx
http://en.wikipedia.org/wiki/Connection_pool
http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx
Factory Method Pattern
The factory method pattern is an object-oriented design pattern. Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. The factory method design pattern handles this problem by defining a separate method for creating the objects, whose subclasses can then override to specify the derived type of product that will be created. More generally, the term factory method is often used to refer to any method whose main purpose is creation of objects.
http://en.wikipedia.org/wiki/Factory_method_pattern
http://lennilobel.wordpress.com/2009/08/06/leveraging-polymorphism-with-factory-classes/
http://dofactory.com/Patterns/PatternFactory.aspx
http://en.wikipedia.org/wiki/Factory_method_pattern
http://lennilobel.wordpress.com/2009/08/06/leveraging-polymorphism-with-factory-classes/
http://dofactory.com/Patterns/PatternFactory.aspx
Tuesday, November 17, 2009
Sunday, November 15, 2009
Wednesday, November 11, 2009
Tuesday, November 10, 2009
IE6 png fix
Javascript method (modified from source: http://homepage.ntlworld.com/bobosola)
function pngfix() {
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (version < 7.0) && (document.body.filters)) {
for (var i = 0; i < document.images.length; i++) {
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = " + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\">"
img.outerHTML = strNewHTML
i = i - 1
}
}
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof (window.onload) != 'function') { window.onload = func; }
else { window.onload = function() { oldonload(); func(); } }
}
addLoadEvent(pngfix);
2. CSS method:
#template
{
_background-image: none;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../images/guide2.png', sizingMethod='scale');
}
function pngfix() {
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (version < 7.0) && (document.body.filters)) {
for (var i = 0; i < document.images.length; i++) {
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = " + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\">"
img.outerHTML = strNewHTML
i = i - 1
}
}
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof (window.onload) != 'function') { window.onload = func; }
else { window.onload = function() { oldonload(); func(); } }
}
addLoadEvent(pngfix);
2. CSS method:
#template
{
_background-image: none;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../images/guide2.png', sizingMethod='scale');
}
Monday, November 9, 2009
Saturday, November 7, 2009
Thursday, November 5, 2009
Reading a file content
Use this code:
StreamReader sr = new StreamReader(Server.MapPath("xxx.txt"));
string m_sOutput = sr.ReadToEnd();
StreamReader sr = new StreamReader(Server.MapPath("xxx.txt"));
string m_sOutput = sr.ReadToEnd();
Facebook Application Box Development
To Add application box to Wall and Info Tab/Box Tab:
http://wiki.developers.facebook.com/index.php/Using_profile_setFBML
API: http://wiki.developers.facebook.com/index.php/Profile.setFBML
Future: http://apps.facebook.com/comicbooks/screencasts/New-Profile-1
1. You need to first call the profile.setFBML
http://wiki.developers.facebook.com/index.php/Profile.setFBML
For updating profile box (dynamic content), use
http://fbcookbook.ofhas.in/2009/02/04/updating-profile-box-using-fbref/
More posts:
http://forum.developers.facebook.com/viewtopic.php?id=26910
http://forum.developers.facebook.com/viewtopic.php?id=31613
2. And then add the Add to Profile button for users to click on it
http://wiki.developers.facebook.com/index.php/Fb:add-section-button
Another method to add the "add to profile" button:
http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowAddSectionButton
FB.Connect.showAddSectionButton("profile", document.getElementById("addProfileButton"));
You need to induce users to click on the button:
http://forum.developers.facebook.com/viewtopic.php?pid=153464
3. Show different info. according to whether the user adds the profile box
Still looking at the info below
http://forum.developers.facebook.com/viewtopic.php?id=36196
http://forum.developers.facebook.com/viewtopic.php?id=33809
http://forum.developers.facebook.com/viewtopic.php?pid=49318
http://wiki.developers.facebook.com/index.php/Talk:Profile.setFBML#How_to_update_profiles_of_all_users_who_installed_your_app.3F
http://wiki.developers.facebook.com/index.php/Using_profile_setFBML
API: http://wiki.developers.facebook.com/index.php/Profile.setFBML
Future: http://apps.facebook.com/comicbooks/screencasts/New-Profile-1
1. You need to first call the profile.setFBML
http://wiki.developers.facebook.com/index.php/Profile.setFBML
For updating profile box (dynamic content), use
http://fbcookbook.ofhas.in/2009/02/04/updating-profile-box-using-fbref/
More posts:
http://forum.developers.facebook.com/viewtopic.php?id=26910
2. And then add the Add to Profile button for users to click on it
http://wiki.developers.facebook.com/index.php/Fb:add-section-button
Another method to add the "add to profile" button:
http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowAddSectionButton
FB.Connect.showAddSectionButton("profile", document.getElementById("addProfileButton"));
You need to induce users to click on the button:
http://forum.developers.facebook.com/viewtopic.php?pid=153464
3. Show different info. according to whether the user adds the profile box
Still looking at the info below
http://forum.developers.facebook.com/viewtopic.php?id=36196
http://forum.developers.facebook.com/viewtopic.php?id=33809
http://forum.developers.facebook.com/viewtopic.php?pid=49318
http://wiki.developers.facebook.com/index.php/Talk:Profile.setFBML#How_to_update_profiles_of_all_users_who_installed_your_app.3F
Facebook Stream.publish
Facebook issues new Open Stream API and the feed template is now deprecated.
Use this in backend:
http://wiki.developers.facebook.com/index.php/Stream.publish
Use this in iframe or facebook connect page:
http://wiki.developers.facebook.com/index.php/FB.Connect.streamPublish
Using the open stream API:
http://wiki.developers.facebook.com/index.php/Using_the_Open_Stream_API
http://wiki.developers.facebook.com/index.php/Attachment_%28Streams%29
Use this in backend:
http://wiki.developers.facebook.com/index.php/Stream.publish
Use this in iframe or facebook connect page:
http://wiki.developers.facebook.com/index.php/FB.Connect.streamPublish
Using the open stream API:
http://wiki.developers.facebook.com/index.php/Using_the_Open_Stream_API
http://wiki.developers.facebook.com/index.php/Attachment_%28Streams%29
Tuesday, November 3, 2009
Scale images in ASP.net
Using this code:
static System.Drawing.Image Scale(System.Drawing.Image imgPhoto, int v_iPercent)
{
int destWidth = (int)(imgPhoto.Width * v_iPercent / 100.0);
int destHeight = (int)(imgPhoto.Height * v_iPercent / 100.0);
Bitmap bmPhoto = new Bitmap(imgPhoto, destWidth, destHeight);
return bmPhoto;
}
static System.Drawing.Image Scale(System.Drawing.Image imgPhoto, int v_iPercent)
{
int destWidth = (int)(imgPhoto.Width * v_iPercent / 100.0);
int destHeight = (int)(imgPhoto.Height * v_iPercent / 100.0);
Bitmap bmPhoto = new Bitmap(imgPhoto, destWidth, destHeight);
return bmPhoto;
}
Subscribe to:
Posts (Atom)