Skip to content

Instantly share code, notes, and snippets.

View oirodolfo's full-sized avatar
🏳️‍🌈

Rod Kisten (Costa) oirodolfo

🏳️‍🌈
View GitHub Profile
@oirodolfo
oirodolfo / update.js
Created August 22, 2018 17:17
Contentful update for SEO
'use strict';
let contentful = require('contentful-management');
let params = require('../config/default.json').contentful;
let client = contentful.createClient({
accessToken: params.managementToken
});
@oirodolfo
oirodolfo / gist:f10a840099ee979156402dd3d8f6e697
Created September 12, 2018 23:56 — forked from mhaagens/gist:61f88e3fbfddbe2c00708f3ebd099be4
Transition Motion React Router 4 Route Transition
const FadeRoute = ({ component: Component, ...rest }) => {
return (
<Route {...rest} children={({ location, match }) => (
<TransitionMotion
willEnter={() => {return {opacity: 0, translateX: 24}}}
willLeave={() => {return {opacity: spring(0, animationPresets.out), translateX: spring(24)}}}
defaultStyles={[ {
key: location.pathname,
style: { opacity: 0, translateX: 24},
@oirodolfo
oirodolfo / get-latest-tag-on-git.sh
Created September 15, 2018 18:13 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@oirodolfo
oirodolfo / HtmlModuleScriptWebpackPlugin.js
Created September 19, 2018 20:10 — forked from robatwilliams/HtmlModuleScriptWebpackPlugin.js
Plugin to create HTML page which loads ES5 or ES6 build according to browser capability
const { concat, mapKeys, merge, uniq } = require('lodash');
/**
* Tweaked from original by Mike Engel
* https://github.com/jantimon/html-webpack-plugin/issues/782#issuecomment-331229728
*
* Use this with multiple Webpack configurations that generate different builds
* for modern and legacy browsers. But use the same instance of the plugin in both configurations.
*
* It keeps track of assets seen in each build configuration, and appends script tags for
@oirodolfo
oirodolfo / inject-to-global.js
Created September 26, 2018 19:52
Codemod for styled-components V4 migration from injectGlobal to createClobalStyle
const importRenameMap = {
injectGlobal: 'createGlobalStyle'
};
module.exports = function transformer(file, api) {
const j = api.jscodeshift;
let source = file.source;
source = renameInjectGlobalImportWithCreateGlobal(j, j(source)).toSource();
source = renameTagTemplate(j, j(source)).toSource();
@oirodolfo
oirodolfo / lambda-redirect-to-trailing-slash.js
Created October 11, 2018 18:28 — forked from nabilfreeman/lambda-redirect-to-trailing-slash.js
Redirect to trailing slashes on CloudFront with AWS Lambda. (all this because S3 uses 302 redirects instead of 301)
'use strict';
const path = require('path')
exports.handler = (event, context, callback) => {
//get request object
const { request } = event.Records[0].cf
const url = request.uri;
@oirodolfo
oirodolfo / updateHeightRAF.js
Created November 29, 2018 21:18 — forked from NoamELB/updateHeightRAF.js
update height with request animation frame
updateHeight(isOpen) {
this.lastRAF && cancelAnimationFrame(this.lastRAF);
if (isOpen) {
this.lastRAF = requestAnimationFrame(() => {
// read:
const height =`${this.contentEl.scrollHeight}px`;
this.lastRAF = requestAnimationFrame(() => {
// write in a different frame:
this.containerEl.style.height = height;
this.lastRAF = null;
@oirodolfo
oirodolfo / propubnerd-gists.md
Created December 5, 2018 20:25 — forked from kleinmatic/propubnerd-gists.md
ProPubNerd Gists

Open Source code doesn’t always come in big complex packages. At ProPublica we sometimes share small, simple snippets of using GitHub "Gists." These Gists range from single-byte file delimiters to an entire JavaScript framework for making stepper graphics. They rarely have documentation and don’t even always have names, but they can be super-useful. Here are some we’ve shared over the past few years:

@oirodolfo
oirodolfo / .eslintrc.js
Created July 12, 2019 19:11 — forked from nikgraf/.eslintrc.js
Prettier / Eslint Setup
module.exports = {
root: true, // make to not take in any user specified rules in parent folders
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/flowtype', 'prettier/react'],
env: {
browser: true,
node: true,
jest: true,
},
plugins: ['flowtype'],
@oirodolfo
oirodolfo / bookmarklet.js
Created March 23, 2020 19:46 — forked from brumm/bookmarklet.js
Find out which element is scrolling
javascript:!function() { var slice = Array.prototype.slice; function throttle(type, name, obj) { obj = obj || window; var running = false; var func = function() { if (running) { return; } running = true; requestAnimationFrame(function() { obj.dispatchEvent(new CustomEvent(name)); running = false; }); }; obj.addEventListener(type, func); } slice .call(document.querySelectorAll("*")) .filter( e => e.scrollWidth > e.offsetWidth || e.scrollHeight > e.offsetHeight ) .filter(e => { var style = window.getComputedStyle(e); return [style.overflow, style.overflowX, style.overflowY].some( e => e === "auto" || e === "scroll" ); }) .forEach(e => { var color = Math.floor(Math.random() * 16777215).toString(16); e.style.backgroundColor = "#" + color; throttle("scroll", "optimizedScroll", e); e.addEventListener("scroll", event => { console.log("%c[scroll]", "color: white; background-color:#" + color, event.target); }); }); }()