Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Tag
javascript
Scripts

Create custom named events in Backbone.js

February 23, 2012 No Comments

In Backbone, Events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. Events do not have to be declared before they are bound, and may take passed arguments. For example:

JavaScript
1
2
3
4
5
6
7
8
9
10
11
<script>
var person = {};
_.extend(person, Backbone.Events);
person.on("scream", function(msg) {
  alert("I am " + msg);
});
person.trigger("scream", "screaming");
</script>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Scripts

Get your Twitter follower count with jQuery

October 13, 2011 No Comments
JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
$(function(){
    $.ajax({
        url: 'http://api.twitter.com/1/users/show.json',
        data: {screen_name: 'rcastera'},
        dataType: 'jsonp',
        success: function(data) {
            console.log(data.followers_count);
        }
    });
});
</script>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Google Analytics – How to manually Track Clicks on Outbound Links

May 20, 2010 6 Comments

You can use Google Analytics to track clicks on links that lead away from your site. Because links that lead away from your site are not automatically tracked, you will need to manually tag all outbound links you want to track. To do this, you’ll add some JavaScript customizations to your page and to the links you want to track.

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

Prototype JS – Determine if an object exists in the page loaded

February 23, 2010 No Comments

I’m so use to using jQuery that I usually don’t have to look up documentation on how to use certain functions. They almost come naturally because it’s so English-like! Unfortunately Magento uses Prototype as it’s native choice of Javascript Frameworks. I sure wish they would have chosenjQuery! I think they would have more people jumping on their platform. I’m sure they have a good choice for it. Anyway, here’s how to check:

JavaScript
1
2
3
if ($('id_of_element') != undefined) {
    alert('Object exists.');
}
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

J-Crop – the jQuery image cropping plugin

May 10, 2009 No Comments

Jcrop is the quick and easy way to add image cropping functionality to your web application. It combines the ease-of-use of a typical jQuery plugin with a powerful cross-platform DHTML cropping engine that is faithful to familiar desktop graphics applications.

Feature Overview

  • Attaches unobtrusively to any image
  • Supports aspect ratio locking
  • Supports minSize/maxSize setting
  • Callbacks for selection done, or while moving
  • Keyboard support for nudging selection
  • API features to create interactivity, including animation
  • Support for CSS styling
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

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

May 9, 2009 91 Comments

This error shows up when the page loads (or tries to load). There are many scenarios that can cause this error which occurs in IE. Microsoft has even issued a patch for solving it.

This error is being caused by calling a piece of Javascript within a page (after the tag). Adding the defer=”defer” tag to the script quickly resolves the issue.

JavaScript
1
<script defer="defer" type="text/javascript" src="src goes here">/*code goes here*/</script>

Hope this helps someone! 🙂

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

MooTools – Free Syntax Highlighting Class

May 5, 2009 3 Comments

Lighter.js is a free syntax highlighting class developed with MooTools. It was created with the MooTools developer in mind and takes advantage of many of the Framework’s features. Using it can be as simple as adding a single script to your web page, selecting the elements you wish to highlight, and Lighter.js takes care of the rest.

All browsers supported by MooTools are compatible with Lighter.js. It’s possible that it may work with earlier/other browsers but these are unofficially supported. The official list is:

  • Safari 2+
  • Internet Explorer 6+
  • Firefox 2+
  • Opera 9+
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Get the filename from upload form using Javascript

August 8, 2008 11 Comments

I needed a way to access the filename of a file being uploaded or attached using the input file from a form. So, I created a nice little function to achieve this. Hopefully it comes in handy for someone.

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
<script>
function getNameFromPath(strFilepath) {
    var objRE = new RegExp(/([^\/\\]+)$/);
    var strName = objRE.exec(strFilepath);
    if (strName == null) {
        return null;
    }
    else {
        return strName[0];
    }
}
</script>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Page 1 of 212»

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