Skip to content

Instantly share code, notes, and snippets.

@herablog
herablog / cwv-report-to-slack-gas.js
Last active January 10, 2024 09:01
CWV (Core Web Vitals) Report to Slack with CrUX API
/**
* This is an example code for Google App Script
* You can run this script with time-driven triggers
* @see https://developers.google.com/apps-script/guides/triggers/installable#time-driven_triggers
*/
// Settings
const CRUX_ORIGINS = []; // e.g. https://example.com
const CRUX_METRICS = ['first_input_delay', 'largest_contentful_paint', 'cumulative_layout_shift']; // first_contentful_paint, first_input_delay, largest_contentful_paint, cumulative_layout_shift
const CRUX_FORM_FACTOR = ['PHONE', 'DESKTOP']; // ALL_FORM_FACTORS, PHONE, DESKTOP, TABLET
@tracker1
tracker1 / MyComponent.jsx
Last active July 8, 2019 12:48
Simple pattern for loading async data with react, redux and redux-thunk middleware
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as Actions from './action';
const mapStateToProps = ({ loaded, loading, error, data }) = ({ loaded, loading, error, data });
const mapDispatchToProps = dispatch => ({ action: bindActionCreators(Actions, dispatch) });
export class MyComponent extends Component {
load = _ => this.props.action.load(this.props.id);
@shirakaba
shirakaba / setup.md
Last active May 16, 2024 13:57
Configuring Nexus as a private registry for npm packages

Get the details to connect to your Nexus-managed npm repository

Note: Nexus group repositories (good example in this StackOverflow question) are out of this tutorial's scope. In any case, deployment to group repositories is currently still an open issue for Nexus 3 (and not intended ever to be implemented in Nexus 2). Thus, it is assumed that we'll push & pull to/from the same repository, and ignore the idea of groups hereon in.

  1. Ask your sysadmin for a username & password allowing you to log into your organistation's Nexus Repository Manager.

  2. Test the login credentials on the Nexus Repository manager at: http://localhost:8081/nexus/#view-repositories (localhost in our case is replaced by a static IP, and can only be connected to over VPN). If your organisation requires a VPN to connect to it, connect to that VPN before proceeding with this tutori

@coryhouse
coryhouse / promise.js
Last active May 1, 2019 08:55
Promise example
getPosts().then( posts => {
console.log(posts.length);
});
function getPosts() {
return fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => {
return response.json();
})
.catch( error => console.log(error));
@coryhouse
coryhouse / async.js
Created October 15, 2017 09:53
Async/Await example
getPosts().then(posts => {
console.log(posts.length);
});
async function getPosts() {
try {
const response = await fetch("https://jsonplaceholder.typicode.com/posts");
return response.json();
} catch(error) {
console.log(error);
// routes.js
const routes = [
{
path: '/',
component: Home,
exact: true
},
{
path: '/gists',
component: Gists
@adamreisnz
adamreisnz / package.json
Last active January 19, 2024 13:01
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Reis",
"url": "http://adam.reis.nz"
},
"license": "UNLICENSED",
@badcrocodile
badcrocodile / detectAdsLoaded.js
Created August 20, 2015 18:41
Detect when Google Ads API is loaded and when ads are ready and loaded in the DOM
window.googletag = window.googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(detectAdLoad);
function detectAdLoad() {
/**
* NOTE: This function depends on the ad slot ID (var targetSlot). If this changes, this function will break
*
* Patched together using documentation at https://developers.google.com/doubleclick-gpt/reference
@ademilter
ademilter / font-face-builder.scss
Last active September 19, 2020 19:23
font-face builder
$font-family: (
group: serif,
id: regular,
name: 'Equity Regular',
fallback: (georgia, serif),
weight: normal,
style: normal,
file-name: 'equity_text_b_regular-webfont'
), (
group: serif,
@girlcheese
girlcheese / gist:29acea17ba606b01153c
Last active June 12, 2020 03:31
slotRenderEnded listener event (DFP)
googletag.pubads().addEventListener("slotRenderEnded", function(event) {
//console.log("googletag slotRenderEnded", event.slot.b.f);
var containerId = "";
// WARN: Fragile access of private object within DFP Slot Object returned with the event
// It's the only way to get access to the id of the DOM element attached to the slot
// FIXME: Ideally we need to contact Google and request a public API method to return the id
if (typeof event.slot !== "undefined") {
if (typeof event.slot.b !== "undefined") {