Skip to content

Instantly share code, notes, and snippets.

View vvo's full-sized avatar
🌱
Growing indie hacker

Vincent Voyer vvo

🌱
Growing indie hacker
View GitHub Profile
@vvo
vvo / Button.js
Last active October 21, 2015 07:41
Shallow rendering example
import React from 'react';
import Label from './Label';
class Button extends React.Component {
render() {
return <div><Label name={this.props.name} /></div>;
}
}
export default Button;
@vvo
vvo / regenerate-shrinkwrap.md
Created October 16, 2015 21:56
How to regenerate a shrinkwrap with npm@2

As of writing this, npm@3 is out but shrinkwrap as even more issues. Stay with npm@2 for now.

We use shrinkwrap, because https://gist.github.com/vvo/84a94cfc0f94c91ea6b6.

We shrinkwrap both dependencies and devDependencies, otherwise the build and testing is not consistent over time.

To update a package, given all the shrinkwrap weird bugs, you have to:

@vvo
vvo / index.js
Last active October 8, 2015 20:58
Pinning npm dependencies resulting in duplicated code in a build
var woofmark = require('woofmark');
var dragula = require('dragula');
@vvo
vvo / should-I-pin-npm-dependencies?.md
Last active March 8, 2017 22:12
About authoring frontend libraries, building them, publishing to npm and dependencies

You have a nice library published on npm but asking yourselve if you should declare your dependencies as lodash: "3.10.0" (known as "pin" a dependency) or lodash: "^3.10.0"?

As library authors we should not pin dependencies but ask our users to do use npm shrinkwrap in their own app.

Here's why:

Pinning dependencies will result in duplicated code and modules in builds

If you pin your dependencies the issue is that anyone using your module will may not benefit from shared dependencies. If your module user has lodash: "^3.11.0" then since you declared

@vvo
vvo / examples-index.html
Created June 9, 2015 09:40
webpack example
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Title</h1>
<script src="/bundle.js"></script>
</body>
@vvo
vvo / index.js
Last active August 29, 2015 14:17
requirebin sketch
// hello world
var algoliasearch = require('algoliasearch');
var client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76', {protocol: 'http:'});
var query = 'ab';
client.startQueriesBatch();
client.addQueryInBatch(
'contacts', // index name
query, {
@vvo
vvo / index.js
Created March 6, 2015 16:52
requirebin sketch
var AlgoliaSearch = require('algolia-search');
var client = new AlgoliaSearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
var index = client.initIndex('contacts');
index.search('a', function() {
console.log(arguments);
});
@vvo
vvo / index.js
Created December 4, 2014 10:48
requirebin sketch
var test = require('tape');
var jade = require('jade');
test('it should keep whitespace between tags if any', function(t) {
t.plan(1);
var fn = jade.compile('input\ninput');
t.equal(fn(), '<input/> <input/>');
});
@vvo
vvo / gist:44b02018504db10c7f7a
Last active August 29, 2015 14:08
deeply remove "private _properties" of JavaScript objects
function removePrivateProperties(dirty) {
return Object.keys(dirty).reduce(function(clean, keyName) {
if (keyName.indexOf('_') === 0) {
return clean;
}
var value = dirty[keyName];
if (typeof value === 'object' && Object.keys(value).length > 0) {
value = removePrivateProperties(value);
@vvo
vvo / the-simplest-config-module.js
Last active August 29, 2015 14:08
The simplest configuration module you will ever need
// This module will load ./process.env.APP_ENV.json and exports it
// And will also read args from command line and merge them, i.e.:
// node index.js --server.hostname=192.168.56.1
// will work.
// Usually this module should be in ./config/index.js
// And then you use var config = require('./config');
// You must set an APP_ENV
if (!process.env.APP_ENV) {