Skip to content

Instantly share code, notes, and snippets.

View yostane's full-sized avatar

Yassine Benabbas yostane

View GitHub Profile
import Foundation
import FoundationNetworking
// URL session provides async and callback API to upload Data
// Use continuations to convert existing callback API into an async
// https://developer.apple.com/documentation/foundation/url_loading_system/uploading_data_to_a_website
// You can POST to the /register endpoint of this API https://movie-api-ybwl.koyeb.app/api-docs/
enum HttpError: Error {
struct ToDoTask {
var description: String
var completed: Bool
}
let task1 = ToDoTask(description: "Practice ping-pong.", completed: false)
let toDoList = [
task1,
ToDoTask(description: "Buy a pirate costume.", completed: true),
ToDoTask(description: "Visit Boston in the Fall.", completed: false),
func computeMax<T: Comparable>(a: T, b: T) -> T{
return if a > b {
a
} else {
b
}
}
// Here, swift inferred that T is Float (or Double ?)
print(computeMax(a: 100, b: 20.0))
@yostane
yostane / exemple.ts
Last active March 7, 2023 15:05
ts project
const x = 10;
const y = 20;
function add(x: number, y: number): number {
return x + y;
}
console.log(add(x, y));
@yostane
yostane / index.jsp
Last active March 1, 2023 10:37
JEE 10 jsp (src/webapp/index.jsp) and web.xml (src/webapp/META-INF/web.xml)
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>
<p/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Client mqtt</title>
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
import paho.mqtt.client as mqtt
def on_connect_mqtt(client, userdata, flags, rc):
print(f"rc : {rc}, {userdata}")
client.publish("chambre1/ordi", "Ah !")
res = client.subscribe("chambre1/tv")
print(f"subscribe res : {res}")
res = client.subscribe("chambre1/tv2")
print(f"subscribe res : {res}")
@yostane
yostane / exo02.js
Last active May 18, 2021 11:01
bie2 1922 fsjs
"use strict";
const http = require("http");
// Cet exercice utilise le module http de nodejs
// documentation: https://nodejs.org/api/http.html et https://www.w3schools.com/nodejs/nodejs_http.asp
/**
* créer un serveur nodejs qui affiche dans la console les champs suivants de la requête client: url, headers, method
* Le serveur répond au client avec une réponse http dont le coprs contient la date à laquelle il a reçu la requete
* Documentation: https://nodejs.org/api/http.html#http_class_http_incomingmessage
// source: https://www.w3resource.com/csharp-exercises/for-loop/csharp-for-loop-exercise-38.php
int num, r, sum = 0, t;
Console.Write("\n\n");
Console.Write("Check whether a number is a palindrome or not:\n");
Console.Write("------------------------------------------------");
Console.Write("\n\n");
Console.Write("Input a number: ");
num = 123115;