Richard Castera

Application Developer/Designer
  • Home
  • About
  • Projects
Apache, Web Resources | 7 Comments | August 1, 2009

Using SSH and Unix commands

Having some basic knowledge of SSH and Unix commands is very useful. Developed in 1995, SSH (Secure Shell) was created as a secure alternative to Telnet. Telnet is a protocol allowing for command line access to a Unix, Linux or FreeBSD based remote computer. I’ve listed some basic commands to get you familiar with them.

The cd command is used to move to a specific directory.
Command: cd
Format: cd /directory/to/browse
The cp command will copy the file or folder from the source, to the destination.
Command: cp
Format: cp /directory/source /directory/destination
mkdir creates a directory.
Command: mkdir
Format: mkdir /directory_to_create
The rmdir command deletes a directory.
Command: rmdir
Format: rmdir /directory/to/delete
The rm command deletes a file.
Command: rm -f
Format: rm -f filename
The mv command will rename or move a file stated in the first portion to the name or location stated in the second portion.
Command: mv
Format: mv /directory/you/want/to/rename/or/move /new/directory/name/or/location
This command will tar zip the files in the directory specified in the second portion into a tar file specified in the first portion.
Command: tar cvf
Format: tar cvf filename.tar.gz /directory/you/wish/to/archive
The tar -xvf will extract all files from the tarball specified into the directory you are currently in.
Command: tar -xvf
Format: tar -xvf filename.tar.gz
This will create a zip file, with the name specified in the first portion from the file or directory listed in the second portion.
Command: zip
Format: zip filename.zip /file/or/folder/you/want/to/zip
This command will unzip or un pack the named zip file, into the directory you’re currently in.
Command: unzip
Format: unzip filename.zip
The Ls command lists files, and folders within the directory you specify
Command: ls
Format: ls /directory/you/wish/to/list/files/
This will add a forward slash to the directory names within the directory you specify
Command: ls -f
Format: ls -f /directory/you/wish/to/list/files/
This will show “hidden” files in the directory you specify
Command: ls -a
Format: ls -a /directory/you/wish/to/list/files/
This command shows detailed info about each file in the directory you specify.
Command: ls -l
Format: ls -l /directory/you/wish/to/list/files/

Also, a lightweight, freeware application which supports SSH commands that I use is, PuTTY.

PHP, Web Resources | 29 Comments | July 6, 2009

PHP – Convert Array to Object with stdClass

The PHP stdClass() is something that isn’t well documented but i will try to shed some light into the matter. stdClass is a default PHP object which has no predefined members. The name stdClass is used internally by Zend and is reserved. So that means that you cannot define a class named stdClass in your PHP code.

It can be used to manually instantiate generic objects which you can then set member variables for, this is useful for passing objects to other functions or methods which expect to take an object as an argument. An even more likely usage is casting an array to an object which takes each value in the array and adds it as a member variable with the name based on the key in the array.

Here’s an example below that converts an array to an object below. This method is called Type Casting.

<?php
$person = array (
   'firstname' => 'Richard',
   'lastname' => 'Castera'
);
$p = (object) $person;
echo $p->firstname; // Will print 'Richard'
?>

Here’s an example below that converts a multi-dimensional array to an object. This is accomplished through recursion.

<?php
function arrayToObject($array) {
	if(!is_array($array)) {
		return $array;
	}
	$object = new stdClass();
	if (is_array($array) && count($array) > 0) {
	  foreach ($array as $name=>$value) {
	     $name = strtolower(trim($name));
	     if (!empty($name)) {
	        $object->$name = arrayToObject($value);
	     }
	  }
      return $object;
	}
    else {
      return FALSE;
    }
}
?>
<?php
$person = array (
   'first' => array('name' => 'Richard')
);
$p = arrayToObject($person);
?>
<?php
// Now you can use $p like this:
echo $p->first->name; // Will print 'Richard'
?>
Magento, PHP, Web Resources | 12 Comments | June 30, 2009

Migrating Magento to another server

Migrating the Magento platform to another server is relatively a simple task. I have detailed the steps below:

  1. From the admin, go to Configuration -> Web -> and change the (Unsecure and Secure) fields to {{base_url}}.
  2. From the admin, go to System -> Tools -> Backups and click on the backup button. This will create a backup of your database.
  3. Make a copy your Magento root.
  4. Move all data over to the new server.
  5. Restore the database on the new host.
  6. If you have a different username, password or database name. You’ll need to update that as well. You can find the file in (‘magento_root/app/etc/local.xml’) and make the required changes.
  7. Navigate to your Magento root, and delete all of the files and folders in, (i.e. /var/www/magento/var) except for the .htaccess file.

Hope this helps someone :)

PHP | No Comments | June 26, 2009

PHP – getting a list of currently loaded classes

In some cases you may need to investigate which classes are loaded in the current scope. You can do it pretty fine with the get_declared_classes() function. This function will return an array of currently available classes.

<?php
    include_once("class.myClass.php");
    print_r(get_declared_classes());
?>
Magento, PHP, Web Resources | 2 Comments | June 25, 2009

Add Magento search plugin to Firefox Search bar

magentoI’ve been working with Magento for some time now. I found myself searching for help countless times on the Magento website. I thought it would be useful to have a search feature built right into Firefox’s list of search engines to search the Magento site. So I went through Mozilla’s Developer Center and found instructions on the Open Search Syntax. So here you go, you can download it here. Hope you find it helpful!

I also have one for PHP which comes in handy as well. If your interested, you can grab it here.

Javascript, My Thoughts, Web Resources | 8 Comments | June 22, 2009

Javascript – Passing Multiple Parameters through setTimeout

One of the problems that I’ve faced with Javascript is passing multiple parameters through the setTimeout function. I found this little snippet on the internet a few months ago and would like to share it with you. I don’t know who the original author is so I could not give him/her proper credit. Thanks!

var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) {
	if(typeof fRef == "function") {
		var argu = Array.prototype.slice.call(arguments,2);
		var f = (function(){ fRef.apply(null, argu); });
		return _st(f, mDelay);
	}
	return _st(fRef,mDelay);
}

Define your function to call with setTimeout:

function alertMe(message, name) {
    alert(message + name);
}

Now, just call the function.

var message = 'Hello, ';
var name = 'Richard';
setTimeout(alertMe, 2000, message, name);

Hope this helps someone! :)

Javascript, Web Resources | 7 Comments | June 8, 2009

How to define your own JavaScript class

There are several ways to define a class in Javascript. I will be listing my favorite method below (JSON Method). It’s important to note that there are no real classes in JavaScript. Everything is considered an object. So below is our class definition:

<script type="text/javascript">
var Person = {
    age: "25",
    sex: "Male",
    location: "New York",
    getASL: function () {
        return 'Age: ' + this.age + ', Sex: ' + this.sex + ', Location: ' + this.location;
    }
};
</script>

So you can start using the class like this:

<script type="text/javascript">
Person.age = "29";
alert(Person.getASL());
</script>
  • Page 6 of 14
  • <
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • ...
  • 14
  • >
  • Premium Email Templates

    Social Profiles

  • Twitter
  • Facebook
  • LinkedIn
  • Digg
  • Google
  • GitHub

    Last Tweet

  • Beware the heat-seeking Nerf machine-gun coming to a cubicle near you http://om.ly/svHF #fb
  • Follow me
  • Archives

    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • September 2008
    • August 2008
    • July 2008
    • June 2008
  • Categories

    • AJAX
    • Apache
    • Books
    • Drupal
    • Ecommerce
    • Flash
    • Google
    • Javascript
    • jQuery
    • Magento
    • Marketing
    • Mootools
    • My Thoughts
    • MySQL
    • News
    • Photoshop
    • PHP
    • Prototype
    • SEO
    • Web Resources
    • Wordpress
  • My Favorites

    • 37 Signals
    • Andrew Warner
    • Chris Coyier
    • Chris Shiflett
    • Collis Ta'eed
    • Development Seed
    • Drupal
    • HubSpot
    • James Padolsey
    • Joel On Software
    • John Resig
    • jQuery
    • Kevin Rose
    • Life Hacker
    • Magento
    • Mashable
    • Matt Cutts
    • Matt Ryan
    • MySQL
    • NetTuts
    • Noupe
    • Photoshop Tutorials
    • PHP
    • Smashing Magazine
    • Tech Crunch
    • WoorkUp
    • Wordpress

2010 © Copyright. Richard Castera - All Rights Reserved.

Top