Skip to content

Instantly share code, notes, and snippets.

View adrianosferreira's full-sized avatar
⚒️

Adriano Ferreira adrianosferreira

⚒️
View GitHub Profile
@adrianosferreira
adrianosferreira / BreadthFirstSearch.php
Created November 9, 2019 18:44
Traversing a Graph through Breadth First Search in PHP
<?php
/**
* Created by PhpStorm.
* User: adriano
* Date: 09/11/19
* Time: 13:18
*/
class Node {
@adrianosferreira
adrianosferreira / BreadthFirstSearch.php
Created November 9, 2019 18:44
Traversing a Graph through Breadth First Search in PHP
<?php
/**
* Created by PhpStorm.
* User: adriano
* Date: 09/11/19
* Time: 13:18
*/
class Node {
@adrianosferreira
adrianosferreira / DepthFirstSearch.php
Last active November 9, 2019 18:33
Traversing a Graph using depth first search in PHP
<?php
/**
* Created by PhpStorm.
* User: adriano
* Date: 09/11/19
* Time: 13:18
*/
class Node {
@adrianosferreira
adrianosferreira / shortestDistance.php
Last active November 9, 2019 16:16
Shortest Distance Algorithm with PHP - Dijkstra’s Shortest Path Algorithm
<?php
/**
* Created by PhpStorm.
* User: adriano
* Date: 08/11/19
* Time: 14:30
*/
class Edge {
function isProperSubTree( b1, b2, found = false ) {
if ( found ) {
return found;
}
if( b2.value === b1.value && b2.left === b1.left && b2.right === b1.right ) {
found = true;
}
if(typeof b1.right === 'object') {
function BST( value ) {
this.left = null;
this.right = null;
this.value = value;
}
BST.prototype.insertNode = function( value ) {
if ( value < this.value ) {
if ( !this.left ) {
this.left = new BST( value );
function LinkedList() {
this.head = null;
this.tail = null;
}
function Node( prev, next, value ) {
this.prev = prev;
this.next = next;
this.value = value;
}
<?php
/**
* This code retrieves course data from an external API and displays it in the user's
* My Account area. A merchant has noticed that there's a delay when loading the page.
* 1) What changes would you suggest to reduce or remove that delay?
* 2) Is there any other code changes that you would make?
*/
public function add_my_courses_section() {
$api_user_id = get_user_meta( get_current_user_id(), '_external_api_user_id', true );
var request = require('request');
var async = require('async');
var q = async.queue(function(task, callback){
request('http://site.com/?page=' + task.index, function( err, res, body ) {
console.log('Finalizado ' + i);
callback();
});
}, 1);
var request = require('request');
var theRequest = function(i){
request('http://site.com/?page=' + i, function( err, res, body ) {
console.log('Finalizado ' + i);
});
}
for (var i = 0; i <= 1000; i++) {
theRequest(i);