Skip to content

Instantly share code, notes, and snippets.

View ralphmoran's full-sized avatar
🎯
Working on something interesting

Ralph Moran ralphmoran

🎯
Working on something interesting
View GitHub Profile
@ralphmoran
ralphmoran / php-event-listener-example.php
Created February 3, 2021 21:02 — forked from im4aLL/php-event-listener-example.php
PHP event listener simple example
<?php
// Used in https://github.com/im4aLL/roolith-event
class Event {
private static $events = [];
public static function listen($name, $callback) {
self::$events[$name][] = $callback;
}
@ralphmoran
ralphmoran / GetContentCURL.php
Created October 3, 2019 18:30
Get file content using CURL. #curl
<?php
/**
* Returns file's content using CURL.
*
* @param string $url
* @return string
*/
function get_content_curl($url)
{
@ralphmoran
ralphmoran / WgetDownload.php
Last active October 3, 2019 17:46
WGet download. #wget
<?php
/**
* @author: unknown
*/
/**
* Simulates a "wget url" and do not buffer data in the memory in order
* to avoid thouse problems on large files.
*
@ralphmoran
ralphmoran / GetEmailThreads.php
Created October 2, 2019 10:23
Get email threads. #hackerrank #test #code
<?php
/**
* Returns (array) number of interactions between a sender and a receiver within their respective thread.
*
* @param array $emails
* @return array
*/
function getEmailThreads(array $emails)
{
@ralphmoran
ralphmoran / TimeConversion.php
Created September 29, 2019 21:13
Time conversion. #hackerrank #test #code
<?php
/**
* Given a time in -hour AM/PM format, convert it to military (24-hour) time.
*
* @param string $_12hourclock
* @return string
*/
function timeConversion(string $_12hourclock)
{
@ralphmoran
ralphmoran / BirthdayCakeCandles.php
Last active September 29, 2019 20:57
Birthday cake candles. #hanckerrank #test #code
<?php
/**
* It must return an integer representing the number of highest candles that can be blown.
*
* @param array $candles
* @return integer
*/
function birthdayCakeCandles(array $candles)
{
@ralphmoran
ralphmoran / MinMaxSum.php
Last active September 29, 2019 20:22
Min-max sum. #hackerrank #testcode
<?php
/**
* Given N positive integers, find the minimum and maximum values that can be
* calculated by summing exactly four of the five integers.
*
* @param array $numbers
* @return string
*/
function miniMaxSum(array $numbers)
@ralphmoran
ralphmoran / PlusMinus2.php
Created September 29, 2019 18:49
Plus minus 2. #hackerrank #test #code
<?php
/**
* Given an array of different values, calculate the fractions of its elements that are similar.
* Print the decimal value of each fraction on a new line.
*
* @param array $values
* @return string
*/
function plus_minus_2(array $groups)
@ralphmoran
ralphmoran / Staircase.php
Last active September 29, 2019 05:49
Staircase. #hackerrank #test #code
<?php
/**
* Observe that its base and height are both equal to 'n',
* and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.
*
* @param integer $size
* @return void
*/
function staircase(int $size)
@ralphmoran
ralphmoran / PlusMinus.php
Created September 29, 2019 02:42
Plus minus problem. #hackerrank #test #code
<?php
/**
* Given an array of integers, calculate the fractions of its elements that are positive,
* negative, and are zeros. Print the decimal value of each fraction on a new line.
*
* @param array $values
* @return string
*/
function plus_minus(array $values)