Skip to content

Instantly share code, notes, and snippets.

View nilsandrey's full-sized avatar
🏠

Nils nilsandrey

🏠
View GitHub Profile
@nilsandrey
nilsandrey / atcb-adapter.scss
Created September 16, 2022 02:26
Archivo para personalizar el export to calendar
body {
@media (max-width: 900px) {
div.atcb_list {
width: 100% !important;
left: 0 !important;
border-radius: 0 !important;
bottom: 0 !important;
top: unset !important;
div.atcb_list_item {
@nilsandrey
nilsandrey / react-useTimeout.hook.js
Last active May 2, 2024 02:52
React useTimeout hook (by Chris Bongers)
// From <https://dev.to/dailydevtips1/react-cleaner-use-of-settimeout-105m>
import { useCallback, useEffect, useRef, useMemo } from 'react';
/**
* To use the hook
* ```
* import useTimeout from './useTimeout';
*
* const [timeout] = useTimeout(() => {
* setShow(false);
@nilsandrey
nilsandrey / gist:99f9a9eaf809dcaea5cb748b1563a778
Created July 6, 2022 02:59 — forked from Mikodes/gist:be9b9ce42e46c3d4ccb6
All Media queries for resolutions
/* (320x480) iPhone (Original, 3G, 3GS) */
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
/* insert styles here */
}
/* (320x480) Smartphone, Portrait */
@media only screen and (device-width: 320px) and (orientation: portrait) {
/* insert styles here */
}
@nilsandrey
nilsandrey / Instatext.bookmarklet.js
Created June 17, 2022 05:54
A bookmarklet for showing the current URL in Instapaper reader mode (twitter threads are rolled up!)
javascript:function iptxt(){var d=document;try{if(!d.body)throw(0);window.location='http://www.instapaper.com/text?u=%27+encodeURIComponent(d.location.href);}catch(e){alert(%27Please wait until the page has loaded.%27);}}iptxt();void(0)
@nilsandrey
nilsandrey / Layout1.tsx
Last active May 5, 2022 06:58
NextJS page layouts
import React from 'react';
function Layout1({ children }) {
return (
<>
<main>{children}</main>
<footer>
By you
</footer>
</>
@nilsandrey
nilsandrey / Lan.tsx
Created May 3, 2022 20:30
i18n useTranslation().t wrapper with placeholder loader from MUI
import { Skeleton } from '@mui/material';
import { useTranslation } from 'next-i18next';
import * as React from 'react';
export interface Props {
textId: string;
width?: string;
}
/**
@nilsandrey
nilsandrey / countTwitterShares.js
Last active May 2, 2024 02:54
How many times a web link has been shared on Twitter
// <https://www.barattalo.it/coding/how-many-times-a-web-link-has-been-shared-on-twitter/>
function readTwitterShares($url) {
$s = file_get_contents("http://urls.api.twitter.com/1/urls/count.json".
"?callback=?&url=".urlencode($url));
preg_match("#(\"count\"):([0-9]*)#",$s,$ar);
return isset($ar[2]) ? $ar[2] : 0;
}
echo readTwitterShares("https://www.nationalgeographic.com/science/article/a-psychedelic-surprise-may-be-thriving-in-your-local-garden");
@nilsandrey
nilsandrey / next.config.js
Last active May 2, 2024 02:59
Use of config.resolve.alias in NextJS config
// Copied for easier bookmarking from <https://github.com/vercel/next.js/issues/706#issuecomment-569041997> by @Lwdthe1
// next.config.js
const aliasPathsToResolve = [
{ name: 'components', path: path.resolve(__dirname, './components') },
{ name: 'Common', path: path.resolve(__dirname, '../../common/react/') },
]
module.exports = () => {
return {
webpack(config, { defaultLoaders }) {
config.module.rules.push({
@nilsandrey
nilsandrey / Date.ext.ts
Last active April 22, 2022 05:09
Extensions to the TypeScript Date class to work with diferences to a future date.
export {};
/**
* Extensions to the Typescript Date class.
*/
declare global {
/**
* Extension members declarations.
*/
interface Date {
@nilsandrey
nilsandrey / HN Avatars.js
Created April 20, 2022 05:29
User script to add avatars to HackerNews pages. Taken from "Show HN".
let observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry, i) => {
if (entry.isIntersecting) {
const p = 2;
const c = document.createElement('canvas');
const x = c.getContext('2d');
c.width = 18;
c.height = 14;
const s = entry.target.innerText;