Skip to content

Instantly share code, notes, and snippets.

View mpacary's full-sized avatar

Maxime Pacary mpacary

  • Grenoble, France
View GitHub Profile

Remix's useFetcher doesn't return a Promise for any of its methods (like fetcher.submit()) because Remix doesn't want you to explicitly await anything so they can handle things like cancellation for you. Instead, they recommend adding a useEffect and performing whatever logic you need to after the fetcher is in a particular state.

I found using an effect to run some logic after a submission to be too indirect, and there seem to be plenty of cases where you want to submit a form and then perform some other work on the client (sometimes async, like requesting the user's permission for their location), and I'd rather just do that after a submission in the event handler rather than an effect.

So here's a proof of concept hook that wraps Remix's useFetcher and returns a version of submit that is a promise, and resolves with the data from the action:

function useFetcherWithPromise() {
  let resolveRef = useRef();
  let promiseRef = useRef();
@jhochwald
jhochwald / Get-MicrosoftCloudTenantInfo.ps1
Created January 31, 2018 14:56
Check if a given Name is availible as Office365/Azure Tenant Name and optional return the Tenant ID if the Tenant exists.
function Get-MicrosoftCloudTenantInfo
{
<#
.SYNOPSIS
Check if a given Name is availible as Office365/Azure Tenant Name
.DESCRIPTION
Check if a given Name is availible as Office365/Azure Tenant Name and optional return the Tenant ID if the Tenant exists.
.PARAMETER name
@ypelletier
ypelletier / RFID_LEDS.ino
Last active March 23, 2020 22:48
Exemple d'utilisation de la bibliothèque MFRC522 par Miguel Balboa
/*******************************************************************************
RFID LEDs
Exemple d'utilisation de la bibliothèque MFRC522 par Miguel Balboa
Lorsque le tag RFID est accepté, une LED verte s'allume pendant 3 secondes
Lorsque le tag RFID est refusé, une LED rougeo s'allume pendant 3 secondes
Pour plus de détails:
@dmitrythaler
dmitrythaler / JSON.replacer.js
Created March 27, 2017 12:49
replacer function for the JSON.stringify() with depth and duplicates control
const replacer = function( depth = Number.MAX_SAFE_INTEGER ) {
let objects, stack, keys;
return function(key, value) {
// very first iteration
if (key === '') {
keys = ['root'];
objects = [{keys: 'root', value: value}];
stack = [];
return value;
}

How you can help reduce node_modules bloat

This recent reddit thread reveals discontent among the web development community about the sheer volume of stuff in a typical node_modules dir. 140MB in this case!

Is it a design flaw in npm?

Opinions in the thread varied from "I'm surprised npm even works" to "everything is fine". I'm not going to offer an opinion, just these two observations:

  1. node_modules dirs typically do contain lots of stuff that doesn't need to be there.
  2. The latest version mitigates overall size by flattening the dependency tree, but some of the bloat is beyond npm's control.
@cmatskas
cmatskas / GitDeleteCommands.ps1
Last active September 22, 2022 07:59
Git Delete Branch commands
## Delete a remote branch
$ git push origin --delete <branch> # Git version 1.7.0 or newer
$ git push origin :<branch> # Git versions older than 1.7.0
## Delete a local branch
$ git branch --delete <branch>
$ git branch -d <branch> # Shorter version
$ git branch -D <branch> # Force delete un-merged branches
## Delete a local remote-tracking branch
@joepie91
joepie91 / delay-promise.js
Last active July 29, 2022 20:02
ES6 Promise.delay
module.exports = function(duration) {
return function(){
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve();
}, duration)
});
};
};
@diyan
diyan / nodejs_generator_runners.md
Last active September 25, 2016 08:55
Evaluate how different ES6 generator runners (Q, Bluebird and Co) behaves with buggy code

Evaluate how different ES6 generator runners (Q, Bluebird and Co) behaves with buggy code

  • NodeJS v5.6.0
  • q@1.4.1
  • bluebird@3.3.1
  • co@4.6.0
var Q = require('q');
var bluebird = require('bluebird');
var co = require('co');
@balupton
balupton / README.md
Last active April 29, 2019 11:57
DocPad: Use DocPad, GitHub & Prose as a Wiki

Use DocPad, GitHub and Prose as a Wiki

This guide will walk you through how you can use a GitHub repository to house your wiki content, have DocPad render it, and automatically update on changes. It's also really nice as we get to benefit from the github project workflow for our wiki, that is issues, pull requests, etc.

We use this workflow heavily by linking the DocPad Website and the DocPad Documentation repositories allowing us to have users edit and submit pull requests for improvements to our documentation, and once merged, the website regenerates automatically.

1. Create a new repository for your Wiki Content

@domenic
domenic / portable-node.md
Created May 25, 2012 21:03
Tips for Writing Portable Node.js Code

Node.js core does its best to treat every platform equally. Even if most Node developers use OS X day to day, some use Windows, and most everyone deploys to Linux or Solaris. So it's important to keep your code portable between platforms, whether you're writing a library or an application.

Predictably, most cross-platform issues come from Windows. Things just work differently there! But if you're careful, and follow some simple best practices, your code can run just as well on Windows systems.

Paths and URLs

On Windows, paths are constructed with backslashes instead of forward slashes. So if you do your directory manipulation