Skip to content

Instantly share code, notes, and snippets.

View jrburke's full-sized avatar

James Burke jrburke

View GitHub Profile
@jrburke
jrburke / gist:9101268
Created February 19, 2014 20:51
npm once

I have a node project. I want to use npm once to fetch a dependency, but from then on, do not depend on the npm registry. The packages installed may need to be compiled/built on different operating systems, not all the packages are pure JS.

I do not want an npm mirror, as I do not need all of npm. I just need the specific versions of the packages I need in my project. I would always set dependency versions to exact version numbers, and would explicitly do version upgrades when I needed. My ideal work flow:

mkdir project-node_modules
cd project-node_modules
mkdir node_modules

# install a bunch of packages, but only in source form, no building
We couldn’t find that file to show.
@jrburke
jrburke / gist:641816
Created October 23, 2010 05:01
Aligned injections
define(["some/module1", "foo", "another/module2", "bar"],
function(module, foo, module2, bar) {
module.doSomething();
});
@jrburke
jrburke / onetwothree.js
Created February 3, 2011 00:53
Sample layout for a one two three
/*
Directory layout
app.html
scripts
- require.js
- one.js
- two.js
- three.js
*/
@jrburke
jrburke / oneOutOfMany.js
Created February 7, 2011 08:13
How one piece of functionality could be created out of many files.
/*
Define a library called foo that has a parse and render
functionality, and a utility function called escape.
*/
/** foo.js **/
//If wanting a global, declare it here
var foo;
//Assemble foo from parts
@jrburke
jrburke / nulleval.js
Created August 17, 2011 20:58
(null,eval)('')
//Came across this in the es-discuss list, on the "clean scope" thread:
https://mail.mozilla.org/pipermail/es-discuss/2011-August/thread.html#16294
//I do not understand what the "null," part buys.
//Has to do something with scope(?), but at least in Firebug,
//I can see foo inside the string being evaled.
var foo = 'foo';
(null,eval)('(function(){console.log(foo);}())');
@jrburke
jrburke / runTests.js
Created August 22, 2011 21:42
jasmine hacking for use in requirejs on node, not really usable
/*jslint strict: false, onevar: false, indent: 2 */
/*global require: false, process: false */
var requirejs = require('./jasmine/lib/r.js');
requirejs.config({
nodeRequire: require
});
//requirejs(['require', 'jasmine-node', 'jasmine-node/lib/jasmine-node/jasmine-1.0.1', 'sys'],
@jrburke
jrburke / gist:1301798
Created October 20, 2011 17:53
AMD in YUI?
//in some/thing.js
define('some/thing', ['a', 'some/b'], function (a, b) {
return 'value';
});
//YUI loader would apply the return value from the define
//as the 'some/thing' property on the YUI instance,
//so the above module could be used like so:
//in some code that uses YUI:
@jrburke
jrburke / amdconfig.md
Created January 18, 2012 00:52
Rough draft of common config understood by loaders

Attempt to list some possible standard AMD loader configuration values.

An AMD loader is not required to implement all of these configuration values, but if it does provide a capability that is satisfied by these configuration values, it should use these configuration values and structures.

baseUrl

String: Indicates the root used for ID-to-path resolutions. Relative paths are relative to the current working directory. In web browsers, the current working directory is the directory containing the web page running the script.

@jrburke
jrburke / gist:3012544
Created June 28, 2012 17:02
override print for r.js optimizer
var requirejs = require('requirejs'),
foo = require('foo');
requirejs.define('node/print', [], function () {
function print(msg) {
//Do whatever you want with the msg here.
//If you use node dependencies, can just require
//them outside of this closure.
foo(msg);
}