Skip to content

Instantly share code, notes, and snippets.

View unes's full-sized avatar

Younes unes

  • ʕʘ̅͜ʘ̅ʔ
  • Casablanca
  • 22:45 (UTC)
View GitHub Profile
@unes
unes / whale-talk.js
Last active September 7, 2023 08:53
Whale Talk - JavaScript (from Codecademy)
/*
* translates "turpentine and turtles" to "whale talk" languag, outputs "UUEEIEEAUUEE"
*/
const input = 'turpentine and turtles';
const vowels = ['a', 'e', 'i', 'o', 'u'];
const resultArray = [];
for(let i = 0; i < input.length; i++) {
@unes
unes / expressjs-error-middleware.js
Created September 4, 2023 08:53
Error Handling - Express.js
const express = require('express');
const app = express();
// Route handler
app.get('/users/:id', (req, res, next) => {
const userId = req.params.id;
// Simulating an error when user is not found
if (!getUserById(userId)) {
const error = new Error('User not found');
@unes
unes / expressjs-routes-api.js
Created September 1, 2023 09:04
LEARN EXPRESS ROUTES - Codecademy
const express = require("express");
const app = express();
// Serves Express Yourself website
app.use(express.static("public"));
const {
getElementById,
getIndexById,
updateElement,
@unes
unes / weather.js
Created August 28, 2023 09:54
get weather info of a random city. using : async, await, fetch
const cities = [
{ name: 'New York', lat: 40.7128, lng: -74.0060 },
{ name: 'London', lat: 51.5074, lng: -0.1278 },
{ name: 'Paris', lat: 48.8566, lng: 2.3522 },
{ name: 'Tokyo', lat: 35.6895, lng: 139.6917 },
{ name: 'Sydney', lat: -33.8651, lng: 151.2099 },
{ name: 'Rome', lat: 41.9028, lng: 12.4964 },
{ name: 'Cairo', lat: 30.0444, lng: 31.2357 },
{ name: 'Rio de Janeiro', lat: -22.9068, lng: -43.1729 },
{ name: 'Dubai', lat: 25.2048, lng: 55.2708 },
@unes
unes / asyncawait.js
Last active August 28, 2023 09:24
Node.js - Javascript Promises and Async/Await
const axiosRequest = require('axios');
axiosRequest
.get('http://www.boredapi.com/api/activity/')
.then(response => {
console.log(`You could ${response.data.activity}`);
})
.catch(error => {
console.error(`ERROR! ${error}`);
});
@unes
unes / jsx-var-attr.js
Created August 26, 2023 16:15
React - Variable Attributes in JSX
// Use a variable to set the `height` and `width` attributes:
const sideLength = "200px";
const panda = (
<img
src="images/panda.jpg"
alt="panda"
height={sideLength}
width={sideLength} />
@unes
unes / index.js
Created August 25, 2023 18:16
Using nodeJS readline module, adding contacts
const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const contacts = [];
function addContact() {
rl.question('Enter name: ', (name) => {
rl.question('Enter phone #: ', (phoneNumber) => {
contacts.push({ name, phoneNumber });
@unes
unes / .gitignore
Created February 22, 2016 22:13
Global gitignore file (OS X)
.DS_Store
._*
Icon
.Spotlight-V100
.Trashes
.LSOverride
.fseventsd
.TemporaryItems
.localized
*.cache
@unes
unes / .gitexcludes
Created February 22, 2016 22:11
Local git excludes file
*.DS_Store
*.idea
*.[Cc]ache
*.log
*.log.*
[Oo]bj
[Bb]in
ErrorLogs
*~
*.db