Archive

Archive for the ‘Programming’ Category

Flix Cloud and S3 makes video sharing really easy

March 22nd, 2010

Being quite busy with implementing a video sharing feature on Sheet Music Trade, I have found that On2 had done a good job with Flix Cloud. Its REST based API makes video processing a real simple job and with Amazon S3 storage and Flow Player it seems that anyone with some level of programming can create a video sharing community nowadays. The days of struggling with FFMpeg (and php-ffmpeg for image extraction) are not very far away (still using this setup for one of the largest video sharing communities in Turkey), I feel that I won’t think about using Flix Cloud twice from now on.

Flix Cloud PHP is a great PHP sample library for encoding videos on Flix Cloud and Amazon S3 PHP Class is also a great source for managing files programmatically on S3.

Internet, PHP, Programming , , , , ,

Session is lost when including a page in frame from another site

September 30th, 2009

While trying to create an application for one of our resellers, I realized that session data on our side is lost when they include our application in an iframe on their site. This is because on some browsers (IE mostly), when you reference cross site pages by frames, cookies are not enabled for the site you reference. As session data is dependent on cookie, you loose session state too.

To prevent this, you should add a P3P header data to your referenced page header like below. You can add this to your global.asax for your dot net application.

1
2
3
4
protected void Application_BeginRequest(Object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
}

ASP.Net, Programming , ,

New site for Zaplat, tweaking SheetMusicTrade and a trip to Gelibolu

September 24th, 2009

Haven’t been posting lately, I have been busy with a major update for Zaplat, one of the first video sharing services in Turkey. Trying to speed things up a little bit, I have found myself struggling with AJAX updates, new video sharing features and lots of coding. I hope first beta will be available by the end of this month.

Today I have finally had some time to add the missing pages to administration pages of SheetMusicTrade, just after I realized that there are some bogus sheets added (one of them was a manual for some machine parts, I guess). I will keep an eye on the site more closely from now on.

Me and my wife had a trip to Gelibolu (Saros exactly) and had a great time there. Visited almost all of the monuments for the people died there during 1st World War and prayed for the heroes that fought like in hell without a second thought for the independent Turkey under the command of the great commander Mustafa Kemal Ataturk. Here are some photos…

 

Programming, Travel , , ,

Preserving values of password fields after postback

August 18th, 2009

You have created your sign up form with full power of AJAX but when you do your trick to check for username availability via AJAX, it seems that passwords fields are reset. You can overcome this situation by setting up passwords filed values each time you make a postback.

1
txtPassword.Attributes.Add("value", txtPassword.Text);

That should do the trick!

ASP.Net, Programming , , ,

Getting selected values of an checkbox array with JQuery

July 1st, 2009

With JQuery it is extremely easy to collect the checked values of an checkbox array. You can use the code below to collect checked items of an array named “itemSelect[]” and give an alert if none of them are checked. This code submits the collected data via ajax to “/ajax_do_something.php” to process the data. If sucessfully processed it refreshes the page to display new data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var selectedItems = new Array();
$("input[@name='itemSelect[]']:checked").each(function() {selectedItems.push($(this).val());});
 
if (selectedItems .length == 0) 
    alert("Please select item(s) to delete.");
else
    $.ajax({
	type: "POST",
	url: "/ajax_do_something.php",
	data: "items=" + selectedItems.join('|'),
	dataType: "text",
	success: function (request) {
	    document.location.reload();
	  },
	error: function(request,error){
	    alert('Error deleting item(s), try again later.');
	  }
	}
    )

JQuery, Javascript, Programming

Windows Mobile Marketplace opens its doors!

May 15th, 2009

Right after Blackberry AppWorld and Nokia OVI Store, Windows Mobile Marketplace opens its doors to developers. I hope MS enables developers to publish their programs more freely, not like Apple.

Windows Mobile Marketplace

PS: Don’t think that I hate Apple. I use an IPod Touch everyday, but not a fan of Apple so much.

Programming , , ,

When AJAX TabContainer is placed in an UpdatePanel, all styling is lost

May 8th, 2009

When you place an ASP.NET AJAX TabContainer in an UpdatePanel, the styles needed to show it properly may be lost. This is because UpdatePanel sometimes decides not to load required styles on PageLoad or on postbacks.

You can overcome this situation by placing an empty TabContainer outside any UpdatePanel, simply causing the browser to load all the required styles on PageLoad and use them for other TabContainers placed inside UpdatePanels.

ASP.Net, Programming

How to disable button that causes postback in ASP.net

April 30th, 2009

You can disable a button on the client side to prevent multiple clicks by just adding an onClick function that runs on client side. You should check if page has a client side validation script and it passes first. If so, you just disable the button and call postback event.

Here is an example for the button named “btnAddcustomer”. Just paste it into Page_Load.

1
2
Dim strDisable As String = "if (typeof(Page_ClientValidate) == 'function') {if (Page_ClientValidate() == false) { return false; }} this.value = 'Please wait...'; this.disabled = true; " & ClientScript.GetPostBackEventReference(btnAddCustomer, "")
btnAddCustomer.Attributes.Add("onclick", strDisable)

ASP.Net, Programming , , ,

How to get traffic details of a domain in Plesk Expand via MySQL

March 19th, 2009

As you might know, Plesk Expand does not limit traffic of domains in any way. So if you want to charge your customers for extra traffic with plain Plesk and Expand, you should do some extra work. As there are no API commands to get traffic details of a domain hosted on Plesk, you have to get your hands dirty and query these data from Plesk Expand MySQL.

First, you have to establish a connection to MySQL, you have to get login credentials from Plesk Expand config file. In my Plesk Expand server, this file is found in /usr/local/expand/conf/expand.conf . In this file you can find the database name, username and password.

1
2
3
4
5
6
7
8
9
10
11
[root@exp ~]# more /usr/local/expand/conf/expand.conf
 
################### Database settings
[DBConnection]
# Database name
db=expand
# Database location
host=localhost
# Database credentials
user=expand
password=xxxxxxxxxx

Now you can connect to mysql via the command below.

1
2
[root@exp ~]# /usr/bin/mysql -uexpand -p
Enter password:

Just enter the password you acquired in previous step and you are authenticated. Now as the database name is “expand”, you have to switch to that database

1
2
3
4
mysql> use expand;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

Now as you are in, you can enter queries to get the data you need. There are 4 tables which are important for us right now.

  • plesk_domain
  • plesk_domain_stat
  • exp_mail_traffic
  • plesk_domain_limit

You can query the traffic limit of domain via:

1
2
3
4
5
6
SELECT plesk_domain.id, plesk_domain.name, plesk_domain_limit.value / 1048576 as max_traffic
FROM plesk_domain, plesk_domain_limit
WHERE plesk_domain.id = plesk_domain_limit.domain_id
AND limit_name = 'max_traffic'
AND plesk_domain_limit.value > 0
AND plesk_domain.name = 'testdomain.com';

You can query the total traffic that domain made in current month via:

1
2
3
4
SELECT plesk_domain.id, plesk_domain.name, plesk_domain_stat.traffic / 1048576 as traffic
FROM plesk_domain, plesk_domain_stat
WHERE plesk_domain.id = plesk_domain_stat.domain_id
AND plesk_domain.name = 'testdomain.com';

But this total traffic includes Web, FTP and SMTP/POP3 traffics. If you want to get pure Web and FTP traffic you should extract mail traffic from this value. You can query the SMTP and POP traffic that domain made in the month stated in query via:

1
2
3
4
SELECT plesk_domain.id, plesk_domain.name, ifnull((select sum(exp_mail_traffic.smtp_out) + sum(exp_mail_traffic.pop3_imap_out)
from exp_mail_traffic where exp_mail_traffic.domain_id = plesk_domain.id and exp_mail_traffic.date >= '2009-03-01' and exp_mail_traffic.date < '2009-04-01'),0) / 1048576 as mail_traffic
FROM plesk_domain
WHERE plesk_domain.name = 'testdomain.com';

And if you combine them altogether, here is a query that fetches the domains that has traffic limits and which total FTP and Web traffic usage exceeds 90% of their allowed limit for the given date (March of 2009 in this case).

1
2
3
4
5
6
7
8
9
10
11
SELECT plesk_domain.id, plesk_domain.name, plesk_domain_stat.traffic / 1048576 as traffic, plesk_domain_limit.value / 1048576 as max_traffic,
ifnull((select sum(exp_mail_traffic.smtp_out) + sum(exp_mail_traffic.pop3_imap_out)
from exp_mail_traffic where exp_mail_traffic.domain_id = plesk_domain_stat.domain_id and exp_mail_traffic.date >= '2009-03-01' and exp_mail_traffic.date < '2009-04-01'),0) / 1048576 as mail_traffic
FROM plesk_domain, plesk_domain_limit, plesk_domain_stat
WHERE plesk_domain.id = plesk_domain_limit.domain_id
AND plesk_domain.id = plesk_domain_stat.domain_id
AND plesk_domain_stat.traffic - ifnull((select sum(exp_mail_traffic.smtp_out) + sum(exp_mail_traffic.pop3_imap_out)
from exp_mail_traffic where exp_mail_traffic.domain_id = plesk_domain_stat.domain_id and exp_mail_traffic.date >= '2009-03-01' and exp_mail_traffic.date < '2009-04-01'),0) > (plesk_domain_limit.value * 0.9)
AND limit_name = 'max_traffic'
AND plesk_domain_limit.value > 0
ORDER BY plesk_domain.name ASC;

This query can be used to warn customers about their traffic approaching its limits. And you can use the query below to get the domains exceeding their traffic limits.

1
2
3
4
5
6
7
8
9
10
11
SELECT plesk_domain.id, plesk_domain.name, plesk_domain_stat.traffic / 1048576 as traffic, plesk_domain_limit.value / 1048576 as max_traffic,
ifnull((select sum(exp_mail_traffic.smtp_out) + sum(exp_mail_traffic.pop3_imap_out)
from exp_mail_traffic where exp_mail_traffic.domain_id = plesk_domain_stat.domain_id and exp_mail_traffic.date >= '2009-03-01' and exp_mail_traffic.date < '2009-04-01'),0) / 1048576 as mail_traffic
FROM plesk_domain, plesk_domain_limit, plesk_domain_stat
WHERE plesk_domain.id = plesk_domain_limit.domain_id
AND plesk_domain.id = plesk_domain_stat.domain_id
AND plesk_domain_stat.traffic - ifnull((select sum(exp_mail_traffic.smtp_out) + sum(exp_mail_traffic.pop3_imap_out)
from exp_mail_traffic where exp_mail_traffic.domain_id = plesk_domain_stat.domain_id and exp_mail_traffic.date > '2009-03-01' and exp_mail_traffic.date < '2009-04-01'),0) > plesk_domain_limit.value
AND limit_name = 'max_traffic'
AND plesk_domain_limit.value > 0
ORDER BY plesk_domain.name ASC;

You can create some windows service to connect to Plesk Expand MySQL and query this data each month to bill your customers for extra traffic.

Programming , , , , , ,