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 / installvagrant
Created October 15, 2018 09:48 — forked from rrgrs/installvagrant
installs brew, virtualbox, and vagrant in osx
if ! type "brew" > /dev/null; then
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)";
fi
brew tap phinze/homebrew-cask && brew install brew-cask;
brew cask install vagrant;
brew cask install virtualbox;
@cherifGsoul
cherifGsoul / can-util-replacements.md
Last active July 6, 2018 17:46
can-util replacements

can-util for can namespace

replaced by can-namespace

can-util/js/each/each

  • when looping on objects replaced by can-reflect.eachKey
  • when looping on lists/arrays replaced by can-reflect.each
  • can-reflect.eachKey has better performance

can-util/js/is-promise/is-promise

replaced by can-reflect.isPromise

@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
}