Skip to content

Instantly share code, notes, and snippets.

View devmsh's full-sized avatar
👨‍💻
Available for new projects

Mohammed S Shurrab devmsh

👨‍💻
Available for new projects
View GitHub Profile
<?php
function __autoload($class) {
require $class . '.php';
}
@devmsh
devmsh / Graph API Subclass Generator
Created May 20, 2015 10:28
Generate the Graph API Subclass src, test, and docs!
<?php
function to_camel_case($str, $capitalise_first_char = false) {
if($capitalise_first_char) {
$str[0] = strtoupper($str[0]);
}
$func = create_function('$c', 'return strtoupper($c[1]);');
return preg_replace_callback('/_([a-z])/', $func, $str);
}
@devmsh
devmsh / MagicUser.php
Last active September 6, 2016 10:44
PHP Magical Setter and Getter
<?php
// once you add the magical setter and getter
// you can can access any private fields as usual
// but you can also develop custom setter and getter if you want
$user = new MagicUser();
$user->username = "test";
$user->password = "pass";
echo $user->username; // will print Test not test.
@devmsh
devmsh / check_auth_without_middleware.php
Last active May 4, 2017 11:24
check auth without middleware
<?php
class CustomerController extends Controller{
public function __construct()
{
if(!$this->session->get('user_id')){
$this->redirect("/login");
}
}
}
<?php
/**
* Group cart items by category, and calculate the total of each category ;)
**/
$cart = [
[ "name" => "product A", "price" => 15, "qty" => 5, "category" => "category 1"],
[ "name" => "product B", "price" => 20, "qty" => 4, "category" => "category 2"],
[ "name" => "product C", "price" => 30, "qty" => 2, "category" => "category 1"],
@devmsh
devmsh / array_assoc.php
Created June 15, 2017 11:50
array_assoc
<?php
/**
* Go from $scores to $result without using any loops!
*/
$scores = [
["player_id" => 3, "name" => "player #1", "score" => 150, "bonus" => 200],
["player_id" => 4, "name" => "player #2", "score" => 120, "bonus" => 100],
];
<?php
$user = [
"workHours" => [
["from" => "08:00:00", "to" => "16:00:00"],
[],
["from" => "08:00:00", "to" => "16:00:00"],
[],
["from" => "08:00:00", "to" => "16:00:00"],
[],
<?php
require_once 'vendor/autoload.php';
const FREE_TIME = 1;
$user = [
"workHours" => [
["from" => "08:00:00", "to" => "16:00:00"],
[],
@devmsh
devmsh / freeat.php
Last active June 18, 2017 12:39
FreeAt challenge solution using Intervals
<?php
use \Achse\Math\Interval\Utils\StringParser\IntegerIntervalStringParser as Parser;
require_once 'vendor/autoload.php';
const FREE_TIME = "01:00:00";
$user = [
"workHours" => [
@devmsh
devmsh / simpleioc.php
Created June 18, 2017 17:42
simple IoC challenge
<?php
class B
{
}
class A
{
private $b;