This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chalk = require("chalk"); | |
const packages = [ | |
require("./package.json"), | |
require("./packages/cec-scripts/package.json"), | |
require("./packages/generator-cec/package.json"), | |
require("./packages/utility-cec-simulator/package.json") | |
]; | |
const compareDeps = p => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extends the return of the HTTPError class | |
class HTTPError extends Error { | |
readonly response: any; | |
readonly status: number; | |
readonly statusText: string; | |
constructor(status: number, statusText: string, response: any) { | |
super(statusText); | |
this.status = status; | |
this.statusText = statusText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _toQueryString = params => | |
`?${Object.entries(params) | |
.map( | |
([key, value]) => | |
`${encodeURIComponent(key)}=${encodeURIComponent(value)}` | |
) | |
.join("&")}`; | |
// EDIT here if you prefer a storage implementation or a store subscription etc. | |
// you could actually also remove the getToken function and directly call it in the header below |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react" | |
import tw from "twin.macro" | |
const bearerToken = | |
process.env.SANITY_STUDIO_TWITTER_API_BEARER_TOKEN | |
const CustomTweetPreview = ({ value: { id } }) => { | |
const [tweet, setTweet] = useState(null) | |
const [error, setError] = useState(null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react" | |
export default function useFocusNextOnEnter() { | |
const formRef = useRef() | |
const isForm = node => Boolean(node.nodeName === "FORM") | |
const handleKeyPress = e => { | |
if (e.key === "Enter" || e.keyCode === 13) { | |
const form = e.target.form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pascalCasePattern = /([A-Z]+[a-z]*)+\b/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawImageScaled({ context, image }) { | |
const canvas = context.canvas | |
const hRatio = canvas.width / image.width | |
const vRatio = canvas.height / image.height | |
const ratio = Math.min(hRatio, vRatio) | |
const centerShift_x = (canvas.width - image.width * ratio) / 2 | |
const centerShift_y = (canvas.height - image.height * ratio) / 2 | |
context.clearRect(0, 0, canvas.width, canvas.height) | |
context.drawImage( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Tested on php 7.2.11 and chrome 80 | |
function console_log(...$args) | |
{ | |
$args_as_json = array_map(function ($item) { | |
return json_encode($item); | |
}, $args); | |
$js_code = "<script>console.log( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { applyMiddleware, compose, createStore } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import rootReducer from './src/reducers'; | |
const loadDevTools = () => | |
process.env.NODE_ENV === 'development' && typeof window !== 'undefined' && window.devToolsExtension | |
? window.__REDUX_DEVTOOLS_EXTENSION__ && | |
window.__REDUX_DEVTOOLS_EXTENSION__() |