Skip to content

Instantly share code, notes, and snippets.

View ahtcx's full-sized avatar

Alexandre Hitchcox ahtcx

View GitHub Profile
import SwiftUI
/// A custom button style designed specifically for use with `NavigationLink`.
///
/// `NavigationLinkButtonStyle` allows you to apply a `PrimitiveButtonStyle` to a `Button` within a `NavigationLink` in SwiftUI.
/// This style adds a forward chevron image to the button, providing a visual cue for navigation.
///
/// Example Usage:
/// ```swift
/// NavigationLink("Navigate") {

hey :)

const getTypeofValue = (value: any) => typeof value;
export type TypeofReturnType = ReturnType<typeof getTypeofValue>;
// prettier-ignore
export type TypeFromTypeString<TypeString extends TypeofReturnType> =
TypeString extends "string" ? string :
TypeString extends "number" ? number :
TypeString extends "bigint" ? BigInt :
TypeString extends "boolean" ? boolean :
TypeString extends "symbol" ? symbol :
export type UseRasterizedImageUrlParameters = [imageUrl: string, width: number, height?: number];
export interface UseRasterizedImageUrlCache {
promise: Promise<void>;
inputs: UseRasterizedImageUrlParameters;
error?: unknown;
rasterizedImageUrl?: string;
}
const caches: UseRasterizedImageUrlCache[] = [];
import { useCallback, useState } from "react";
export const useForceUpdate = () => {
const [, dispatch] = useState(Object.create(null));
return useCallback(() => dispatch(Object.create(null)), [dispatch]);
};
import { useEffect, useRef } from 'react'
export interface ScrollEvents<Event extends any> {
scrollStart?: (event: Event) => void
scrollStop?: (event: Event) => void
scroll?: (event: Event) => void
}
export const useScrollEvents = <Event extends any = React.UIEvent>(
scrollEvents: ScrollEvents<Event>,
@ahtcx
ahtcx / useInterval.ts
Created November 1, 2019 14:32
TypeScript version of Dan Abramov's `useInterval`
import { useEffect, useRef } from 'react'
type Callback = () => void
export const useInterval = (callback: Callback, delay: number | null = null) => {
const savedCallback = useRef<Callback>()
useEffect(() => {
savedCallback.current = callback
}, [callback])
@ahtcx
ahtcx / intra_api.md
Last active December 15, 2022 16:40
Non-official list of Epitech Intra API endpoints

Epitech API

Epitech's API is located at https://intra.epitech.eu/ and for the most part is any intranet page with the format=json param added.

Authentication

To access most endpoints a PHPSESSID cookie must be set to an authenticated session. Authentification can be done with an autologin code or via Office 365 oauth.

Endpoints

API endpoints and what they require and do. JSON file of endpoints below the documentation.

@ahtcx
ahtcx / deep-merge.js
Last active April 29, 2024 17:13
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}