How to Benchmark Your Javascript?

This is a quick tutorial on how to benchmark your javascript with console.time(“arg”) and console.timeEnd(“arg”)
You would use developer tools to see how fast your script runs.
javascript_benchmark

Example Code:

Array.prototype.proto1 = function(){};
Array.prototype.proto2 = function(){};
Array.prototype.proto3 = function(){};
Array.prototype.proto4 = function(){};
Array.prototype.proto5 = function(){};

var objectLateral = {
  arrayBank: ['Some random string', 'Other String', 'More Stringy Spaghetti']
};

function runThisCode(){
  var things = objectLateral.arrayBank,
      list = "";
	console.time("time");  

  for(var i = 0, ff = things.length; i < ff; i++){
    list += (things[i] + " ");
  }

  console.timeEnd("time");
  return list.trim();
}

runThisCode();

Returning Functions and Immediate Invocation

// ride and wait time
var parkRides = [["birch bumpers", 40], ["dank bumpers", 36], ["trap bumpers", 41], ["wtf bumpers", 43],];
// fast pass for faster line
var fastPassQueue = ["birch bumpers", "dank bumpers", "trap bumpers", "wtf bumpers"];
// allRides arg - this parameter will be the array of the rides and their wait time
// passrides arg - this will be the array of the nxt available fast pass rides
// pick arg - this will be the actual ride for which our customer would like a ticket!
function buildTicket(allRides, passRides, pick) {
	if(passRides[0] == pick){
		var pass = passRides.shift();
		return function() {alert("Quick! You've got a fast pass to " + pass +"!"); 
	};
	} else {
		for(var i =0; i<allRides.length;i++){
			if(allRides[i][0]==pick){
				return function () {alert("A ticket is print for " + pick +"!\n" + "Your wait time is about " + allRides[i][1] + " minutes.");
				};
			}
		}
	}
}
var wantsRide = "birch bumpers";
// self invoking function when you add () at the end off the function
buildTicket(parkRides, fastPassQueue, wantsRide)();

 

This is hypothetical fast pass system created with functions, arrays, conditional, and for loop statement. All written javascript.

jQuery – $.each vs $.map jquery

We are going to go over what are the difference between $.each and $.map in jquery. Both are like foreach loops, but utilized differently.

The each method is meant to be an immutable iterator, where as the map method can be used as an iterator, but is really meant to manipulate the supplied array and return a new array.

Another important thing to note is that the each function returns the original array while the mapfunction returns a new array. If you overuse the return value of the map function you can potentially waste a lot of memory.

<script>
    var cities = ['Paris', 'London', 'Orlando'];
    
    $.each(cities, function(index, city){
        var result = city + " " + index;
        console.log(result);
    });
    // paris 0
    // london 1
    // orlando 2

    $.map(cities, function(city, index){
        var result = city + " " + index;
        console.log(result);
        return result;
    });
    // paris 0
    // london 1
    // orlando 2

</script>

This is Example Code of php Inheritance

This is example code of php inheritance parents and child. extend is the keyword to inherit from the parent class.

 

<?php 

abstract class Shape {

	protected $color;

	public function __construct($color = 'blue')
	{
		$this->color = $color;
	}

	public function getColor()
	{
		return $this->color;
	}

	abstract protected function getArea();
	
}

class Square extends Shape {
	
	protected $length = 4;

	public function getArea()
	{
		return pow($this->length, 2);
	}
}

class Triangle extends Shape {

	protected $base = 4;

	protected $height = 7;

	public function getArea()
	{
		return .5 * $this->base * $this->height;
	}
}

class Circle extends Shape {

	protected $radius = 5;

	public function getArea()
	{
		return M_PI * pow($this->radius, 2);
	}
}

// long hand methods
// $circle = new Circle;

// echo $circle->getArea();

//shorthand
echo (new Circle)->getArea();

How to Setup a squid3 proxy with username and password

This is a tutorial on how to set up a username and password on your squid 3 proxy for ubuntu.

How this proxy useful. It’s to tunnel all the though to your network to usa for example skype or anything in your native country while your in foreign country. Plus you can visit american websites with the ip ranges here.

Squid uses

Cache — The SQUID Proxy Server can Cache web files from all eb Requests and then transefer those chaced files locally if another host requests the same file
ACL Control — Access Control Lists allow you to specify whether certain websites can be accessed.
Bypass Web filters — You can connect to a Proxy Server on a different network to bypass Web Filers on your LAN

Squid Configuration Setup on Server Setup (Note: These steps are shown using Ubuntu 14.04 Server Edition. The basic steps are the same on all Linux distributions, but the actual commands may be slightly different. Please just use Google to find the correct commands if these do not work for you.):
To Install SQUID:

sudo apt-get install squid

To edit SQUID Configuration File:

sudo nano /etc/squid3/squid.conf

To Allow Access to the SQUID Server from Hosts Change:

http_access deny all

http_access allow all

Restart SQUID Service after any configuration changes: sudo service squid3 restart

To Configure Internet Explorer (Note: Proxy Server Configurations are set within Internet Explorer for the Entire System. Even if you use Chrome you still need to change the settings in IE) :
Open Internet Explorer and Go to Tools
Select Internet Options
Select Connections Tab
Click LAN Settings Button
Type in username and password if there is one.
Select Checkbox under Proxy Server Settings and enter the Proxy Servers IP Address, and the port number SQUID is using. (The port number default is 3128)
Click OK

Basic squid conf

sudo nano /etc/squid3/squid.conf instead of the super bloated default config file

auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_port 3128 # or whatever you like

Please note the basic_ncsa_auth program instead of the old ncsa_auth

Setting up a user

sudo htdigest -c /etc/squid3/passwords realm_you_like username_you_like

and enter a password twice for the chosen username then

sudo service squid3 restart

Super Mario World – Game

[supermarioworld]

 

A – Jump
S – Fireball

Arrow Keys to Move

Disclaimer:
I do not own mario, mario is copyrighted by nintendo. This is only for educational and for fun purposes only. This game is not hosted by me. This is just iframe. It is hosted by critic.net.