Skip to content

Instantly share code, notes, and snippets.

View justinehell's full-sized avatar
🎯
Focusing

Justine justinehell

🎯
Focusing
View GitHub Profile
@justinehell
justinehell / index.js
Last active September 13, 2020 14:38
Express 2 - Express, MySQL, Postman
const express = require("express");
const app = express();
const port = 3000;
const connection = require("./conf");
app.get("/api/movies", (req, res) => {
connection.query("SELECT * from movie", (err, results) => {
if (err) {
res.status(500).send("Error while recovering movies");
} else {
@justinehell
justinehell / index.js
Created September 11, 2020 09:54
Express 1 - Découverte d'Express
const express = require("express");
const app = express();
const port = 3000;
app.get(`/api/movies`, (request, response) => {
response.send("Récupération de tous les films");
});
app.get(`/api/movies/:id`, (request, response) => {
response.json({ id: request.params.id });
@justinehell
justinehell / server.js
Created September 8, 2020 10:09
Node.js - Créer un serveur HTTP
const http = require("http");
const url = require("url");
const port = 8000;
const requestHandler = (request, response) => {
let parsedUrl = url.parse(request.url, true);
if (parsedUrl.query.name && parsedUrl.query.city) {
response.end(
`Hello, ${parsedUrl.query.name} from ${parsedUrl.query.city}!`
);
@justinehell
justinehell / school.sql
Created September 7, 2020 08:35
03 - Manipulation des données
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)
@justinehell
justinehell / select.sql
Created September 7, 2020 07:48
02 - Récupérer des informations avec SELECT
Récupère tous les champs pour les sorciers nés entre 1975 et 1985
mysql> SELECT * FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31';
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| id | firstname | lastname | birthday | birth_place | biography | is_muggle |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| 1 | harry | potter | 1980-07-31 | london | | 0 |
| 2 | hermione | granger | 1979-09-19 | | Friend of Harry Potter | 0 |
| 4 | ron | weasley | 1980-03-01 | | Best friend of Harry | 0 |
| 5 | ginny | weasley | 1981-08-11 | | Sister of Ron and girlfriend of Harry | 0 |
@justinehell
justinehell / requests.http
Created September 4, 2020 09:44
Le protocole HTTP - Mise en pratique
### Request with Wilders URL
GET https://http-practice.herokuapp.com/wilders
### Request with 2 filters : Javascript & page 2
GET https://http-practice.herokuapp.com/wilders?language=JavaScript&page=2
### Request url-encoded
POST https://http-practice.herokuapp.com/wilders
Content-Type: application/x-www-form-urlencoded
@justinehell
justinehell / MyTimer.js
Created August 10, 2020 13:10
Cycle de vie - React
import React from "react";
class MyTimer extends React.Component {
constructor(props) {
super(props);
this.state = {
timer: 0,
};
}
@justinehell
justinehell / script.js
Last active June 22, 2020 17:17
What's a cow !
let cowsay = require("cowsay");
console.log(cowsay.say({
text : "hello boy",
e : "><",
T : "U "
}));
@justinehell
justinehell / app.js
Last active June 22, 2020 16:33
Découverte de NodeJS
process.stdin.resume()
process.stdin.setEncoding('utf8')
console.log('Please enter your age')
process.stdin.on('data', (age) => {
let actualYear = new Date().getFullYear();
if (typeof(parseInt(age)) === "number" && parseInt(age) < 100 && parseInt(age) > 0) {
console.log(`Year of your birth : ${actualYear - age}`);
process.exit();
} else {
console.log("Invalide input, try again !")
@justinehell
justinehell / poo.js
Created June 22, 2020 13:22
POO en JS 1 - Procédural vs Objet, classes, instances
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
tellMyName() {
console.log(`I am ${this.name}`)
}
tellMyAge() {
console.log(`I am ${this.age} old`)