Skip to content

Instantly share code, notes, and snippets.

View vmalep's full-sized avatar

Pierre van Male vmalep

View GitHub Profile
@vmalep
vmalep / WCS-Linux1
Last active September 13, 2021 20:49
I find weird to copy/past real content of my Linux install and make it public.
Therefore I am limiting this exercice to executing the 3 commands into my WCS folder...
vmalep@L390Y:~/Documents/study/WildCodeSchool$ cd quests/
vmalep@L390Y:~/Documents/study/WildCodeSchool/quests$ ls
hello-world my-super-website wild-git
vmalep@L390Y:~/Documents/study/WildCodeSchool/quests$ pwd
/home/vmalep/Documents/study/WildCodeSchool/quests
vmalep@L390Y:~/Documents/study/WildCodeSchool/quests/planets$ find
.
./fictional
./fictional/coruscant.jpeg
./fictional/arrakis.jpeg
./fictional/cybertron.jpeg
./real
./real/terrestrial
./real/terrestrial/earth.jpeg
./real/terrestrial/neptune.jpeg
@vmalep
vmalep / gist:8d768fbc88c9042537986129a4f32682
Created November 1, 2021 21:23
Quest 383 / Pierre van Male
const http = require('http')
const url = require('url')
const port = 8000
const requestHandler = (request, response) => {
console.log(request.url)
const current_url = new URL(request.url, 'http://localhost:8000')
const search_params = current_url.searchParams
const name = search_params.get('name')
const city = search_params.get('city')
@vmalep
vmalep / gist:25cf3aebc9e7e2c6fd351bf0aed0a69a
Created November 8, 2021 08:24
Quest 485 - Pierre van Male
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> 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),
app.post('/api/users', (req, res) => {
const { firstname, lastname, email } = req.body
connection.promise().query(
'INSERT INTO users(firstname, lastname, email) VALUES (?, ?, ?)',
[firstname, lastname, email],)
.then(result=>res.status(201).send('User successfully saved')
.catch(err=>res.status(500).send('Error saving the user'))
)
})
app.put('/api/movies/:id', (req, res) => {
const movieId = req.params.id
const moviePropsToUpdate = req.body
connection.promise().query(
'UPDATE movies SET ? WHERE id = ?',
[moviePropsToUpdate, movieId],)
.then(result=>res.status(200).send('Movie updated successfully 🎉'))
.catch(err=>{
console.log(err)
res.status(500).send('Error updating a movie')
app.delete('/api/movies/:id', (req, res) => {
const movieId = req.params.id;
connection.promise().query(
'DELETE FROM movies WHERE id = ?',
[movieId],)
.then(result=>res.status(200).send('🎉 Movie deleted!'))
.catch(err=>{
console.log(err)
res.status(500).send('😱 Error deleting an movie')
})
app.get('/api/movies', (req, res) => {
let sql = 'SELECT * FROM movies'
if(req.query.color === '1') {
sql += ' WHERE color = 1'
}
if(req.query.max_duration){
const maxDuration = parseInt(req.query.max_duration)
sql.includes('WHERE') ? sql += ' AND ' : sql += ' WHERE'
sql += ` duration <= ${maxDuration}`
app.post('/api/movies', (req, res) => {
const { title, director, year, color, duration } = req.body
connection.promise().query(
'INSERT INTO movies(title, director, year, color, duration) VALUES (?, ?, ?, ?, ?)',
[title, director, year, color, duration])
.then(result => {
const id = result.insertId
const createdMovie = { id, title, director, year, color, duration }
res.status(201).json(createdMovie)
res.redirect('Movie successfully saved')
Queries:
SELECT w.lastname, w.firstname, p.role, t.name
FROM player AS p
JOIN wizard AS w ON p.wizard_id=w.id
JOIN team AS t ON p.team_id=t.id
ORDER BY t.name, p.role, w.lastname, w.firstname;
SELECT w.lastname, w.firstname
FROM player AS p
JOIN wizard AS w ON p.wizard_id=w.id