Skip to content

Instantly share code, notes, and snippets.

View .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /webapi/index.php?route=$1 [L,QSA]
@aminnairi
aminnairi / partial.mjs
Created Feb 4, 2022
Partial Application
View partial.mjs
const partial = (callback, ...initialArguments) => {
return (...additionalArguments) => {
const allArguments = [...initialArguments, ...additionalArguments];
if (allArguments.length >= callback.length) {
return callback(...allArguments);
}
return partial(callback, ...allArguments);
};
View index.mjs
// For these excercises :
// - Only use recursion (or direct recursion)
// - Array.prototype methods are prohibited
// - for, while & do while loops are prohibited
// - Array.prototype.length is accepted
/**
* @description Update every item of an array
* @param {<Type>(item: Type) => Type} update A function that will update one item
* @param {Array<Type>} items An array of items to update
@aminnairi
aminnairi / posts.js
Created Jan 25, 2022
Seconde partie de l'exercice sur XMLHttpRequest
View posts.js
const request = new XMLHttpRequest();
const errorElement = document.getElementById("error");
const postsElement = document.getElementById("posts");
request.addEventListener("timeout", function() {
errorElement.innerText = "Le délai d'attente maximum est dépassé pour la requête.";
});
request.addEventListener("error", function() {
errorElement.innerText = this.statusText;
@aminnairi
aminnairi / index.php
Created Jan 18, 2022
Exercice Fonction
View index.php
<!DOCTYPE html>
<?php
$cart = [
[ "product" => "paper", "quantity" => 7, "price" => 1.26 ],
[ "product" => "pen", "quantity" => 2, "price" => 0.12 ],
[ "product" => "eraser", "quantity" => 5, "price" => 0.89 ]
];
$stocks = [
@aminnairi
aminnairi / index.php
Created Jan 18, 2022
Function Exercise
View index.php
<?php
$cart = [
[
"product" => "paper",
"quantity" => 7,
"price" => 1.26
],
[
"product" => "pen",
View exercise.php
<!DOCTYPE html>
<?php
$students = [
[
"id" => 1,
"name" => "Amanda ANDERSSON",
"CC1" => 10,
"CC2" => 17,
"CC3" => 12
@aminnairi
aminnairi / functions-exercise.php
Last active Jan 10, 2022
Functions exercises in PHP
View functions-exercise.php
<?php
$cart = [
["product" => "paper", "quantity" => 7, "price" => 1.26],
["product" => "pen", "quantity" => 2, "price" => 0.12],
["product" => "eraser", "quantity" => 5, "price" => 0.89]
];
$stocks = [
["product" => "paper", "quantity" => 88],
@aminnairi
aminnairi / asynchronous-recursive-generator.js
Last active Dec 17, 2021
Asynchronous Recursive Generator
View asynchronous-recursive-generator.js
async function* webservice(entity, index = 1) {
const response = await fetch(`https://jsonplaceholder.typicode.com/${entity}/${index}`);
if (response.ok) {
yield response.json();
yield* webservice(entity, index + 1);
}
}
for await (const user of webservice("users")) {
@aminnairi
aminnairi / asynchronous-recursive-generator.js
Created Dec 17, 2021
Asynchronous Recursive Generator
View asynchronous-recursive-generator.js
// Générateur asynchrone récursif
async function* webservice(entity, index = 1) {
const response = await fetch(`https://jsonplaceholder.typicode.com/${entity}/${index}`);
if (response.ok) {
yield response.json();
// Yield Star (yield*)
// Permet de renvoyer la valeur résolue d'un générateur dans un générateur
// Équivalent d'applatir une imbrication de génerateur les uns dans les autres