Skip to content

Instantly share code, notes, and snippets.

View prince272's full-sized avatar
💭
🧐

Prince Owusu prince272

💭
🧐
View GitHub Profile
@davepcallan
davepcallan / stringEqualsBenchmarks.cs
Created July 31, 2023 09:24
String equals benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
namespace BenchmarkDotNet.Samples
{
[MemoryDiagnoser]
@prince272
prince272 / axiosAuth.js
Last active August 11, 2022 19:30
Inspired by @jetbridge, the http-client.js stores, clears, transmits and automatically refresh JWT authentication tokens. Supports both localstorage and cookie storage.
import Cookies from 'js-cookie';
import { BehaviorSubject } from 'rxjs';
// How to Set Expiry Time (TTL) for LocalStorage With Javascript
// source: https://www.sohamkamani.com/blog/javascript-localstorage-with-ttl-expiry
const createLocalStorage = () => {
return {
get: (key) => {
const itemStr = localStorage.getItem(key);
import {useEffect} from 'react'
import Plyr, {SourceInfo, Options} from 'plyr'
import 'plyr/dist/plyr.css'
const usePlyr = (id: string, sources: SourceInfo, opts?: Options) => {
useEffect(() => {
const el = document.getElementById(id)
const player = new Plyr(el, opts)
player.source = sources
@ux-powered
ux-powered / README.md
Created June 9, 2020 03:35
PhotoSwipe + Swiper integration

The code snippet of PhotoSwipe + Swiper integration. Works for both looped and non-looped sliders.

  1. Create libs/photoswipe/photoswipe-swiper.js
  2. Import the created file in the libs/photoswipe/photoswipe.js and export initPhotoSwipeWithSwiper function
  3. Init PhotoSwipe on the .swiper-wrapper element

Note: You can include libs/photoswipe/photoswipe.js and use both initPhotoSwipeFromDOM() and initPhotoSwipeWithSwiper() functions; or include only libs/photoswipe/photoswipe-swiper.js if you don't need default PhotoSwipe initializer.

@kripod
kripod / Box.tsx
Last active July 19, 2024 05:10
Superseded by https://www.kripod.dev/blog/behind-the-as-prop-polymorphism-done-well/ – Polymorphic `as` prop for React components with TypeScript
import React from 'react';
// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts
type PropsOf<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
E extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>
> = JSX.LibraryManagedAttributes<E, React.ComponentPropsWithRef<E>>;
export interface BoxOwnProps<E extends React.ElementType = React.ElementType> {
as?: E;
@MartinL83
MartinL83 / react-bootstrap-breakpoints.js
Created November 19, 2017 20:47
A simple React HOC to feed css breakpoint data to a component.
import React, { Component } from 'react';
import _ from 'lodash';
/*
HOC to feed breakpoints data to child component.
Breakpoint data is based on Bootstrap's breakpoints
Using lodash throttle to optimize the high rate of events being fired.
*/
export const Breakpoints = (WrappedComponent) => {
@doncadavona
doncadavona / Aes256CbcEncrypterApp.cs
Last active July 1, 2024 14:21
A sample C# class to encrypt and decrypt strings using the cipher AES-256-CBC used in Laravel.
using System;
using System.Text;
using System.Security.Cryptography;
using System.Web.Script.Serialization;
using System.Collections.Generic;
namespace Aes256CbcEncrypterApp {
class MainClass {
public static void Main(string[] args) {
Console.WriteLine("Hello, world!");
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨