Skip to content

Instantly share code, notes, and snippets.

View wajdijurry's full-sized avatar

Wajdi Jurry wajdijurry

View GitHub Profile
@wajdijurry
wajdijurry / rabbit_rbc.js
Created May 14, 2021 12:21
Connect to RabbitMQ in NodeJS using Promise (RPC model)
var amqp = require('amqplib');
var config = require('../config/config');
function generateUuid() {
return Math.random().toString() +
Math.random().toString() +
Math.random().toString();
}
const connect = (url) => {
@wajdijurry
wajdijurry / binary_search.php
Created January 3, 2020 14:32
Find a number within an array in recursive mode
<?php
/**
* Find a number within an array in recursive mode
*/
function findNumber($a, $num, $start, $end) {
$mid = floor(($end - $start) / 2) + $start;
if ($num > $a[$end] || $num < $a[0] || $start > $end) {
return "number does not exist";
}
if ($a[$mid] == $num) {
@wajdijurry
wajdijurry / fibonacci-series.php
Created December 28, 2019 12:57
Fibonacci series in two ways: Recursive and for loop
<?php
/**
* Fibonacci series as simple for loop
*/
function fibonacciLoop($n) {
$series = [0, 1];
if ($n == 0 || $n == 1) {
return $n;
}
for ($i=2; $i<=$n; $i++) {
@wajdijurry
wajdijurry / ArrayHelper.php
Last active November 17, 2018 11:23
Convert one-dimensional array to tree (parent -> children)
<?php
/**
* Author:Wajdi Jurry <jurrywajdi@yahoo.com> (https://github.com/wajdijurry)
* Requires PHP >= 5
*/
class ArrayHelper
{
private $parentIdAttribute;
private $itemIdAttribute;
@wajdijurry
wajdijurry / ArrayManipulation.php
Last active July 6, 2021 15:21
Adding item to array or change existent item position after shifting elements up or down depending on available positions
<?php
/**
* Author:Wajdi Jurry <jurrywajdi@yahoo.com> (https://github.com/wajdijurry)
* Gist: https://gist.github.com/wajdijurry/a00752123134342ccc9d13a480c9f013
*/
class ArrayManipulation
{
private $array;
public function __construct(array $array)