Skip to content

Instantly share code, notes, and snippets.

View simon-saliba's full-sized avatar

Simon Saliba simon-saliba

  • Paris
View GitHub Profile
@simon-saliba
simon-saliba / main.py
Created January 19, 2021 22:41
Explaining basic web scraping - 1
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
op = webdriver.ChromeOptions()
driver = webdriver.Chrome("/app/chromedriver_84_linux",options=op)
while(1):
driver.get("https://the-url-of-some-website")
@simon-saliba
simon-saliba / main.py
Created January 19, 2021 22:47
Changing user-agent property after every request - 1
import requests
from selenium import webdriver
from fake_useragent import UserAgent
ua = UserAgent()
userAgent = ua.random
options.add_argument(f'user-agent={userAgent}')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome("/app/chromedriver_84_linux",options)
while(1):
@simon-saliba
simon-saliba / directory-structure-1.txt
Last active January 23, 2021 14:30
directory-structure
/project
/frontend
/backend
@simon-saliba
simon-saliba / project-directory-2.txt
Created January 23, 2021 14:51
project-directory-2
/project
package.json <--- this is the backend package.json
/front
/node-modules
/public
/src
.gitignore
package-lock.json
package.json <--- this is the frontend package.json
README.md
@simon-saliba
simon-saliba / index.js
Last active January 23, 2021 15:40
backend-dev-version
const express = require('express');
var cors = require('cors');
let app = express();
let port = process.env.PORT || 8080;
app.use(cors());
app.get('/hello', function(req, res) {
res.json('Hello from backend !');
})
app.listen(port, () => {
@simon-saliba
simon-saliba / package.json
Created January 23, 2021 15:19
backend-packagejson-dev
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "nodemon index.js"
},
"author": "",
@simon-saliba
simon-saliba / App.js
Last active January 23, 2021 15:47
front-end App.js
import React, { useState, useEffect } from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
const [message, setMessage] = useState('');
// Send a request to the server on port 8080 to retrieve message
useEffect(() => {
fetch('http://localhost:8080/hello')
.then(response => {
@simon-saliba
simon-saliba / package.json
Last active January 23, 2021 15:53
frontend package.json proxy
{
"name": "course-lookup-front",
"version": "0.1.0",
"private": true,
...
"proxy": "http://localhost:8080"
}
@simon-saliba
simon-saliba / index.js
Created January 23, 2021 16:31
backend-prod-version
const express = require('express');
var cors = require('cors');
let app = express();
let port = process.env.PORT || 8080;
var path = require('path');
app.use(cors());
if(process.env.NODE_ENV === 'production'){
// If running in production mode enter here
app.use(express.static(path.join(__dirname, 'front/build')));
@simon-saliba
simon-saliba / package.json
Created January 23, 2021 16:39
backend-package-production
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "nodemon index.js",
"start": "NODE_ENV=production nodemon index.js"
},