Skip to content

Instantly share code, notes, and snippets.

@neenhouse
neenhouse / ab-testing.spec.ts
Last active January 19, 2024 15:18
Simple AB Testing
import {describe, beforeEach, test, expect, jest} from '@jest/globals';
import {v4 as uuidv4} from 'uuid';
import {calculateBucket} from '../ab-testing';
function generateVisitorUuid(): string {
return uuidv4().replace(/-/g, '');
}
describe('ab-testing', () => {
@neenhouse
neenhouse / src-property-index.html
Created June 1, 2020 15:38
Federated AppShell
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://localhost:3001/remoteEntry.js"></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
@neenhouse
neenhouse / src-appshell-webpack.config.js
Last active June 10, 2020 03:45
Federated AppShell
module.exports = {
// ...
plugins: [
new ModuleFederationPlugin({
name: "appshell",
library: { type: "var", name: "appshell" },
filename: "remoteEntry.js",
remotes: {},
exposes: {
module.exports = {
// ...
plugins: [
new ModuleFederationPlugin({
name: 'property',
library: {type: 'var', name: 'property'},
filename: 'remoteEntry.js',
remotes: {
appshell: 'appshell'
},
@neenhouse
neenhouse / src-property-app.jsx
Created June 1, 2020 15:30
Federated AppShell
import React from "react";
import { HashRouter } from "react-router-dom";
const AppShell = React.lazy(() => import("appshell/StandardLayout"));
import {Photos} from './Photos';
function App() {
return (
<HashRouter>
import React from 'react';
import App from './App';
import PropTypes from 'prop-types';
function StandardLayout({title, children}) {
return <App title={title}>{children}</App>;
}
StandardLayout.propTypes = {
title: PropTypes.string,
@neenhouse
neenhouse / src-appshell-App.jsx
Last active June 1, 2020 15:26
Federated AppShell
import React from 'react';
import PropTypes from 'prop-types';
import {HashRouter} from 'react-router-dom';
import {Header} from './Header';
import {Footer} from './Footer';
import './App.less';
function App({children}) {
return (
<HashRouter>
@neenhouse
neenhouse / Ponies
Created September 1, 2017 15:11
Ponies
(function(){
var basePonyConfig = document.createElement('script');
basePonyConfig.setAttribute('src','https://panzi.github.io/Browser-Ponies/browserponies.js');
basePonyConfig.setAttribute('id','browser-ponies-script');
document.head.appendChild(basePonyConfig);
var ponyScript = document.createElement('script');
ponyScript.setAttribute('src','https://panzi.github.io/Browser-Ponies/basecfg.js');
ponyScript.setAttribute('id','browser-ponies-script');
document.head.appendChild(ponyScript);
function init(){
window.$ = $;
function $(s) {
let c = {
'#': 'ById',
'.': 'sByClassName',
'@': 'sByName',
'=': 'sByTagName'}[s[0]];
return document[c?'getElement'+c:'querySelectorAll'](s.slice(1));
}