Skip to content

Instantly share code, notes, and snippets.

View bernard-ng's full-sized avatar
🏘️
working from home

Bernard Ngandu bernard-ng

🏘️
working from home
View GitHub Profile
<?php
#....
protected array $listeners = [];
public function getState()
{
return $this->state;
}
public function subscribe(callable $listener)
<?php
$store->subscribe(function($state) {
print_r($state);
});
# Que diriez-vous d'un envoi :
# ...
public function dispatch(array $action)
{
<?php
class Store
{
protected array $state;
protected Closure $reducer;
protected array $listeners = [];
public function __construct( callable $reducer, array $initialState)
{
<?php
const INCREMENT_BY_ACTION = 'INCREMENT_BY';
function countReducer(array $state, $action) {
switch($action['type']) {
case INCREMENT_BY_ACTION;
$value = $action['value'] ?? 0;
return array_replace([], $state, ['count' => $state['count'] + $value]);
case INCREMENT_ACTION:
return array_replace([], $state, ['count' => $state['count'] + 1]);
rootReducer = combineReducers({potato: potatoReducer, tomato: tomatoReducer});
<?php
function combineReducers(array $reducers) {
return function(array $state, $action) use ($reducers) {
$newState = $state;
foreach($reducers as $stateKey => $reducer) {
if(!isset($newState[$stateKey])) {
$newState[$stateKey] = [];
}
$newState[$stateKey] = $reducer($newState[$stateKey], $action);
}
<?php
$initialState = [
'count' => [
'count' => 1
],
'sum' => 0
];
function sumReducer($state, $action) {
switch($action['type']) {
set -g status-justify left # Aligne les titres de fenetres a gauche
set -g status-bg colour1 # Status bar noir sur rouge
set -g status-fg colour0 #
set -g status-interval 2 # Evite des bug de refraichissement
setw -g window-status-current-fg colour1 # Inversion des couleur pour l'onglet selectione
setw -g window-status-current-bg colour0 #
set-option -g history-limit 10000 # Permet de scroller 10k lignes
set -g history-limit 10000 #
@bernard-ng
bernard-ng / deploy-ionic-angular.sh
Last active August 31, 2020 18:23
a script that deploys a angular or ionic app to a production server using git
BUILD_DEPLOY_DIRECTORY="$HOME/dev/projects/app-build"
BUILD_DEPLOY_REMOTE=$(git config --get remote.origin.url)
BUILD_DIRECTORY="$HOME/dev/projects/app/www" # www or build
BUILD_COMMIT_MESSAGE=$(date +'%c')
R=$(tput setaf 1)
G=$(tput setaf 2)
Y=$(tput setaf 3)
NC=$(tput sgr0)
@bernard-ng
bernard-ng / .htaccess
Last active August 1, 2020 11:15
angular - ionic .htaccess
<IfModule mod_rewrite.c >
RewriteEngine on
RewriteOptions inherit
# let's encrypt ssl
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/.+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^.well-known/acme-challenge - [L]
# redirect to no-www