Inject jQuery into a Webpage Through Chrome Javascript Console

include these lines of jQuery instantiation code in the javascript console

Exploring the DOM is much easier with jQuery. However, You may be working with a webpage that does not natively have jQuery installed.

That’s ok, the following lines of code will solve this. Just include these lines of jQuery instantiation code before you explore the DOM and now you can use jQuery!

Iterate an array with a promise in javascript

Example of how to iterate an array with a promise

It can be challenging to figure out how to iterate over an array of items with a promise.

The following code takes a callback function that may or may not be a promise already.

Once inside the PromiseForEach function, the callback will become a promise (if it isn’t already).

You also have the option of pushing the values onto an output array,  responseArray in the example below.

The response from the callback may be pushed directly onto the responseArray resulting in an array of promises that may be further manipulated, although at this point I am not sure why one would do that.

 

[solved] devtool reloads if application writes to a file

If you are developing a node js application using devtool, you may experience a rather frustrating situation whereby you application stops without any traceable errors followed by a subsequent reload of the devtool.

Why does devtool keep reloading when there are no errors?

There is a likelyhood that you are experiencing this issue as you are developing with fs (file system) and writing to appending to or streaming to a file.

For me, I was in the habit of using devtool with the –watch option. So accustomed to using this option was I that I did so mindlessly. The devtool –watch option performs the task of reloading the devtool whenever the development environment saves a file. Since the file my application was writing to existed within the development environment, the devtool with the –watch option was simply doing what it was designed to do.

Solution: Unwanted reloading of devtool when writing to a file

On solution to unwanted reloading of the devtool when working with the file system (fs) is simply not to use the –watch option with devtool.

Another solution is to write to a file that is outside the immediate development environment.

If you application has the requirement of writing to the file within the development environment, then you can change the location of the file until you have completed development and then move it back to where it is required.

I hope this note has saved you some time and frustration.

403 Error after adding a new website directory

On an ubuntu server it is common to host site files in a directory with a structure like ‘/var/www/example.com’.

One might wish to separating a subdomain out from site files in another directory. Something like ‘/var/dev/example.com’.

How to fix or prevent a 403 error after adding a new site directory

To prevent a 403 error, remember to edit the /etc/apache2/apache2.conf file to allow this directory to be accessed from the outside world.

The /etc/apache2/apache2.conf file has a ‘Require all granted’ directive for the normal /var/www directory that looks like this:

Make a copy of this directory for the new directory that are creating and add it to the /etc/apache2/apache2.conf file.
Once you have updated this file, remember to restart apache.

SECURE COPY (SCP): EXAMPLES OF HOW TO USE SECURE COPY

Examples of how to use Secure Copy (scp)

scp uses ssh for data file transfer between servers and provides the same level of security as ssh.

Secure copy the file “somefile.txt” from a remote host to your local host

 

Secure Copy your file “somefile.txt” from the local host to a remote host

 

Secure Copy the directory “localfoo” from your local host to a remote host’s directory “foobar”

 

Copy the file “foobar.dat” from remote host “remoteh1.com” to remote host “remoteh2.com”

 

Copying the files “foo.dat” and “bar.dat” from yor localhost to your home directory on the remote host

 

Copy the file “foobar.txt” from the local host to a remote host using port 2264

 

Copy multiple files from remote to your current directory on the local host

Or
 

Managing scp Performance

scp uses the Triple-DES cipher to encrypt the data being sent by default. By using Blowfish, as a cipher you may increase speed. Here is how.

If you have a slow connection you can use the -C option for compression to increase speed. If your connection is not slow, then this is not very helpful as it ads to the CPU burden.

 

PHP What is Opcode Cache and When to Use it

Are you wondering:

What is Opcode Cache and When to Use it?

I just read an excellent article entitled PHP Performance I: Everything You Need To Know About OpCode Caches published by Engine Yard. The article is a transcript of a video on PHP opcode cache, actually. Engine Yard goes into just enough detail, allowing one to really appreciate how it works.

What is OPCODE CACHE

OpCode Caches are an extension for PHP to enhance performance. By design, they inject themselves into the execution life-cycle and cache the results. This allows the compilation step to be skipped on subsequent cycles.

When to use OPCODE CACHE

According to the article, Opcode cache has almost no side-effects aside from using some extra memory for storing the cache. That stated, opcode cache should always be used in production environments

I recommend reading the article for a more indepth explanation. It’s a good read.

[SOLVED] ERROR mysqli_real_connect(): (HY000/2002): No such file or directory

If you are getting a wordpress error that starts with “mysqli_real_connect(): (HY000/2002):” and includes “No such file or directory” and ends with “wp-includes/wp-db.php on line 1490”, then here is what resolved the issue for me.

In the wp-config.php file, include (or change) this line from

define(‘DB_HOST’, ‘localhost’);

to

define(‘DB_HOST’, ‘127.0.0.1’);

I put it near the top. Hopefully this will help someone.

leave a comment : )

[SOLVED] How to Fix $.ajax() Not Working ie 8, ie 9 and ie 10

 

jQuery is an great tool to use for making ajax calls. As usual MS Internet Explorer has to make things that would otherwise be standard — difficult. Setting aside any rants about how much hair one can pull out in the days it takes to accomplish something that should have been easy, here is what works.

In order for $.ajax() to work with ie, there are certain things you must make sure are in place.

Internet Explorer, in all its wisdom, insists on caching, so it is important to prevent ie from caching when making a GET call to an API.

This can be done a number of ways shown below.

In the client side jQuery code

To prevent caching universally in your jQuery code use:

On a per call basis, use “cache: false,”  within the $.ajax() object as shown below.

In the $.ajax()  object

Be sure to specify    contentType: ‘application/json; charset=utf-8’,  within the $.ajax() object.
However, the dataType within the $.ajax() object, should remain as dataType: ‘json’,

Important Server Side configurations:

Be sure to set the response headers as follows:
“Access-Control-Allow-Origin”, “*”
“Access-Control-Allow-Headers”, “Origin, X-Requested-With, Content-Type, Accept”
‘Content-Type’, ‘text/plain’  <– this can be a gottcha for ie

Also, there is a workaround for the Cross-Domain AJAX for IE8 and IE9 mess.

If you are working with jQuery, install the script from the following git repo. It’s easy. Just include it and it works!  Be sure to install it after the jQuery script is called. You do not need to configure anything.
https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

Example  $.AJAX()  OBJECT that works with IE 8 – 11