Skip to content

Instantly share code, notes, and snippets.

View Young-Einstein10's full-sized avatar

Abdulrahman Yusuf Young-Einstein10

View GitHub Profile
@Young-Einstein10
Young-Einstein10 / _app.js
Created October 22, 2023 06:50 — forked from claus/_app.js
Restore scroll position after navigating via browser back/forward buttons in Next.js
import useScrollRestoration from "utils/hooks/useScrollRestoration";
const App = ({ Component, pageProps, router }) => {
useScrollRestoration(router);
return <Component {...pageProps} />;
};
export default App;
function convertToDownloadUrl(imgSrc) {
var imageData = atob(imgSrc.split(",")[1]);
var arrayBuffer = new ArrayBuffer(imageData.length);
var view = new Uint8Array(arrayBuffer);
for (var i = 0; i < imageData.length; i++) {
view[i] = imageData.charCodeAt(i) & 0xff;
}
var blob = new Blob([arrayBuffer], { type: "application/octet-stream" });
var url = (window.webkitURL || window.URL).createObjectURL(blob);
@Young-Einstein10
Young-Einstein10 / reset.css
Created June 24, 2022 11:57 — forked from EllyLoel/reset.css
CSS Reset
/*
Made by Elly Loel - https://ellyloel.com/
With inspiration from:
- Josh W Comeau - https://courses.joshwcomeau.com/css-for-js/treasure-trove/010-global-styles/
- Andy Bell - https://piccalil.li/blog/a-modern-css-reset/
- Adam Argyle - https://unpkg.com/open-props@1.3.16/normalize.min.css / https://codepen.io/argyleink/pen/KKvRORE
Notes:
- `:where()` is used to lower specificity for easy overriding.
*/
@Young-Einstein10
Young-Einstein10 / convertToFormData.js
Last active January 26, 2022 14:56
function to convert nested object with to FormData, works for objects containing File Instance also.
function convertToFormData(data, formData?: FormData, parentKey?: any) {
if (data === null || data === undefined) return null;
formData = formData || new FormData();
if (
typeof data === "object" &&
!(data instanceof Date) &&
!(data instanceof File)
) {
/**
* Question:
* Given an `nums` and value `val`, write a function to remove all
* instances of val from the array and return the new length.
*
*
* Example: if nums = [5, 2, 2, 5, 3], your function should return 3.
*/
const removeInstaces = (nums, val) => {
/**
* Question:
* Given a sorted array `nums`, write a function to remove the
* duplicates from the array such that each element appears only once.
* Your function should return the new length.
*
*
* Example: if nums = [0, 0, 1, 1, 2, 2, 3, 3, 4], Your function should return 5.
*/