Skip to content

Instantly share code, notes, and snippets.

View montogeek's full-sized avatar

Fernando Montoya montogeek

View GitHub Profile
@humitos
humitos / spotify-noads.py
Last active February 21, 2021 03:12
Remove Ads from Spotify Linux client by mutting the audio system
# -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@Rich-Harris
Rich-Harris / module-loading.md
Last active April 19, 2023 09:11
Dynamic module loading done right

Dynamic module loading done right

Follow-up to Top-level await is a footgun – maybe read that first

Here are some things I believe to be true:

  1. Static module syntax is beneficial in lots of ways – code is easier to write (you get better linting etc) and easier to optimise (tree-shaking and other things that are only really possible with static syntax), and most importantly, faster to load (it's trivial for a module loader to load multiple dependencies concurrently when they're declared with a static syntax – not so with imperative statements like require(...) or await import(...)).
  2. App startup time is perhaps when performance is most critical. (You already know this, I don't need to cite the studies.)
  3. If you're in favour of constructs that jeopardise app startup time, you are anti-user. Top-level await is such a construct.
@Rich-Harris
Rich-Harris / footgun.md
Last active March 9, 2025 06:13
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@MoOx
MoOx / solution1.js
Created September 8, 2016 22:16
avoid "windows is undefined" error when in node for React component
import React, { Component } from "react"
import styles from "./index.css"
export default class Hero extends Component {
componentDidMount() {
if (typeof window !== "undefined") {
require("particles.js").particlesJS.load("particles-js", "assets/particles.json", function() {
console.log("callback - particles.js config loaded")
const ABORTABLE_ERROR_KEY = '__abortablePromise';
/**
* @typedef {Promise.<*>} AbortablePromise
*
* @property {function} abort Additional method for abort original promise
*/
/**
*

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

var attrsToRemove = {
'[ng-bind]': 'ng-bind',
'[ng-repeat]': 'ng-repeat',
'[ng-bind-html]': 'ng-bind-html',
'[ng-controller]': 'ng-controller',
'[ng-if]': 'ng-if',
'[ng-class]': 'ng-class',
'[ng-click]': 'ng-click',
'[ng-show]': 'ng-show',
'[ng-hide]': 'ng-hide',
@leebyron
leebyron / maybeFilter.js
Last active June 29, 2016 08:34
An array filter function which does not create a new array if no items are removed.
function maybeFilter(array, predicate) {
var newArray;
array.forEach((item, i) => {
if (predicate(item)) {
if (newArray) {
newArray.push(item)
}
} else if (!newArray) {
newArray = array.slice(0, i)
}
@jed
jed / handler.js
Created May 16, 2016 16:30
Break Bot: pushing AWS IoT button events to Slack
'use strict'
// for context, see https://twitter.com/jedschmidt/status/732244756491816960
const https = require('https')
const qs = require('querystring')
const WEBHOOK_PATH = '/services/YOUR_WEBHOOK_PATH_HERE'
const EVENTS_BY_CLICKTYPE = {
SINGLE : {emoji: ':coffee:', type: 'beverages'},
@jennifer-shehane
jennifer-shehane / cypress_example_spec.js
Last active December 4, 2017 11:47
Selenium versus Cypress.io
describe('Kitchen Sink', function(){
it('cy.should - assert that <title> is correct', function(){
cy
.visit('https://example.cypress.io/')
.title().should('include', 'Kitchen Sink')
})
context('Querying', function(){
beforeEach(function(){
cy.visit('https://example.cypress.io/commands/querying')