Skip to content

Instantly share code, notes, and snippets.

View andresgcarmona's full-sized avatar
🎯
Focusing

Andrés G. Carmona andresgcarmona

🎯
Focusing
View GitHub Profile
@andresgcarmona
andresgcarmona / packages
Created August 17, 2023 20:03
Laravel starter packages
composer require spatie/simple-excel
@andresgcarmona
andresgcarmona / useInterval.js
Created July 18, 2023 16:54
Use interval hook
function useInterval(callback, delay) {
const intervalRef = React.useRef(null);
const savedCallback = React.useRef(callback);
React.useEffect(() => {
savedCallback.current = callback;
}, [callback]);
React.useEffect(() => {
const tick = () => savedCallback.current();
@andresgcarmona
andresgcarmona / properties.js
Created July 12, 2023 21:24
Object properties
const obj = {
[Symbol('my_key')] : 1,
enum : 2,
nonEnum : 3
};
Object.defineProperty(obj, 'nonEnum', { enumerable: false }); // Making 'nonEnum' as not enumerable.
// Ignores symbol-valued property keys:
> Object.getOwnPropertyNames(obj)
@andresgcarmona
andresgcarmona / App.js
Last active June 28, 2023 23:26
Reduce React Context Hell
const App = () => {
return (
<MultiProvider
providers={[
<ReduxProvider value={store} />,
<ThemeProvider value={theme} />,
<OtherProvider value={otherValue} />,
<OtherOtherProvider value={otherOtherValue} />,
// ...others,
<HellProvider value={hell} />,
@andresgcarmona
andresgcarmona / GoogleAnalytics.js
Created March 20, 2023 13:36
Load Google Analytics Dynamically
export const GoogleAnalytics = ({ ga_id }) => (
<>
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${ga_id}`}
></script>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
@andresgcarmona
andresgcarmona / detect_low_power_mode.js
Created March 20, 2023 13:22
Video testo for slow power mode
base64 src:
src="data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAACAG1wNDJpc28yYXZjMW1wNDEAAANObW9vdgAAAGxtdmhkAAAAAOA5QnjgOUJ4AAAD6AAAAEMAAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAmt0cmFrAAAAXHRraGQAAAAD4DlCeOA5QngAAAABAAAAAAAAAEMAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAACAAAAAgAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAABDAAAAAAABAAAAAAHjbWRpYQAAACBtZGhkAAAAAOA5QnjgOUJ4AAFfkAAAF3BVxAAAAAAALWhkbHIAAAAAAAAAAHZpZGUAAAAAAAAAAAAAAABWaWRlb0hhbmRsZXIAAAABjm1pbmYAAAAUdm1oZAAAAAEAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAU5zdGJsAAAAznN0c2QAAAAAAAAAAQAAAL5hdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAACAAIABIAAAASAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGP//AAAAMWF2Y0MBTUAo/+EAGWdNQCjspLYC1BgYGQAAAwABAAK/IA8YMZYBAAVo6uEyyAAAABNjb2xybmNseAAGAAYABgAAAAAQcGFzcAAAAAEAAAABAAAAFGJ0cnQAAAAAAAF1IAABdSAAAAAYc3R0cwAAAAAAAAABAAAAAgAAC7gAAAAUc3RzcwAAAAAAAAABAAAAAQAAABxzdHNjAAAAAAAAAAEAAAABAAAAAgAAAAEAAAAcc3RzegAAAAAAAAAAAAAA
@andresgcarmona
andresgcarmona / Singleton.ts
Created March 20, 2023 13:08
Singleton Typescript
export class Singleton {
// Define your props here
private _express: Application = express();
private static _instance: Singleton;
constructor() {
if (Singleton._instance) {
return Singleton._instance;
}
@andresgcarmona
andresgcarmona / pipe.js
Created January 24, 2023 19:03
Javascript pipe function
const pipe = (...fns) => input => fns.reduce(
(acc, fn) => fn(acc), input
)
const formatString = pipe(toUpperCase, removeSpaces, addExclamation)
formatString('Hello World') // HELLOWORLD!
@andresgcarmona
andresgcarmona / dialogMotion.css
Last active January 1, 2023 01:13
Dialog snippets
@media (prefers-reduced-motion: no-preference) {
dialog {
animation: var(--animation-scale-down) forwards;
animation-timing-function: var(--ease-squish-3);
}
dialog[open] {
animation: var(--animation-slide-in-up) forwards;
}
}
function useEventListener(eventName, handler, element = window) {
// Create a ref that stores handler
const savedHandler = useRef();
// Update ref.current value if handler changes.
// This allows our effect below to always get latest handler ...
// ... without us needing to pass it in effect deps array ...
// ... and potentially cause effect to re-run every render.
useEffect(() => {
savedHandler.current = handler;
}, [handler]);