Skip to content

Instantly share code, notes, and snippets.

View calina-c's full-sized avatar

Călina Cenan calina-c

  • Kaolin Technologies
  • Cluj-Napoca, Romania
View GitHub Profile
@calina-c
calina-c / if-inversion-example.php
Created October 19, 2016 07:02
Exemplified IF inversion technique for better readability
<?php
function validateApplicationTangled($user) {
if($user->age>18) {
if(($user->hasPreviousApplication && !$user->previousApplicationApproved) || !$user->hasPreviousApplication) {
printf("Cool, application approved for user %s\n", $user->name);
return true;
} else {
printf("Sorry, but the user %s has a previously approved application\n", $user->name);
return false;
}
@calina-c
calina-c / if-inversion-tangled-function.php
Last active October 19, 2016 07:11
Part of IF inversion examples, contains only the tangled version of the function
<?php
function validateApplicationTangled($user) {
if($user->age>18) {
if(($user->hasPreviousApplication && !$user->previousApplicationApproved) || !$user->hasPreviousApplication) {
printf("Cool, application approved for user %s\n", $user->name);
return true;
} else {
printf("Sorry, but the user %s has a previously approved application\n", $user->name);
return false;
}
@calina-c
calina-c / if-inversion-untangled-function.php
Created October 19, 2016 07:13
Part of IF inversion examples, contains only the untangled version of the function
<?php
function validateApplicationUntangled($user) {
if($user->age<18) {
printf("Sorry, but the user %s is under 18\n", $user->name);
return false;
}
if($user->hasPreviousApplication && $user->previousApplicationApproved) {
printf("Sorry, but the user %s has a previously approved application\n", $user->name);
return false;
return sprintf(
“The user %s %s has a balance of $%f.”,
$firstName,
$lastName,
$balance
);
return "The user " . $firstName . " has a balance of $" . $balance . ".";
return sprintf("%0.3f",$number);
return number_format($number, 3, '.', '');
return 'The number is ' + str(2) + '.'
return 'The number is %s.' % 2
return $id ? "The item was updated." : "The item was created";
########
$action = $id ? "updated" : "created";
return sprintf("The item was %s.", $action).
class FizzRule:
def matchesRule(self, number):
return not (number % 3);
def getReplacement(self):
return "Fizz";
class BuzzRule:
def matchesRule(self, number):
return not (number % 5);
class Rule:
def matchesRule(self, number):
pass
def getReplacement(self):
pass
class FizzRule:
def matchesRule(self, number):
return not (number % 3);
<?php
namespace App\Forms;
use Kris\LaravelFormBuilder\Form;
use Yaml;
use Carbon\Carbon;
use App\Forms\Report\FormConfig;
use App\Forms\Entities\EntityFormConfig;
use App\Services\ReportServices\ReportStringProcessingTrait;