Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
@prateekbh
prateekbh / app.jsx
Last active July 24, 2019 21:50
How to get pre-rendered data in `routes` folder components
import { h, Component } from 'preact';
import { Router } from 'preact-router';
import { Provider } from '@preact/prerender-data-provider';
import Home from './routes/home';
import Route66 from './routes/route66';
import Custom from './routes/custom';
import './style.css';
export default class App extends Component {
handleRoute = e => {

Preact + Material-UI example

Preact is a fast 3kB alternative to React with the same modern API.

This example uses shows how to use Material UI 4 with Preact X and Preact CLI 3.

How to use

git clone blah preact-mui
@tannerlinsley
tannerlinsley / remove-linkin-connections.js
Created July 12, 2019 15:43
A script for removing LinkedIn connections automatically
function removeFirstConnection () {
$('[type=ellipsis-horizontal-icon]').first().click()
setTimeout(() => {
$('.js-mn-connection-card__dropdown-delete-btn > button').click()
setTimeout(() => {
$('[data-control-name="confirm_removed"]').click()
}, 250)
}, 250)
}
@domenic
domenic / engine-ua-sniffer.js
Last active September 6, 2019 16:40
Rendering engine UA sniffer
// This is a minimal UA sniffer, that only cares about the rendering/JS engine
// name and version, which should be enough to do feature discrimination and
// differential code loading.
//
// This is distinct from things like https://www.npmjs.com/package/ua-parser-js
// which distinguish between different branded browsers that use the same rendering
// engine. That sort of distinction is maybe useful for analytics purposes, but
// for differential code loading it is overcomplicated.
//
// This is meant to demonstrate that UA sniffing is not really that hard if you're
/** Converts destructured parameters with default values to non-shorthand syntax, fixing Edge 16 & 17. */
module.exports = (babel, options = {}) => {
const { types: t } = babel;
const isArrowParent = p => p.parentKey=='params' && p.parentPath && p.parentPath.isArrowFunctionExpression();
return {
name: "transform-edge-default-parameters",
visitor: {
AssignmentPattern(path) {
@pl12133
pl12133 / preact-upgrade-experience.md
Last active June 13, 2019 05:42
Preact@8 to Preact@10 Upgrade Notes

PreactX Upgrade Experience

Obvious breaking changes

See release 10.0.0-alpha.0 for a full list.

  • h -> createElement
  • VNode.nodeName -> VNode.type
  • VNode.attributes -> VNode.props
  • VNode.children -> VNode.props.children
# scaffold your project
npx preact-cli@rc create default my-app && cd my-app
# upgrade to Preact X
npm i -D preact-cli@rc && npm i preact@latest preact-router@latest preact-render-to-string@latest
npm rm preact-compat
<!DOCTYPE html>
<html>
<head>
<title>Demo: Treat Safari 11 and Prior as nomodule</title>
</head>
<body>
<script>
if (/Safari\/5/.test(navigator.userAgent)) {
var $fss = function () {
for (var i of document.scripts) {
// import fetch from 'isomorphic-unfetch';
const RETRIES = 5;
/**
* Example:
* global.fetch = fetchWithRetry;
*/
function fetchWithRetry(url, options) {
const {useCallback, useEffect, useReducer, useRef} = require('react');
let effectCapture = null;
exports.useReducerWithEmitEffect = function(reducer, initialArg, init) {
let updateCounter = useRef(0);
let wrappedReducer = useCallback(function(oldWrappedState, action) {
effectCapture = [];
try {
let newState = reducer(oldWrappedState.state, action.action);