Skip to content

Instantly share code, notes, and snippets.

View mkhoussid's full-sized avatar

mkhoussid

View GitHub Profile
@mkhoussid
mkhoussid / gist:09e7b5329ef647fb0c5338796d6c884d
Last active November 14, 2026 08:24
agy location check patch
#!/usr/bin/env python3
"""Inspect a known binary patch; modify only with --apply and a reviewed SHA-256.
Supports thin, little-endian Mach-O arm64 and x86_64 executables only. Matching
is heuristic: a unique instruction sequence is not proof of its purpose, and
passing these checks does not establish compatibility with any CLI release.
Quit the CLI and its updater before applying. Original bytes and mode are
retained beside the target; ad-hoc signing changes the vendor signing identity.
Only registered exact build hashes may be modified. The current profile covers
one observed W2 local eligibility check; server-side acceptance unverified;
@mkhoussid
mkhoussid / gist:d6cb58fb9eba048212329c1d090cebf4
Created June 26, 2024 12:11
useSearchParams (adapted from react-router/-dom)
/*
I wanted to update and listen to search param changes without installing any more libraries than neccessary.
So, instead of installing `react-router-dom` just for its `useSearchParams` hook, I plucked some of their code.
Their `useSearchParams` hook used `useNavigate` to update the url, and `LocationContext` wraps
their `Routes` component, so I omitted those two as well
*/
import * as React from 'react';
import { SetSearchParams, SearchParamsChange } from 'interfaces/SearchParams';
@mkhoussid
mkhoussid / unicodeToWin1251.js
Last active September 28, 2021 16:00
unicodeToWin1251 function
const map = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
@mkhoussid
mkhoussid / useNetworkInfo.tsx
Last active December 9, 2020 09:35
useNetworkInfo hook written in Typescript
// adapted from here: https://googlechrome.github.io/samples/network-information/
import React from 'react';
type TNetworkInfo = {
type: string;
downlink: string;
rtt: string;
downlinkMax: string;
effectiveType: string;
@mkhoussid
mkhoussid / useComponentWillMount.ts
Created November 16, 2020 08:45
useComponentWillMount ReactJS hook
// NOTE: This does NOT work on NextJS: https://github.com/vercel/next.js/discussions/19204
// Adapted from here: https://stackoverflow.com/questions/53464595/how-to-use-componentwillmount-in-react-hooks#comment101488609_56818036
const useComponentWillMount = (func: (...params: any[]) => any): void => {
const willMount = useRef(true);
useEffect(() => {
// invert flag to ensure `func` does not run twice after mount
willMount.current = false;
}, []);
@mkhoussid
mkhoussid / hexToRgba.ts
Last active November 16, 2020 08:39
Convert Hex color to RGBA format
export const hexToRgba = (rgbaColor: string, opacity: number): string =>
`rgba(${parseInt(rgbaColor.substring(1, 3), 16)}, ${parseInt(rgbaColor.substring(3, 5), 16)}, ${parseInt(
rgbaColor.substring(5, 7),
16,
)}, ${opacity})`;
// example usage:
// hexToRgba(#FFFFFF, 0.5) -> 'rgba(255, 255, 255, 0.5)'
@mkhoussid
mkhoussid / usePreloadImages.ts
Created November 16, 2020 08:22
usePreloadImages hook (download images in the background after DOM has rendered)
// This preloads images AFTER DOM has loaded
// See PreloadedImages.tsx for loading images before DOM is ready (https://gist.github.com/mkhoussid/d6a1a7b3d029c42bbcb45bdc929602c8)
import React from 'react';
export default function usePreloadImages(imageUrls: string[]): void {
React.useEffect(() => {
imageUrls.forEach((imageUrl) => {
const image = new Image();
image.src = imageUrl;
@mkhoussid
mkhoussid / PreloadImages.tsx
Created November 16, 2020 08:22
PreloadImages component (download images before DOM has loaded)
// This preloads images BEFORE DOM has loaded
// See usePreloadImages.ts for loading images after DOM has loaded (https://gist.github.com/mkhoussid/c960ba200d6ef9142b80769a7c84e5f1)
import React from 'react';
type TPreloadImages = {
imageUrls: string[];
};
export default React.memo(({ imageUrls }: TPreloadImages) => {
return (
@mkhoussid
mkhoussid / PhoneInput.tsx
Created November 16, 2020 07:09
Country input + phone number format (using i18n-iso-countries and libphonenumber-js)
///////////////////////////////////////////////////////////////////////////////////////////////////
// https://codesandbox.io/s/hopeful-williams-ntsqk?file=/src/components/PhoneInput/index.tsx:0-2307
///////////////////////////////////////////////////////////////////////////////////////////////////
import React from "react";
import { Input, Select, Button } from "antd";
import countries, { getNames } from "i18n-iso-countries";
import {
AsYouType,
getCountryCallingCode,
@mkhoussid
mkhoussid / App.tsx
Last active November 16, 2020 07:10
ThemeProvider with useContext
/////////////////////////////////////////////////////////////////////////////
// https://codesandbox.io/s/inspiring-thunder-dzyi8?file=/src/index.tsx:0-274
/////////////////////////////////////////////////////////////////////////////
import * as React from "react";
import { Button } from "components/ui";
import { ThemeContext } from "contexts/ThemeContext";
import { themes } from "utils/theme";
import { Container, Label, RadioInputStyled } from "components/styled/App";