Skip to content

Instantly share code, notes, and snippets.

View rubennorte's full-sized avatar

Rubén Norte rubennorte

View GitHub Profile
@rubennorte
rubennorte / Base source: test.js
Last active June 7, 2018 12:52
Babel bug for-of vs block-scoping (loose)
for (let result of results) {
result = otherValue;
fn(() => {
result;
});
}

This gist reproduces a bug in Yarn v0.27.5.

The bug is caused by Yarn returning exit status 0 when a script inside the package.json "scripts" causes a segmentation fault.

This only happens when there is a single command in the script (e.g.: "test": "./segfault"). When there are several commands in the script (e.g.: "test-alt": "true && ./segfault") it returns an exit status 1.

This bug causes errors to be unnoticed in CI builds, where everything seems to be OK.

Steps to reproduce:

@rubennorte
rubennorte / domains-and-promises.js
Last active May 19, 2017 14:01
Domains & Promises
var domain = require('domain');
var d = domain.create();
// Example 1: callback style
d.run(() => {
console.log('Initial domain is', process.domain);
setTimeout(() => {
console.log('Final domain is', process.domain); // good
}, 1000);
});
@rubennorte
rubennorte / execute-sequentially.js
Created May 19, 2015 21:05
Sequential promises
function executeSequentially(promises) {
return promises.reduce(function (result, promise) {
return result.then(promise);
}, Promise.resolve());
}
@rubennorte
rubennorte / SassMeister-input-HTML.html
Last active August 29, 2015 14:14
Generated by SassMeister.com.
<ul class="customers">
<li>John Doe</li>
<li>Jane Dane</li>
<li class="special-customer">
<img class="special-customer-photo" src="//placehold.it/150x150">
<div class="special-customer-info">
<p>Jack Jackson</p>
<p>Wallaby St, 42, Sydney</p>
</div>
@rubennorte
rubennorte / class-property-inheritance.js
Created August 19, 2014 19:40
Demostration of how to inherit class properties in JavaScript
function assert(condition, message) {
if (!condition) {
throw new Error(message || "Assertion failed");
}
}
var setPrototypeOf = (function () {
if (Object.setPrototypeOf) {
return Object.setPrototypeOf;
} else {
@rubennorte
rubennorte / mixin-initialization.js
Created July 5, 2014 02:43
Initializing Backbone mixins
var Class = Backbone.Model; // or Collection or View or Router
var MixinInitializerClass = Class.extend({
initialize: function() {
/* Other code */
this.initializeMixins();
},
initializeMixins: function() {
var self = this;
var functions = _.functions(this);
/*
* Script to cheat SpeedSums.com test
*/
function getResult(expression){
var regex = /\s*(\d+)\s*([^\s])\s*(\d+)/;
var matches = regex.exec(expression);
if (matches){
var x = parseInt(matches[1], 10),