Skip to content

Instantly share code, notes, and snippets.

@bastienapp
bastienapp / employee-add-fields.sql
Created February 18, 2020 07:22
employee-add-fields.sql
ALTER TABLE employee ADD COLUMN hired_year SMALLINT;
ALTER TABLE employee ADD COLUMN department ENUM('Marketing', 'HR', 'Software', 'Hardware');
UPDATE employee SET hired_year = FLOOR(RAND()*(2019-2014+1)+2014);
UPDATE employee SET department = CASE
WHEN RAND() < 0.25 THEN 'Marketing'
WHEN RAND() < 0.33 THEN 'HR'
WHEN RAND() < 0.5 THEN 'Software'
ELSE 'Hardware'
END;
@bastienapp
bastienapp / index.js
Last active February 14, 2020 13:09
Express quest 5
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
@bastienapp
bastienapp / index.js
Last active February 14, 2020 13:05
Express quest 4
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
@bastienapp
bastienapp / index.js
Created February 14, 2020 10:54
Express quest 3
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
@bastienapp
bastienapp / index.js
Last active February 14, 2020 13:07
Express 2
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
const express = require('express');
const app = express();
const port = 3000;
app.get('/api/movies', (req, res) => {
res.send('Récupération de tous les films');
});
app.get(`/api/movies/:id`, (req, res) => {
const id = req.params.id; // récupère John
const url = require('url');
const http = require('http');
const port = 8000;
const requestHandler = (request, response) => {
const parsedUrl = url.parse(request.url, true);
const params = parsedUrl.query;
if (params.name && params.city) {
response.end(`Hello ${params.name} from ${params.city}!`);
} else {
### get all wilders
GET https://http-practice.herokuapp.com/wilders
### get wilder for JavaScript, page 10
GET https://http-practice.herokuapp.com/wilders?language=JavaScript&page=10
### create wilder from url-encoded
POST https://http-practice.herokuapp.com/wilders
Content-Type: application/x-www-form-urlencoded
var cowsay = require("cowsay");
console.log(cowsay.say({
text : "hello boy",
e : "^^",
T : "U "
}));
process.stdin.resume()
process.stdin.setEncoding('utf8')
console.log('What\'s your age ? ')
process.stdin.on('data', (value) => {
const age = parseInt(value, 10);
if (isNaN(age)) {
console.error("Value is not a number")
} else if (age < 0 || age > 99) {
console.error("Illegal value")