1,135 karma · joined Mar 22, 2009 (17y ago) · 212 submissions
comment 13y ago · link · parent
https://gist.github.com/substack/4735826
Program:
var falafel = require('falafel');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/src.js', 'utf8');
var output = falafel(src, function (node) {
if (node.type === 'IfStatement'
&& node.test.type === 'MemberExpression'
&& node.test.object.name === 'Meteor'
&& node.test.property.name === 'isServer') {
node.update('');
}
});
console.log(output);
Input: if (Meteor.isClient) {
console.log("I'm the client!");
}
if (Meteor.isServer) {
console.log("I'm the server!");
}
Output: if (Meteor.isClient) {
console.log("I'm the client!");
}
This won't catch fancy things like Meteor['isServer'] or compound expressions but should be a good place to start.edit: I had them backwards. Fixed now.
comment 13y ago · link · parent
comment 13y ago · link · parent
comment 13y ago · link · parent
Basic example: http://substack.net/projects/pricing-widget/basic/ Fancy example: http://substack.net/projects/pricing-widget/browserling/
comment 14y ago · link · parent
comment 14y ago · link · parent
and it DOES work with everything
... so long as you wrap all the files in the particular variant of define() function that works with requirejs (but not with other competing AMD function signatures). And then you might want to use some modules written for commonjs or node with `exports`, so you'll need a tool to transform those files. And then you'll probably want to compile the application into a single javascript bundle in production for performance.I'm not saying bower is any better in any of these respects, just that everything is terrible.
comment 14y ago · link · parent
The reason why I am skeptical of new entrants into the javascript package management arena is that there is already a package manager with over 14k packages and a vibrant community that is producing packages at a very high rate: npm. npm might not be the best package manager as-is for browser development, but tools like browserify (disclaimer: I wrote browserify), ender, or many others can let your browser code use much of the value that has already been created for npm, even though npm is primarily about node.js packages. A surprising number of modules written for node will just work in tools like browserify.
Any upstart package systems would be wise to have a clear and simple path for unlocking the value created in the node community because there is too much value being created in npm to ignore. Whether that path involves adding fields to the package.json, tools to bridge the gap between package repositories, fancy in-browser trickery or compile steps remains an open question but it would be really pointless to require people to publish their modules that they've already put on npm to buy in to yet another package system, especially since there seems to be a new package manager every month lately.
comment 14y ago · link · parent
function sum (m, n) {
return m * (m + 1) / 2 - n * (n - 1) / 2
}
I only know this because I remember from math competitions in high school learning that you can compute the sum of the digits from 1 to n quickly from `n * (n + 1) / 2` which naturally follows from the equations regarding binomial sums.This example somewhat agrees with the author's main point that we are more a product of our experiences than endowed with certain innate capabilities.
comment 14y ago · link · parent
comment 14y ago · link · parent
comment 14y ago · link · parent
comment 14y ago · link · parent
It's a better idea to do:
"dnode" : "~0.9.11",
"browserify" : "~1.10.17"
since that way you'll get patch fixes automatically but your library won't break when I push out an update that bumps the minor version, which could including backwards-incompatible changes.comment 14y ago · link · parent
Here's a tap example that sets up a server and client for dnode: https://github.com/substack/dnode/blob/master/test/single.js
Timers usually aren't necessary with test harnesses like tap or nodeunit since you need to call `t.end()` explicitly or else `t.plan()` the number of tests that are supposed to be run. If a different number of tests actually run or assertions fire after `t.end()` is called, those are reported as errors.
For (4), to run a bunch of test files in a directory you can use the `tap` command. You can even add something like `tap test/*.js` to the scripts.test field of a package.json file and then to run all your tests you can just do `npm test`.
76.
Multi-server continuous deployment with fleet(substack.net ↗)
7 points · by substack · 14y ago · discuss
comment 14y ago · link · parent
> And, for the record, I'm all in for homeopathy and faith
> cures - they may help remove some undesirable genetic
> traits from the gene pool. OTOH, the populations presenting
> such traits can evolve to have better immune systems. Life
> has a way to perpetuate itself.
Susceptibility to harmful ideologies really doesn't work like that. Being raised within a religion or cultural practice is an amazingly better predictor for continuing that belief in the next generation than what genes were passed along. Faith cures and placebos operate at the level of belief and culture, not the gene level.Further, look no further than the anti-vaccination movement to see how harmful medical ideas can put the general population at a greater risk for entirely preventable diseases.
comment 14y ago · link · parent
81.
Colorful javascript object diffs with difflet(substack.net ↗)
15 points · by substack · 14y ago · 1 comment
comment 14y ago · link · parent
In particular, I still really dislike the special import "local renaming" syntax since it seems so unnecessary compared to just having an import keyword that returns an object and letting the programmer extract and manipulate the relevant entries. You would still get the static analysis benefits of having static imports without all the awkward complexity of the current proposal. Wouldn't it just be the same thing to Object.freeze() the export object but without any syntax magic necessary?
Plus, overloading `module` to do loading AND defining with the `module Bar at "uri"` form seems really wrong. Why can't it JUST do defining and just let import do all the loading?
comment 14y ago · link · parent
In ES.next, you've got to use pythonesque `import y from Bar` statements which introduce a frustrating correspondence between the lexicals of your own program and the export names of the module you're trying to use which is really terrible if you're using as many modules as I typically do. I presume ES.next will invent even more specific syntax for some sort of `as` like keyword to side-step this but it seems so unnecessary when javascript already has a module system that is so very good as is exploding in popularity and use (>7000 modules now on http://search.npmjs.org/).
I understand what they're trying to do with static analysis too but you can already pretty much do that and I've done it. It's not hard at all, just ignore require() statements that don't contain strings when you walk the AST, like this: https://github.com/substack/node-detective
Inventing more syntax instead of just adopting a far better module system that has seen actual use in practical situations is such a shame and ES.next is rife with this kind of prescriptivism. It irritates me to no end and I sometimes want ES.next to die a quiet death in obscurity because of it.
85.
Semver your services with seaport(substack.net ↗)
2 points · by substack · 14y ago · discuss
comment 14y ago · link · parent
Javascript doesn't have this (by itself) but node has a very nice require() system that is really excellent for long-term maintainability. When you bump a dependency in a node project that change will only affect the code near it because of how node_modules are resolved to the most local copy. You can bump dependencies without worrying how this will affect other packages.
Plus, require() just returns an object. It doesn't puke a bunch of objects into the current scope. This is massively useful for readability. I've sunk a lot of time on other systems tracking down unqualified exports to figure out which package's documentation to consult.
I've got nothing against scala and am sure it's a useful language but I wonder if the author has even used node.
comment 14y ago · link · parent
comment 14y ago · link · parent
When you design your own art assets, you can iterate on the design in a much more incremental way because the transaction cost of going out and finding a designer is quite high. When you can design your own assets in-house, the art can work its way into the core of the product better and ends up in more places. For instance, many of the modules my startup has released have silly cartoons that I drew: http://www.catonmat.net/blog/browserling-open-sources-90-nod...
When there are external barriers to art, you're probably going to use it less. Contracting out for all of those silly readme cartoons would be wildly uneconomical but for me it provides a nice refuge from coding all day that happens to help us establish credibility with potential customers and expand our product exposure.
If you are a developer who is going to try your hand at doing the art yourself, I wouldn't be too concerned if your initial attempts look amateurish. Our earliest prototype looked really bad:
http://substack.net/images/screenshots/browserling-1.png
but we iterated and made it a little better:
http://substack.net/images/screenshots/browserling-3.png
and then did a redesign recently:
Make some art!