Skip to content

Instantly share code, notes, and snippets.

View mdarens's full-sized avatar
🎯
Focusing

Mark D'Arensbourg mdarens

🎯
Focusing
  • New Orleans
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mdarens
mdarens / getRevalidationStrategyByDay.ts
Last active July 7, 2021 21:39
Next.js revalidation strategy for routes associated with dates
import { differenceInCalendarDays } from "date-fns";
const buildDate = new Date();
// starting at 1 minute, add a minute to the revalidation
// for each additional day in the past/future.
// for example, a page associated with a date today, tomorrow or yesterday would refetch when stale by a minute.
// one a week in the past or future would only revalidate every 7 minutes,
// and one a month out would revalidate on the half hour.
// the assumption here is that events, posts and other entities with
@mdarens
mdarens / urlcat.d.ts
Last active February 25, 2021 16:35
urlcat types where params can be inferred from path template
declare module "urlcat" {
type PathTemplateTokens<
Rte
> = Rte extends `${string}/:${infer P}/${infer Rest}`
? P | PathTemplateTokens<`/${Rest}`>
: Rte extends `${string}/:${infer P}`
? P
: never;
function urlcat<
@mdarens
mdarens / index.html
Last active August 29, 2015 14:24 — forked from anonymous/index.html
client server connection animation http://output.jsbin.com/dubemogole
<!DOCTYPE html>
<html>
<head>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
svg {
width: 3em;
height: 1em;
@mdarens
mdarens / index.jsx
Created June 19, 2015 20:59
React.js highlight on change component
var React = require("react");
var cx = require("classnames");
var _ = require("lodash");
require("./index.less");
var HighlightOnChange = React.createClass({
propTypes: {
subscribeTo: React.PropTypes.any.isRequired,
component: React.PropTypes.any,
@mdarens
mdarens / bs-tooltip-extended.less
Created June 19, 2015 16:31
quick and dirty extended bootstrap tooltips
@import "PATH/TO/bootstrap/less/variables.less";
.tooltip {
.tooltip-inner {
.classisize-inner(~"danger");
.classisize-inner(~"success");
.classisize-inner(~"warning");
.classisize-inner(~"info");
}
.tooltip-arrow {
@mdarens
mdarens / colorize-svg
Created March 6, 2015 21:58
Colorize an SVG in Less and inline it
// adds fill attribute to all g, polygon, path and rect children of an SVG string,
// assuming you have stripped the fill attributes already
.colorize-svg(@svg: "", @cl-fill: currentColor) {
@colorized-svg: replace(@svg, '(<g\s|<polygon\s|<path\s|<rect\s)', '$1fill="@{cl-fill}" ', 'g');
}
// You don't have to base64 SVGs unless you've embedded some binary images in them
// See https://css-tricks.com/probably-dont-base64-svg/
.make-svg-data-url(@svg: "") {
@mdarens
mdarens / keybase.md
Created September 23, 2014 16:30
keybase.md

Keybase proof

I hereby claim:

  • I am mdarens on github.
  • I am mdarens (https://keybase.io/mdarens) on keybase.
  • I have a public key whose fingerprint is 1579 EADF BA25 F3FE 7343 9DB5 F148 D874 46FA C492

To claim this, I am signing this object:

@mdarens
mdarens / amino-acid-scrape
Created June 29, 2014 00:46
Scrape the amino acid profile from a page on nutritiondata.self.com
var selectors = [];
for (var i = 77; i <= 96; i+=1) {
selectors.push('#NUTRIENT_'+i);
}
var proteinAmounts = [];
$.each(selectors, function(idx, sel) {
proteinAmounts.push($(sel).text());
});
proteinAmounts;
@mdarens
mdarens / jsbin.epigUFu.html
Created December 23, 2013 22:48
Wrappin queries
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<h1>Wrappin Queries</h1>