Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / console-helpers.js
Last active March 25, 2021 03:58
JavaScript console helpers: a few functions I use here or there in the console
// 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 / Gruntfile.js
Created March 20, 2014 16:20
Grunt toStringify hackery
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 / globule-mapping-rename.js
Last active August 29, 2015 13:57
globule.mapping new rename src/dest example
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 March 4, 2014 16:20
Grunt: async config using a wrapper task
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 / jQuery-deferreds-wtf-anger.js
Last active August 29, 2015 13:56
Man, jQuery Deferreds annoy the fuck out of me.
// 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 / globule-test.md
Created February 19, 2014 17:48
globule: work in progress

Script

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

globule.find([
  '**/*.js',
  '!**/*built.js',
  '**/*.js',
  '**/*.js',
@cowboy
cowboy / json-with-comments-in.yaml
Last active August 29, 2015 13:56
Why do we keep having the "comments in JSON" discussion? Just use YAML.
{
# this is a comment
"a": "hello",
# this is another comment
"b": -1,
"c": [
true,
"test",
null
],
@cowboy
cowboy / hollaback.js
Last active March 1, 2018 09:20
Should Node.js have a helper method for this pattern? Does it already?
// Instead of lots of "if err, callback(err), else, callback(null, result)"
exports.doSomething = function(callback) {
var err, result;
// a bunch of code
if (err) {
callback(err);
} else {
callback(null, result);
}
};
@cowboy
cowboy / log.txt
Created January 7, 2014 18:03
npm updated wat
$ cat package.json
{
"name": "globule",
"description": "An easy-to-use wildcard globbing library.",
"version": "0.1.0",
"homepage": "https://github.com/cowboy/node-globule",
"author": {
"name": "\"Cowboy\" Ben Alman",
"url": "http://benalman.com/"
},
@cowboy
cowboy / upgrade.sh
Created December 12, 2013 03:09
Note to self: Upgrade ts3 (teamspeak 3) server on Ubuntu
#!/bin/bash
# 1. download ts3 Server x86 from: http://www.teamspeak.com/?page=downloads
# 2. run this script as root from within /opt/
# notes:
# http://robert.penz.name/296/howto-install-teamspeak-3-server-on-ubuntu-10-04-lucid/
if [[ ! "$1" || ! -e "$1" ]]; then
echo "Usage: $(basename $0) teamspeak3-server_linux-x86-x.y.z.tar.gz"