Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / Gruntfile.js
Created September 25, 2012 20:30
super basic gruntfile
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
meta: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= meta.name %> - v<%= meta.version %> */\n',
},
dist: {
src: 'src/<%= meta.name %>.js',
@cowboy
cowboy / yaml-indent-documents.js
Created September 22, 2012 14:00
JavaScript, YAML: wrapper around js-yaml that allows literal/folded styles on documents, eg. --- | or --- > without all that "crazy" indenting.
/*
* yaml-indent-documents
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
'use strict';
@cowboy
cowboy / stringify.js
Created September 19, 2012 13:45
JavaScript: like JSON.stringify but handles functions, good for creating arbitrary .js objects?
var stringify = function(obj, prop) {
var placeholder = '____PLACEHOLDER____';
var fns = [];
var json = JSON.stringify(obj, function(key, value) {
if (typeof value === 'function') {
fns.push(value);
return placeholder;
}
return value;
}, 2);
@cowboy
cowboy / isprimitive-no-strict.js
Created September 18, 2012 12:23
JavaScript: isPrimitive
var isPrimitive = function(val) {
return val !== function() { return this; }.call(val);
};
@cowboy
cowboy / possible-gruntfile.js
Created September 17, 2012 17:54
gruntfile idea
var grunt = require('grunt');
// Init config
exports.config = {
awesome: {
target1: {src: ['foo.js', 'bar.js']}
}
};
// Initialize task object
@cowboy
cowboy / grunt-config-idea.js
Created September 17, 2012 17:47
grunt config idea: insanity?
var grunt = {};
// http://twitter.com/cowboy/status/247745191287611392
var isObject = function(val) {
return val === function() { return this; }.call(val);
};
var config = function(prop, val) {
var method = arguments.length === 2 ? 'set' : 'get';
return config.__proto__[method].apply(null, arguments);
@cowboy
cowboy / grunt-task-definition-options.js
Created September 17, 2012 15:37
task definitions
// inside a gruntfile
grunt.registerTask('awesome', {
description: 'The most awesome task ever.',
type: 'multi',
main: function(grunt, arg) {
var files = grunt.file.expandFiles(grunt.util._.pluck(this.files, 'src'));
var success = this.task.listFiles(grunt, files);
grunt.log.writeln('Stuff happened...');
if (success) { grunt.log.ok(); } else { grunt.log.error(); }
},
@cowboy
cowboy / ocd.log
Created September 10, 2012 13:34
bot-t: hi5
[09:09] <@rmill> o/\o
[09:09] <@rmill> common abbreviation for "boo-yah"
[09:10] <@rmill> _o/\o_
[09:10] <@ben_alman> ?hi5 rmill
[09:10] <bot-t> ben_alman, Couldn't find "hi5 rmill" in jQuery Docs.
[09:10] <@ben_alman> FINE
[09:10] <@rmill> :'(
[09:10] <@ben_alman> ?eval hi5(" rmill ben_alman ")
[09:10] <bot-t> ben_alman: " rmill ben_alman "
[09:10] <@ben_alman> o well
@cowboy
cowboy / log.txt
Created September 7, 2012 20:23
my npm_update script at work
$ npm_update
Installing @latest version of all dependencies...
npm http GET https://registry.npmjs.org/colors
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/dateformat
npm http GET https://registry.npmjs.org/async
npm http GET https://registry.npmjs.org/glob-whatev
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/hooker
npm http GET https://registry.npmjs.org/nopt
@cowboy
cowboy / abstraction-lite.js
Created August 31, 2012 20:57
Abstraction.js "Lite" (live-coded at BrazilJS 2012)
/*
* Abstraction.js "Lite"
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
var $elseif, $else;
var $if = function(state) {