Skip to content

Instantly share code, notes, and snippets.

View OtayNacef's full-sized avatar
🎯
Focusing

Nacef Otay OtayNacef

🎯
Focusing
View GitHub Profile
@OtayNacef
OtayNacef / postcodesTunisia.json
Created December 8, 2022 23:56
zip codes city region tunisia
[{"Gov":"Ariana","Deleg":"Sidi Thabet","Cite":"Cite Dridi","zip":"2032"},
{"Gov":"Ariana","Deleg":"La Soukra","Cite":"Cite Fateh","zip":"2036"},
{"Gov":"Ariana","Deleg":"Sidi Thabet","Cite":"Cite El Bokri","zip":"2032"},
{"Gov":"Ariana","Deleg":"La Soukra","Cite":"Cite Fonciere","zip":"2036"},
{"Gov":"Ariana","Deleg":"Sidi Thabet","Cite":"Cite El Frachich","zip":"2032"},
{"Gov":"Ariana","Deleg":"La Soukra","Cite":"Cite Snit","zip":"2036"},
{"Gov":"Ariana","Deleg":"Raoued","Cite":"Cite El Mouaouiet","zip":"2081"},
{"Gov":"Ariana","Deleg":"Sidi Thabet","Cite":"Cite El Ghribi","zip":"2032"},
{"Gov":"Ariana","Deleg":"La Soukra","Cite":"Cite Touilia","zip":"2036"},
{"Gov":"Ariana","Deleg":"Raoued","Cite":"Cite El Mountazeh","zip":"2081"},
@OtayNacef
OtayNacef / copyToClipboard.ts
Created December 16, 2021 14:04
typescript function to copy text to clipboard
export const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text);
};
@OtayNacef
OtayNacef / PaginationPipeline.ts
Created November 24, 2021 10:05
Pagination Pipeline Using Aggregate - Mongoose
export const paginationAggregate = ( page: number) => {
//Max Items
const limit = 10;
const skip = (page - 1) * limit;
return [
{
$unwind: '$total',
},
{
@OtayNacef
OtayNacef / formatPaginatedResponse.ts
Last active November 24, 2021 10:01
Javascript pagination that returns currentPage , totalItems , totalPages and items
export const formatPaginatedResponse = (rows: unknown[], count: number, page: string) => {
const itemsPerPage = Number(process.env.ITEMS_PER_PAGE);
const currentPage = Math.max(Number(page), 1) || 1;
return {
page: currentPage,
totalItems: count,
hasNextPage: itemsPerPage * displayPage < count,
totalPages: Math.max(Math.floor(count / itemsPerPage) + (count % itemsPerPage === 0 ? 0 : 1), 1),
items: rows,
};
@OtayNacef
OtayNacef / Users.tsx
Created April 14, 2021 07:47
Redux Toolkit
import React, {useEffect, MouseEvent} from 'react';
import {useSelector} from 'react-redux';
import {fetchUsers, usersSelector, createUser} from './slices/users';
import {useAppDispatch} from './store';
import {User} from './store/user/user';
import './styles.scss';
const Users = () => {
@OtayNacef
OtayNacef / users.ts
Created April 13, 2021 08:14
Redux toolkit Slice
import {createSlice, PayloadAction} from '@reduxjs/toolkit';
import {User} from '../store/user/user';
import {RootState} from '.';
import {AppDispatch, AppThunk} from '../store';
export type UsersState = {
loading: boolean;
hasErrors: boolean;
users: User[];
};
@FXML
private void telecharger(ActionEvent event) throws SQLException {
Reservation_hotes res = new Reservation_hotes();
res = table_reserv.getSelectionModel().getSelectedItem();
ReservationPdf pdf = new ReservationPdf();
pdf.Reservation(
res.getNumero_reservation(),
res.getDate_debut(),
res.getNb_jours(),
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "ESNext",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"jsx": "react",
"allowJs": true,
"baseUrl": "src",
@OtayNacef
OtayNacef / webpack.config.ts
Last active March 17, 2021 22:46
React Typescript Webpack
import path from "path";
import { Configuration, DefinePlugin } from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
const webpackConfig = (): Configuration => ({
entry: "./src/index.tsx",
...(process.env.production || !process.env.development
? {}
@OtayNacef
OtayNacef / tsconfig.json
Created March 11, 2021 09:27
React TypeScript Without CRA
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",