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
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;
@abdelfattahradwan
abdelfattahradwan / hue_colors.md
Created May 9, 2021 18:02 — forked from popcorn245/hue_colors.md
XY Color Conversion

FROM HUE DESIGN DOCS

https://github.com/PhilipsHue/PhilipsHueSDK-iOS-OSX/blob/00187a3db88dedd640f5ddfa8a474458dff4e1db/ApplicationDesignNotes/RGB%20to%20xy%20Color%20conversion.md

#Conversion between RGB and xy in the CIE 1931 colorspace for hue The conversion between RGB and xy in the CIE 1931 colorspace is not something Philips invented, but we have an optimized conversion for our different light types, like hue bulbs and LivingColors. It is important to differentiate between the various light types, because they do not all support the same color gamut. For example, the hue bulbs are very good at showing nice whites, while the LivingColors are generally a bit better at colors, like green and cyan.