Tanveer’s Weblog

Entries categorized as ‘Tips' n Tricks'’

C++/CLI: Object Clone

May 8, 2009 · Leave a Comment

Basically, Clone can be implemented either as a deep copy or a shallow copy. In a deep copy, all objects are duplicated; whereas, in a shallow copy, only the top-level objects are duplicated and the lower levels containreferences.

But here we work under System::Runtime::Serialization::Formatters::Binary

Step 1: Serialize your object
Step 2: And then Deserialize  your object
Step 3: Close you MemoryStream instance
Step 4: Return Object
That’s it..

So here is the method,

public: System::Object^ Clone(System::Object^ apObj )
{
MemoryStream^ ms = gcnew MemoryStream();
BinaryFormatter^ bf = gcnew BinaryFormatter();
bf->Serialize( ms, apObj );
ms->Position = 0;
System::Object^ obj = bf->Deserialize( ms );
ms->Close();
return obj;
}

This is most fast way to clone your object very easily. So fulks ..

enjoy ;)

Categories: .NET · C++/CLI · Tips' n Tricks'

Communicating with C++/CLI to ActionScript

March 1, 2009 · Leave a Comment

Inspired by Gabe Wishnie
As a matter of fact, i was tried to implement C# and the Flash Player 8 External API with my C++/CLI project. However,  i was using Visual Studio 2005.
My main goal of this post is to aware what is the most basic part to implement this kind of staff in project.
Troubleshooting
1. To begin porting over the FLVPlayer it will be batter to use the most updated flash player.
2. Most of the time people ask about the problem with CallFunction method as it said this method is not a member.
3. If this kind of ambiguous problem faced then re-check your Flash Virsion. Flash 6,7 will the main cause of this error. Upgrade it into 8, 9 or 10
4. In ActionScript you must add these lines first

import flash.external.ExternalInterface;
ExternalInterface.addCallback("YourMethod", null, YourMethod);
function YourMethod(uri:String):Void
{
if(uri == "TANVEER")
{
// something my logic will be applicable;
}
}

5. In C++/CLI

private: AxShockwaveFlashObjects::AxShockwaveFlash^ mpAxShockwaveFlashBee;
private: System::Void mpButtonClick_Click(System::Object^ sender, System::EventArgs^ e)
{

mpAxShockwaveFlashBee->CallFunction(“<invoke” + ” name=\”loadAndPlayVideo\” returntype=\”xml\”><arguments><string>TANVEER</string></arguments></invoke>”);

}

6. Done! It is now that easy to pass data back ActionScript and C++/CLI.

My Source code:needbee.rar.pdf

rename it as needbee.rar

Categories: .NET · C++/CLI · Tips' n Tricks'

[HotFixer] Transparent PNG support into IE6 using TwinHelix

July 29, 2008 · 2 Comments

Couple of days ago one of my colleague asked my why ie6 couldn’t be able to show a trasparent png image ! He was so rock n roll mood about this matter ! :D n asked me is there any solution to fix this crap!! Unfortunatly i dont have any thing to say. So i googled for a while n got the answer. Here is the key things we can do to fix this bug.

1. Download TwinHelix iepngfix.zip v1.0 (37kb) under GNU LGPL, version 2.1 or later. After that you can open “iepngfix.html” in a browser; to find the step by step instructions.

2. Copy and paste iepngfix.htc and blank.gif into your website folder.

3. Copy and paste this into your website’s CSS or HTML:

<style type="text/css">
img, div { behavior: url(iepngfix.htc) }
</style>

That CSS selector must include the tags/elements on which you want PNG support — basically, give it a comma-separated list of tags you use. It must also include the correct path to the .HTC relative to the HTML document location (not relative to the CSS document!). For instance, yours may look like this:

<style type="text/css">
img, div, a, input { behavior: url(/css/resources/iepngfix.htc) }
</style>

4. If your site uses subfolders, open the .HTC file in a text editor like Windows Notepad and change the blankImg variable to include a correct path to blank.gif like so:

var blankImg = '/images/blank.gif';

Again the path is relative to the HTML file. Otherwise, you will see a “broken image” graphic!

Now if you would like to use this behavior in your defined css class just use something like

<style type="text/css">
.myimg{ behavior: url(/css/resources/iepngfix.htc);padding-left:5px ... }
</style>

That’s it ! You are done. Now you can enjoy any transparent png image file any where in your web derictory

;)

Ref: twinhelix

Categories: Fun · Tips' n Tricks'
Tagged: , , ,

[Tips] MP3 support, DVD playback in Ubuntu

July 19, 2008 · 1 Comment

Some times it is really disturbing after installed a new Ubuntu/Linux and cant play mp3 files. That’s why i need to make a note down here :D

1. MP3 support, DVD playback, Java plugin, and Flash plugin

To install ubuntu-restricted-extras package. In terminal window, command is:

sudo apt-get install ubuntu-restricted-extras

For Kubuntu, command is :

sudo apt-get install kubuntu-restricted-extras

For Xubuntu, command is:

sudo apt-get install xubuntu-restricted-extras

2. Install w32codecs

This non-free multimedia codecs will be used for MPlayer and Xine. To install w32codecs, you can see also here.

3. Install CompizConfig Settings Manager

sudo apt-get install compizconfig-settings-manager

4. Install Opera 9.24

To use commercial repository for Ubuntu 7.10.

sudo gedit /etc/apt/sources.list

Add this line:

deb http://archive.canonical.com/ gutsy partner

After save file, run these commands:

sudo apt-get update
sudo apt-get install opera

5. Clean up Ubuntu

To clean up Ubuntu 7.10, run the following commands:

sudo apt-get autoclean
sudo apt-get clean

Or use:

sudo apt-get autoremove

Done!

Categories: Linux · Tips' n Tricks' · UBUNTU
Tagged:

[Apache] Loopback Interface Testing

July 15, 2008 · 2 Comments

Sometimes it’s really important to test multiple websites on localhost. How we can do that? Very easy! ;) .. Yes we can use different port for each site. Some days ago i found one of the windows hosting server did this for their different users. So we can also be able to to it in apache..

What we need is to initialize the port for each site.. here is an example

We need to edit our httpd.conf file and paste these code in the suitable place

Listen 127.0.0.1:8000
Listen 127.0.0.1:1111
BindAddress 127.0.0.1

Port 1111
Port 8000

ServerName 127.0.0.1

NameVirtualHost *

<VirtualHost *:8000>
DocumentRoot “/home/username/test/example.org/htdocs”
<Directory “/home/username/test/example.org/htdocs”>
Options Indexes FollowSymLinks MultiViews
AllowOverride None

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:1111>
DocumentRoot “/home/username/test/example.com/htdocs/”
<Directory “/home/username/test/example.com/htdocs/”>
Options Indexes FollowSymLinks MultiViews
AllowOverride None

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

done, now port 8000 is for our development and 1111 is for testing purpose

enjoy ;)

Ref: Security Tips for Server Configuration

Categories: Apache · Linux · Tips' n Tricks'
Tagged: ,

[CakePHP] Unit Testing

July 10, 2008 · 2 Comments

What a fun !! :D
Today i test one of my Country Model using cakephp component. That why i write down this notes to make sure that i can use several times.

1. Download Simple Test unit testing suite.
2. Uncompress it in my app/vendors directory.
3. Change DEBUG level of 1 in my app/config/core.php file
4. Create a new database connection in app/config/database.php for only testing purpose like;

var $test = array(
‘driver’ => ‘mysql’,
‘persistent’ => true,
‘host’ => ‘localhost’,
‘login’ => ‘root’,
‘password’ => ”,
‘database’ => ‘db_name’,
‘prefix’ => ”,
‘encoding’ => ‘utf8′
);

5. Fixture : Create a file named country_test_fixture.php in your app/tests/fixtures directory, with the following content

<?php
class CountryTestFixture extends CakeTestFixture {

var $name = ‘CountryTest’;

var $import = array(‘model’ => ‘Country’, ‘records’ => true , ‘connection’ => ‘test’);

}
?>

6. Test Case : Create a file named country.test.php in your app/tests/cases/models directory, with the following contents:

<?php

loadModel(‘Country’);

class CountryTest extends Country {
var $name = ‘Country’;
//var $useDbConfig = ‘test_suite’;
}

class CountryTestCase extends CakeTestCase {

var $fixtures = array( ‘Country_test’ );

function testFindAll() {

$this->CountryTest =& new CountryTest();

$result = $this->CountryTest->findAll(“Country.country_id=1″);

$expected = array(

array (
‘Country’ => array( ‘country_id’ => 1, ‘region_id’ => 2 , ‘country’ => ‘Bangladesh’ ),

)

);

$this->assertEqual($result, $expected);

}

}
?>

7. Running My Test Case: Point my browser to http://tanveer-noman/myProject/test.php. Click on App Test Cases and find the link to your models/country.test.php. Click on that link.
Waoow!! I got a nice green screen saying that your test succeded.
;)

To know more

cake bake

Categories: Fun · Tips' n Tricks' · cakePHP
Tagged:

CakePHP: Creating a route usage https (SSL connection)

July 9, 2008 · 8 Comments

While playing in my workspace i need to make a route which should be use a secure path. That means https (SSL connection). So after googled for while i got the idea. Basically what i need is.. when an user in my sing in page will go through via the ssl connection. After entering user name and password will validated and redirect in to another location. So usually user will go through in https protocol then again redirected into http.

Here what i did;

Well, obviously i use cake’s component

1. Create a file ssl.php into app/controllers/components/
paste this code

<?php
class SslComponent extends Object {

var $components = array('RequestHandler');

var $Controller = null;

function initialize(&$Controller) {
$this->Controller = $Controller;
}

function force() {
if(!$this->RequestHandler->isSSL()) {
$this->Controller->redirect('https://'.$this->__url());
}
}

function unforce() {
if($this->RequestHandler->isSSL()) {
$this->Controller->redirect('http://'.$this->__urll());
}
}

function __url() {
$port = env('SERVER_PORT') == 80 ? '' : ':'.env('SERVER_PORT');

return env('SERVER_NAME').$port.env('REQUEST_URI');
}

function __urll() {
$port = env('SERVER_PORT') == 443 ? '' : ':'.env('SERVER_PORT');

return env('SERVER_NAME').$port.env('REQUEST_URI');
}

}
?>

you can find it also here but i added unforce() and __urll() ;)

3. Now, in my case only when user click in to sign in or lend now, I need the https connection. Thats why, in my home controller i added this beforeRender() method, but make sure you assign this Ssl component.

var $components = array( 'Ssl' );
public function beforeRender(){

$action = array( 'signin', 'lendnow' );

if( in_array( $this->params['action'] , $action ) ){

     $this->Ssl->force();
}else{
     $this->Ssl->unforce();
}

}

So, i will create a secure connection with my apache server.
4. User now enter their user name and password and submit

5. If anyone click beside this they will have only http connection

That’s it

enjoy ;)

Categories: Tips' n Tricks' · cakePHP
Tagged:

[Linux] Crontab every five minutes

July 8, 2008 · 3 Comments

Well, i want to schedules to run one of my file every 5 minutes. Then what would be the best choose. Yes, CRON.
I can schedule my cron to run that file every five minutes to execute my desired results. Thats why i want to make a note on this regards.

To edit the crontab i use the following command:

$ crontab -e

To list my currnet crontab

$ crontab -l

The following is the format entries in a crontab must be. Note all lines starting with # are ignored, comments.

So in terminal print ‘Hello’ every 5 minutes..


# MIN   HOUR   MDAY  MON  DOW   COMMAND 
   */5     *      *     *    *    echo 'Hello' 
MIN	Minute 	 0-60
HOUR	Hour [24-hour clock] 	0-23
MDAY	Day of Month 	1-31
MON	Month 	1-12 OR jan,feb,mar,apr ...
DOW	Day of Week 	0-6 OR
sun,mon,tue,wed,thu,fri,sat
COMMAND	Command to be run 	Any valid command-line

Examples

Here are a few examples, to see what some entries look like.

#Run command at 7:00am each weekday [mon-fri]
00 07 * * 1-5 mail_pager.script ‘Wake Up’

#Run command on 1st of each month, at 5:30pm
30 17 1 * * pay_rent.script

#Run command at 8:00am,10:00am and 2:00pm every day
00 8,10,14 * * * do_something.script

#Run command every 5 minutes during market hours
*/5 6-13 * * mon-fri get_stock_quote.script

#Run command every 3-hours while awake
0 7-23/3 * * * drink_water.script

Special Characters in Crontab

You can use an

asterisk

in any category to mean for every item, such as every day or every month.

You can use commas in any category to specify multiple values. For example: mon,wed,fri

You can use dashes to specify ranges. For example: mon-fri, or 9-17

You can use forward slash to specify a repeating range. For example: */5 for every five minutes, hours, days
Special Entries

There are several special entries, some which are just shortcuts, that you can use instead of specifying the full cron entry.

The most useful of these is probably @reboot which allows you to run a command each time the computer gets reboot. This could be useful if you want to start up a server or daemon under a particular user, or if you do not have access to the rc.d/init.d files.

Example Usage:

# restart freevo servers
@reboot freevo webserver start
@reboot freevo recordserver start

The complete list:

Entry Description Equivalent To
@reboot Run once, at startup. None
@yearly Run once a year 0 0 1 1 *
@annually (same as @yearly) 0 0 1 1 *
@monthly Run once a month 0 0 1 * *
@weekly Run once a week 0 0 * * 0
@daily Run once a day 0 0 * * *
@midnight (same as @daily) 0 0 * * *
@hourly Run once an hour 0 * * * *

Miscelleanous Issues

Script Output
If there is any output from your script or command it will be sent to that user’s e-mail account, on that box. Using the default mailer which must be setup properly.

You can set the variable MAILTO in the crontab to specify a separate e-mail address to use. For example:
MAILTO=”admin@mydomain.com”

Redirect Output to /dev/null
You can redirect the output from a cron script to /dev/null which just throws it away. By redirecting to /dev/null you will not receive anything from the script, even if it is throwing errors.
* * * * * /script/every_minute.pl > /dev/null 2>&1

Missed Schedule Time
Cron does not run a command if it was missed. Your computer must be running for cron to run the job at the time it is scheduled. For example, if you have a 1:00am scheduled job and your computer was off at that time, it will not run the missed job in the morning when you turn it on.

Related Links
[mkaz.com] At Command Mac OS X and eBay – at is similar to cron but for one time jobs, not reoccuring

Categories: Linux · Tips' n Tricks'

Gears@WordPress

July 3, 2008 · Leave a Comment

I have just installed this wordpress staff. Looks really cool to me… :)

Gears? It is a browser extension like Flash or QuickTime/Media Player. However Gears works with the browser to enhance web based applications. It can create local database and file storage, and run JavaScript in the background to update them without slowing down the browser.

Gears has been in the making for over a year and is well known among the web developers. Currently it supports Firefox versions 2 & 3 and Internet Explorer versions 6 & 7. Safari 3 support is coming soon.

On WordPress.com it is used to store all images and other web page components from the admin area to the user’s PC, speeding up access and reducing unnecessary web traffic.

The speed increase is most noticeable when Internet is slow or on high latency and makes everybody’s blogging experience more enjoyable.

The main thing is it really does the gear thing. It loads my wordpress pages faster then before. Hope people will enjoy..

To install click Gears

To know more about Gears visit code.google.

Categories: Fun · Tips' n Tricks'

cakephp : $ajax.observeField and Session lost

July 2, 2008 · 3 Comments

Finlay i made the solution in my style… :)
In my cakePHP project when ever i made any Ajax request to my system… my session was lost.. and the new requested controller and action take the place on my session variable. I was totally mad.. because it takes my localization action away… The thing is when ever i change my combo box.. it calls the ajax request and reset my language session value and if any one click on the language flag on that moment my page layout was lost and broke down… :(

Solutions:

1. Change the CAKE_SECURITY in app core.php to a level of medium or low
(don't worry it will not make any hole in the system and someone says that it can be the solution anyway..)
2. In app_controller set
var $components=array('RequestHandler');
3. Now, inside the beforeRender() method...add
$current_session_value = $this->Session->read('my_sess_var') ;
// this is the session which i want to have it
//What i did just check is ther any Ajax request has occurred.. so i use isAjax()
if ( $this->RequestHandler->isAjax() ) {
$this->Session->write('my_sess_var', null ); //i reset that session which was use to store
$this->Session->write('my_sess_var', $current_session_value ); // re-assign again
}

yahoo…. my problem is solved… no i can change my language whenever i want…

:)

Categories: PHP · Tips' n Tricks' · cakePHP