Skip to content

Instantly share code, notes, and snippets.

View abdelfattahradwan's full-sized avatar
🏠
Working from home

abdelfattahradwan

🏠
Working from home
View GitHub Profile
@abdelfattahradwan
abdelfattahradwan / .env
Created February 19, 2025 09:15
A Docker Compose file that spins up a MongoDB replica set with one master and two slave nodes.
MONGODB_ROOT_USERNAME="YOUR_USERNAME_HERE"
MONGODB_ROOT_PASSWORD="YOUR_PASSWORD_HERE"
# Use `openssl rand -base64 756` to generate a valid MongoDB key.
MONGO_REPLICA_SET_KEY="YOUR_REPLICA_SET_KEY_HERE"
const ACCEPT_LANGUAGE_REGEX =
/(?<code>[a-zA-Z]{1,8})(?:-(?<region>[a-zA-Z]{1,8}))?(?:;q=(?<quality>0\.\d+|\d))?/g;
type Language = {
code: string;
region?: string;
quality: number;
};
export default function parseAcceptLanguage(header: string): Array<Language> {
import { browser } from "$app/environment";
export default function formatDateTime(dateTime: Date): string {
return browser && window.navigator
? new Intl.DateTimeFormat(window.navigator.language, {
dateStyle: "long",
timeStyle: "short",
}).format(dateTime)
: dateTime.toLocaleString();
}
<script lang="ts">
import { page } from "$app/stores";
export let title: string = "";
export let type: string = "";
export let image: string = "";
export let url: string = $page.url.pathname;
export let description: string = "";
export let siteName: string = "";
export let twitter: string = "";
@abdelfattahradwan
abdelfattahradwan / form-data-to-object.ts
Created April 17, 2024 00:35
A function to convert FormData into an object, supporting multiple values per key using arrays.
export default async function formDataToObject(
formData: Promise<FormData> | FormData,
): Promise<Record<string, unknown>> {
const object: Record<string, unknown> = {};
for (const [key, value] of await Promise.resolve(formData)) {
const property = object[key];
if (property === undefined) {
object[key] = value;
} else if (Array.isArray(property)) {
property.push(value);
@abdelfattahradwan
abdelfattahradwan / slugify.ts
Last active April 16, 2024 20:52
A function that converts strings into URL-friendly slugs by lowercasing, replacing non-alphanumeric characters with dashes, and trimming leading/trailing dashes.
const NON_ALPHANUMERIC_REGEX = /[^a-z0-9]+/g;
const LEADING_TRAILING_DASHES_REGEX = /^-+|-+$/g;
export default function slugify(title: string): string {
return title
.toLowerCase()
.replace(NON_ALPHANUMERIC_REGEX, "-")
.replace(LEADING_TRAILING_DASHES_REGEX, "");
}
@abdelfattahradwan
abdelfattahradwan / SyncCollectionViewer.cs
Created January 13, 2023 13:42
An editor tool that allows you inspect the contents of Fish-Networking's sync collections. (https://ko-fi.com/winterboltgames)
using FishNet.Object;
using System.Collections.Generic;
using System.Reflection;
using System;
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Linq;
using FishNet.Object.Synchronizing;
@abdelfattahradwan
abdelfattahradwan / .htaccess
Created December 29, 2022 15:29
.htaccess File for SvelteKit Single-Page-Applications
# Rewrite non /app/build/ requests to /app/build/
RewriteCond %{REQUEST_URI} !^/app/build/
RewriteRule ^(.*)$ /app/build/$1 [L]
# Rewrite requests to non-existing files/dirs to /app/build/index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@abdelfattahradwan
abdelfattahradwan / NoClip.cs
Created July 6, 2021 04:15
Prevents first person objects from clipping through objects in world without needing a separate camera.
using UnityEngine;
public sealed class NoClip : MonoBehaviour
{
[SerializeField] private float radius;
[SerializeField] private float distance;
[SerializeField] private AnimationCurve offsetCurve;
[SerializeField] private LayerMask clippingLayerMask;
@abdelfattahradwan
abdelfattahradwan / SimpleCharacterController.cs
Created July 6, 2021 04:13
Simple FPS Character Controller for Unity
using UnityEngine;
public sealed class SimpleCharacterController : MonoBehaviour
{
[SerializeField] private float speed;
[SerializeField] private float jumpSpeed;
private Vector3 _velocity;
[SerializeField] private CharacterController characterController;