Skip to content

Instantly share code, notes, and snippets.

Ben Alman cowboy

Block or report user

Report or block cowboy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cowboy
cowboy / json-with-comments-in.yaml
Last active Aug 29, 2015
Why do we keep having the "comments in JSON" discussion? Just use YAML.
View json-with-comments-in.yaml
{
# this is a comment
"a": "hello",
# this is another comment
"b": -1,
"c": [
true,
"test",
null
],
@cowboy
cowboy / globule-test.md
Created Feb 19, 2014
globule: work in progress
View globule-test.md

Script

var globule = require('./lib/globule');

globule.find([
  '**/*.js',
  '!**/*built.js',
  '**/*.js',
  '**/*.js',
@cowboy
cowboy / jQuery-deferreds-wtf-anger.js
Last active Aug 29, 2015
Man, jQuery Deferreds annoy the fuck out of me.
View jQuery-deferreds-wtf-anger.js
// When a jQuery deferred is resolved with a single value, the arguments to
// the .then callback are the same as when .then is called directly on the
// deferred or on $.when(deferred) AND ALSO $.when(deferred, deferred).
var dfd = $.Deferred().resolve([1, 2, 3]);
dfd.then(function(a) {
console.log('[1a]', a); // [1, 2, 3]
});
$.when(dfd).then(function(a) {
console.log('[2a]', a); // [1, 2, 3]
});
@cowboy
cowboy / Gruntfile.js
Created Mar 4, 2014
Grunt: async config using a wrapper task
View Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({});
grunt.registerTask('require-wrapper', 'whatever', function() {
var done = this.async();
var args = this.args;
// simulate async config building
setTimeout(function() {
// set config
grunt.config('requirejs', {yay: true});
@cowboy
cowboy / globule-mapping-rename.js
Last active Aug 29, 2015
globule.mapping new rename src/dest example
View globule-mapping-rename.js
var globule = require('globule');
// This actually looks for files '1' '2' etc, doesn't find them,
// but retains the pattern because nonull == true
console.log(globule.findMappingSync({
src: '12345'.split(''),
nonull: true,
rename: function(n) {
return {
src: 'in/' + n + '.txt',
@cowboy
cowboy / Gruntfile.js
Created Mar 20, 2014
Grunt toStringify hackery
View Gruntfile.js
module.exports = function(grunt) {
function toStringify(obj, toString) {
obj.toString = toString;
return obj;
}
grunt.initConfig({
stuff: {
foo: ['l', 'o', 'l'],
bar: toStringify(['w', 'u', 't'], function() {
@cowboy
cowboy / console-helpers.js
Last active Aug 29, 2015
JavaScript console helpers: a few functions I use here or there in the console
View console-helpers.js
// simplify testing things like regexes
function eqs() {
var a = [].slice.call(arguments);
var fn = a.pop();
var i, actual;
for (i = 0; i < a.length; i += 2) {
actual = fn(a[i]);
if (actual !== a[i+1]) {
console.error('"%s" !== "%s" (%s)', actual, a[i+1], a[i]);
}
@cowboy
cowboy / AutoHotkey.ahk
Created Apr 17, 2014
AutoHotkey Misc
View AutoHotkey.ahk
SoundPlay *64
; =============
; Edit & Reload
; =============
!^+F12::
Edit
Reload
return
@cowboy
cowboy / wat.js
Created Apr 25, 2014
why do i do this kind of thing
View wat.js
(function() {
var $=['_'].concat(Array(arguments.length-1),'return _');
var _=Function.apply(null,$);
$.forEach.call(arguments,function($,$$){_[$$]=$});
return $.map.bind.call($.map,_,_);
}(5,6,7,8))()
@cowboy
cowboy / not-grunt-init.sh
Created May 7, 2014
Grunt: Look, I re-integrated grunt-init back into grunt. Here ya go, @rwaldron
View not-grunt-init.sh
# (Include this function in your .bashrc)
# If the first argument is "init" or begins with "init:", run grunt-init.
# Otherwise run grunt.
function grunt() {
if [[ "$1" =~ ^init: ]]; then
grunt-init "${1##init:}" "${@:2}"
elif [ "$1" == "init" ]; then
grunt-init "${@:2}"
else
You can’t perform that action at this time.