Skip to content

Instantly share code, notes, and snippets.

@rgaidot
rgaidot / design-patterns.md
Created April 4, 2024 12:09
design patterns

Design patterns

Patrons de Création :

  • Singleton : Garantit qu'une classe n'a qu'une seule instance et fournit un point d'accès global à cette instance.
  • Factory Method : Définit une interface pour créer un objet, mais permet aux sous-classes de choisir la classe d'objet à instancier.
  • Abstract Factory : Fournit une interface pour créer des familles d'objets connexes sans spécifier leurs classes concrètes.
  • Builder : Sépare la construction d'un objet complexe de sa représentation afin que le même processus de construction puisse créer différentes représentations.
  • Prototype : Utilisé pour créer de nouveaux objets en copiant un prototype existant plutôt qu'en utilisant un constructeur.
  • Object Pool : Un ensemble d'objets pré-construits qui sont maintenus prêts à être utilisés, évitant ainsi le coût de création et de destruction d'objets fréquemment utilisés.
@rgaidot
rgaidot / bomberman.py
Last active November 25, 2023 01:35
Bomberman game written in Python using the Pygame library
import pygame
# Set up the screen dimensions
screen_width = 640
screen_height = 480
screen = pygame.display.set_mode((screen_width, screen_height))
# Set up the title of the window
pygame.display.set_caption('Bomberman')
@rgaidot
rgaidot / tetris.rs
Created November 21, 2023 15:06
tetris
use std::fmt;
use std::time::Duration;
fn main() {
// Set up the game board
let mut board = vec![];
for _ in 0..10 {
board.push(vec![0; 10]);
}
@rgaidot
rgaidot / ti-tac-toe.ts
Last active November 21, 2023 15:01
Tic Tac Toe
class Game {
private gameBoard: number[] = []; // 3x3 grid of squares
private playerPieces: string[] = ['X', 'O']; // array of player pieces (X or O)
private winningConditions: string[] = ['horizontally', 'vertically', 'diagonally']; // array of winning conditions
constructor() {
this.resetGame();
}
resetGame(): void {
@rgaidot
rgaidot / wireguard
Last active September 21, 2023 23:13
wireguard with wireguard-ui
version: "3"
services:
wireguard:
image: linuxserver/wireguard:latest
container_name: wireguard
cap_add:
- NET_ADMIN
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
@rgaidot
rgaidot / pairsum.ts
Last active March 4, 2022 09:57
pairSum in javascript
const pairSumExplain = (array: Array<number>, target: number): Array<Array<number>> => {
const length: number = array.length;
const found: Array<Array<number>> = [];
for(let i = 0; i < length; i++) {
for(let j = (i + 1); j < length; j++) {
if(target == array[i] + array[j]) found.push([array[i], array[j]]);
}
}
#!/bin/sh -e
cat <<EOF
__ ________ .___
| | __\_____ \ __| _/
| |/ / _(__ < / __ |
| < / \/ /_/ |
|__|_ \/______ /\____ |
\/ \/ \/
@rgaidot
rgaidot / WorkingAgreementsTech.md
Last active July 12, 2022 01:38
Working Agreements Tech

Rules & Conventions

You're contributor, here are the guidelines we would must follow:

  • We've very precise rules over how our git commit messages can be formatted. This leads to more readable messages that are easy to follow when looking through the project history. But also, we use the git commit messages to generate change log. We use Conventional Commits guideline. It's better to create branches and commit messages in English and make them understandable
  • I.N.V.E.S.T.(Independent, Negotiable, Valuable, Estimatable, Small, Testable) ! Each Stories are a widely accepted set of criteria, or checklist, to assess the quality. If stories fails to meet one of these criteria, the team may want to reword it, or even consider a rewrite.
  • DRY ! It's better whenever possible, re-using as much code as possible rather than duplicating similar
@rgaidot
rgaidot / TextWithCR.js
Last active August 28, 2019 18:49
Text with carriage returns without dangerouslySetInnerHTML #react
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
const TextWithCR = ({ text }) => {
const lines = text.split('\n');
return (
<Fragment>
{lines.map(line => (
<Fragment key={line}>
@rgaidot
rgaidot / useStateFetch.js
Last active June 11, 2019 11:46
useStateFetch
import { useState, useEffect } from 'react';
const render = data => match =>
data.pending ? match.pending()
: data.error ? match.error(data.error)
: data.data ? match.data(data.data)
: null;
export const useStateFetch = url => {
const [data, setData] = useState({ pending: true });