Skip to content

Instantly share code, notes, and snippets.

View marcog83's full-sized avatar

marco gobbi marcog83

View GitHub Profile
@ScriptedAlchemy
ScriptedAlchemy / getOrLoadRemote.js
Last active December 20, 2024 21:14
The Right Way to Load Dynamic Remotes
import { injectScript } from '@module-federation/utilities';
// example of dynamic remote import on server and client
const isServer = typeof window === 'undefined';
//could also use
// getModule({
// remoteContainer: {
// global: 'app2',
// url: 'http://localhost:3002/remoteEntry.js',
// },
// modulePath: './sample'
@marcog83
marcog83 / chunk.js
Last active November 7, 2019 12:13
chunk array elements over a predicate function
var data = [1, 2, 3, 13, 5, 6, 7, 8, 9, 10, 11];
var predicate = element => element % 2 === 0;
function chunk(predicate, data) {
return data.map(predicate).reduce((prev, curr, i, arr) => {
if (curr) {
if (prev.length) {
let first = prev[prev.length - 1][1];
prev.push([first, i + 1]);
} else {
@staltz
staltz / introrx.md
Last active April 19, 2025 05:15
The introduction to Reactive Programming you've been missing
@tantaman
tantaman / polymer-requirejs
Last active April 5, 2018 07:29
polymer + requirejs : originally by Scott Miles from: http://jsbin.com/efojap/2/edit
<!doctype html>
<html>
<head>
<title>Polymer and RequireJS</title>
<script src="http://polymer.github.io/cdn/polymer.min.js"></script>
</head>
<body>
<!-- #foo -->
<div id="foo">the foo has no joy.</div>
@zaphar
zaphar / requirejs-shim-polymer-element
Last active December 23, 2015 02:09
A polymer custom element that can load requirejs modules. You may have to modify the paths to suite your setup.
<polymer-element name="require-js" attributes="libnames event">
<script>
(function() {
// Helper function to add a script.
var addScript = function(src) {
var script = document.createElement('script');
script.src = src;
var s = document.querySelector('script');
s.parentNode.insertBefore(script, s);
return script;
@bgrins
bgrins / detectDataURL.js
Last active March 22, 2025 13:42
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
// Detecting data URLs
// data URI - MDN https://developer.mozilla.org/en-US/docs/data_URIs
// The "data" URL scheme: http://tools.ietf.org/html/rfc2397
// Valid URL Characters: http://tools.ietf.org/html/rfc2396#section2
function isDataURL(s) {
return !!s.match(isDataURL.regex);
}
isDataURL.regex = /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
@briancavalier
briancavalier / promise-monad-proof.js
Created August 8, 2012 15:57
A proof that Promises/A is a Monad
//-------------------------------------------------------------
//
// Hypothesis:
//
// Promises/A is a Monad
//
// To be a Monad, it must provide at least:
// - A unit (aka return or mreturn) operation that creates a corresponding
// monadic value from a non-monadic value.
// - A bind operation that applies a function to a monadic value