Skip to content

Instantly share code, notes, and snippets.

View cherifGsoul's full-sized avatar
🎯
Focusing

Cherif Bouchelaghem cherifGsoul

🎯
Focusing
View GitHub Profile
@cherifGsoul
cherifGsoul / fp-lingo.md
Created May 3, 2018 07:13 — forked from ericelliott/fp-lingo.md
A Guide to Functional Programming Lingo for JavaScripters

A Guide to Functional Programming Lingo for JavaScripters

Functional programming gets a bad wrap about being too hard for mere mortals to comprehend. This is nonsense. The concepts are actually quite simple to grasp.

The jargon is the hardest part. A lot of that vocabulary comes from a specialized field of mathematical study called category theory (with a liberal sprinkling of type theory and abstract algebra). This sounds a lot scarier than it is. You can do this!

All examples using ES6 syntax. wrap (foo) => bar means:

function wrap (foo) {
@cherifGsoul
cherifGsoul / js-observables-binding.md
Created April 7, 2018 23:51 — forked from austinhyde/js-observables-binding.md
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

@cherifGsoul
cherifGsoul / EmailAddress.php
Last active March 1, 2018 13:41
Value Object implementation pattern
<?php
class EmailAddress
{
/**
* Undocumented variable
*
* @var [type]
*/
private $address;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>object creation</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@cherifGsoul
cherifGsoul / README.md
Created December 9, 2017 07:57 — forked from rrag/README.md
Yet another tutorial and Cheat sheet to Functional programming

There are many tutorials and articles available online which explain functional programming. Examples show small functions, which are composed into others which again get composed. It is hard to imagine how it would all work, then come the analogies and then the math. While the math is necessary to understand it can be difficult to grasp initially. The analogies on the other hand, (at least for me) are not relatable. Some articles assume the reader knows the different terminologies of FP. Over all I felt it is not inviting to learn.

This introduction is for those who have had a tough time understanding those analogies, taken the plunge to functional programming but still have not been able to swim. This is yet another tutorial on functional programming

Terminology

Functions as first class citizens

Functions are first class means they are just like anyone else, or rather they are not special, they behave the same as say primitives or strings or objects.

@cherifGsoul
cherifGsoul / email-address.js
Last active November 26, 2017 10:24
Simple example for email Address value object
var address;
var setAddress = function(address) {
/**
* @todo add validation here
*/
address = address;
};
function EmailAddress(anAddress) {
@cherifGsoul
cherifGsoul / TodoActiveRepository.php
Last active October 12, 2017 22:22
Quick example of repository pattern using Yii2 active record
<?php
namespace Todolist\Infrastructure\Persistence\Yii\Respository;
use Todolist\Domain\Model\Todo\Todo;
use Todolist\Domain\Model\Todo\TodoRepository;
use Todolist\Infrastructure\Persistence\Yii\Record\TodoRecord;
class TodoActiveRepository implements TodoRepository
{
public function forId(TodoId $id)
@cherifGsoul
cherifGsoul / slugify.js
Created July 28, 2017 11:54 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@cherifGsoul
cherifGsoul / bdd_cucumber-js.md
Created July 16, 2017 01:03 — forked from steckel/bdd_cucumber-js.md
Workflow: Behavior Driven Development/Design for Front End Development (JavaScript)

Beyond any other definition, Behavior Driven Development/Design ("BDD") is a philosophy.

What is "BDD"?

"BDD" is a set of tools and techniques that exist to support one idea: good software is written to meet the needs of the stakeholders (typically clients).

These stakeholders know their business better than the people designing the software. It is the responsibility of developers to capture the business requirements and translate them into software.

BDD tools facilitate this as a process by letting developers author features first, which capture requirements in a domain-specific language. Code is developed by working on these high-level features, and then on code specifications.

@cherifGsoul
cherifGsoul / DDD, CQRS & ES.md
Created February 25, 2017 19:27 — forked from rasheedamir/DDD, CQRS & ES.md
DDD, CQRS & ES!

To implement command processing we need the following pieces:

  • Commands which request that something should happen, i.e. some state change
  • Events which indicate that something has happened
  • Aggregates that handles Commands and generates Events based on the current state
  • Event store which stores all events that has happened
  • Application services that receives Commands and routes it to the appropriate aggregate

https://github.com/rasheedamir/event-sourcing-in-practice