Saturday, November 28, 2009

Remove null element in PHP array and reorder

<?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

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

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.

Eyeblaster Creative Zone

http://creativezone.eyeblaster.com/

Wednesday, November 18, 2009

Using SharePoint and log4net in harmony

http://www.codeproject.com/KB/sharepoint/SharepointLog4Net.aspx

ASP.NET MVC

http://weblogs.asp.net/shijuvarghese/archive/2008/07/09/asp-net-mvc-vs-asp-net-web-form.aspx

SQL Server Integration Services

http://msdn.microsoft.com/en-us/library/ms141026%28lightweight%29.aspx

JSON hi-jacking

http://hackademix.net/2009/01/13/you-dont-know-what-my-twitter-leaks/

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

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

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');
}

Monday, November 9, 2009

More in request form

http://wiki.developers.facebook.com/index.php/Talk:Fb:request-form

Thursday, November 5, 2009

Reading a file content

Use this code:
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

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

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;
}

MVC

http://msdn.microsoft.com/en-us/library/ms978748.aspx

Facebook Fan page customization

http://thinkdiff.net/facebook/customize-facebook-fan-page-by-static-fbml-app/


http://thinkdiff.net/facebook/develop-customize-facebook-application-for-fan-page/


http://www.snipe.net/2009/10/mini-site-facebook-static-fbml/