Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Category
Scripts
Resources Scripts Web Server

Using SSH and Unix commands

July 31, 2009 8 Comments

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.

Shell
1
2
Command: cd
Format: cd /directory/to/browse

The cp command will copy the file or folder from the source, to the destination.

Continue reading
Reading time: 2 min
Share:
Written by: rcastera
Resources Scripts

PHP – Convert Array to Object with stdClass

July 5, 2009 53 Comments

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.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

PHP – getting a list of currently loaded classes

June 25, 2009 1 Comment

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
1
2
3
4
<?php
    include_once("class.myClass.php");
    print_r(get_declared_classes());
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Add Magento search plugin to Firefox Search bar

June 24, 2009 2 Comments

I’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.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Javascript – Passing Multiple Parameters through setTimeout

June 21, 2009 13 Comments

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!

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
<script>
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);
}
</script>

Define your function to call with setTimeout:

JavaScript
1
2
3
4
5
<script>
function alertMe (message, name) {
    alert(message + name);
}
</script>

Now, just call the function.

JavaScript
1
2
3
var message = 'Hello, ';
var name = 'Richard';
setTimeout(alertMe, 2000, message, name);

Hope this helps someone! 🙂

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

How to define your own JavaScript class

June 7, 2009 8 Comments

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:

JavaScript
1
2
3
4
5
6
7
8
9
10
<script>
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:

JavaScript
1
2
3
4
<script>
Person.age = "29";
alert(Person.getASL());
<script>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

.htaccess – Limit website access by IP

May 31, 2009 4 Comments

I’ve been asked many times how to limit website access by allowable IP’s. This is fairly simple to accomplish with .htaccess and very useful for blocking web vagrants to allowing you to make updates to a website while redirecting all other IP’s to a maintenance page. Simply follow the steps below:

  1. Create a file and name it .htaccess.
  2. Add The following to the file:
    Apache
    1
    2
    3
    order deny,allow
    deny from all
    allow from 255.255.255.255
  3. Replace 255.255.255.255 with you IP address. (If you don’t know it, you can get it here: WhatsMyIP)
  4. Once the file is created, put it in the root directory. That’s it!
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Migrate WordPress to a new Server or Directory

May 26, 2009 9 Comments

If you decide to change the URL or link location of your WordPress Blog due to a new domain or moving to a sub-directory, here are some simple steps that should be done to ensure proper migration without breaking links.

To update WordPress options with the new blog location, use the following SQL command:

MySQL
1
2
3
4
5
6
7
8
SET @oldsite='http://www.olddomain.com';
SET @newsite='http://www.newdomain.com';
UPDATE wp_options SET option_value = REPLACE(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = REPLACE (post_content, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, @oldsite, @newsite);
UPDATE wp_comments SET comment_content = REPLACE (comment_content, @oldsite, @newsite);
UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, @oldsite, @newsite);
UPDATE wp_posts SET guid = REPLACE (guid, @oldsite, @newsite) WHERE post_type = 'attachment';
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Show blocks that are not loaded in the current Object or Template

May 25, 2009 1 Comment

Customizing Magento could be difficult. Here is an easy way to display any block in any template file that cannot be loaded with $this->getChildHtml().

PHP
1
<?php echo $this->getLayout()->getBlock('top.search')->toHtml() ?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Find which Class is loaded in the current Template

May 24, 2009 No Comments

If you’ve just started working with Magento, you’ll find that figuring out which class is loaded in the current template file very difficult. Here’s a little snippet that helps you figure it out. Just place the following into any .phtml template files:

PHP
1
<?php print_r(get_class_methods(get_class($this))); ?>

or

PHP
1
<?php print_r($this->debug()); ?>

or

PHP
1
<?php echo Zend_Debug::dump($this); ?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Page 5 of 9« First...«4567»...Last »

About me

Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.

Popular Posts

Magento – Display new products on the home page

May 20, 2009

How to Fix “Internet Explorer Cannot Open the Internet Site- Operation Aborted” Error

May 9, 2009

PHP – Convert Array to Object with stdClass

July 5, 2009

Categories

  • Home Automation
  • Resources
  • Scripts
  • SEO
  • Thoughts
  • Web Server

Tags

Apache Apple Bash CSS Drupal Free home automation htaccess Java Javascript Magento PHP raspberry pi SEO SQL thoughts Wordpress

© 2019 copyright Richard Castera // All rights reserved