Skip to content

Instantly share code, notes, and snippets.

@AmauryLugdu
AmauryLugdu / email-validator.ts
Created December 3, 2019 12:08
16 - Angular - Les formulaires : validations
import { AbstractControl, ValidationErrors } from '@angular/forms';
export function emailValidator(control: AbstractControl): ValidationErrors | null {
// One uppercase at least
const emailRegex = RegExp('^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\\.[a-z]{2,3}$');
const valid = emailRegex.test(control.value);
const errors = {
email: {
rules: 'should be a valid email adress'
@AmauryLugdu
AmauryLugdu / user.component.html
Created December 2, 2019 20:30
15 - Angular - Les formulaires : Reactive Form et FormGroup
<form [formGroup]= "userForm"(ngSubmit)="onSubmit()">
<div formGroupName="address">
<div>
<label>
Street:
<input type="text" formControlName="street">
</label>
</div>
<div>
@AmauryLugdu
AmauryLugdu / index.js
Created November 27, 2019 16:53
Express 4 - Méthode PUT et modification de données
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
const bodyParser = require('body-parser');
// Support JSON-encoded bodies
app.use(bodyParser.json());
// Support URL-encoded bodies
app.use(bodyParser.urlencoded({
extended: true
@AmauryLugdu
AmauryLugdu / index.js
Created November 27, 2019 12:38
Express 3 - Méthode POST et insertion de données
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
const bodyParser = require('body-parser');
// Support JSON-encoded bodies
app.use(bodyParser.json());
// Support URL-encoded bodies
app.use(bodyParser.urlencoded({
extended: true
@AmauryLugdu
AmauryLugdu / inde.js
Last active November 28, 2019 08:11
Express 2 - Express, SQL-MySQL, Postman
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.get('/api/movie', (req, res) => {
// connection to the database, and selection of employees
connection.query('SELECT * from movie', (err, results) => {
console.log(err)
@AmauryLugdu
AmauryLugdu / app.js
Created November 20, 2019 10:07
Express 1 - Discover Express
const express = require('express');
const app = express();
const port = 3000;
app.get("/api/movies", (req, res) => {
res.send("Récupère tout les films");
});
app.get("/api/movies/:id", (req, res) => {
res.json({ id: req.params.id });
@AmauryLugdu
AmauryLugdu / requests.http
Last active November 20, 2019 10:29
Le protocole HTTP - Mise en pratique
GET https://api.ipify.org/
### GET Image construction
GET https://upload.wikimedia.org/wikipedia/commons/2/20/UnderCon_icon.svg
### GET Tim Berner Lee
GET https://www.w3.org/History/19921103-hypertext/hypertext/WWW/TheProject.html
### GET Heroes
GET https://http-practice.herokuapp.com/status
### GET application statis in JSON format
GET https://http-practice.herokuapp.com/status
Accept: application/json
mysql> SELECT * FROM school;
Empty set (0,00 sec)
mysql> INSERT INTO school (name, country, capacity) VALUES ('Beauxbatons Academy of Magic', 'France', 550) , ('Castelobruxo ', 'Brazil', 380), ('Durmstrang Institute', 'Norway', 570), ('Hogwarts School of Witchcraft and Wizardry', 'United Kingdom', 450), ('Ilvermorny School of Witchcraft and Wizardry', 'USA', 300), ('Koldovstoretz', 'Russia', 125), ('Mahoutokoro School of Magic', 'Japan', 800), ('Uagadou School of Magic', 'Uganda', 350);
Query OK, 8 rows affected (0,02 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM school; +----+----------------------------------------------+----------+----------------+
| id | name | capacity | country |
+----+----------------------------------------------+----------+----------------+
@AmauryLugdu
AmauryLugdu / gist:e10847fa9e5b57861864772088fd1d0f
Created November 19, 2019 09:56
02 - Retrieving information with SELECT
mysql> USE wild_db_quest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT firstname,lastname,birthday,birth_place,biography,is_muggle FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31';
+-----------+----------+------------+-------------+---------------------------------------+-----------+
| firstname | lastname | birthday | birth_place | biography | is_muggle |
+-----------+----------+------------+-------------+---------------------------------------+-----------+
| harry | potter | 1980-07-31 | london | | 0 |
@AmauryLugdu
AmauryLugdu / helloboy.js
Created October 6, 2019 13:05
module node
var cowsay = require("cowsay");
console.log(cowsay.say({
text : "Hello boy",
e : "oO",
T : "U "
}));
// or cowsay.think()