Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / sudo-hack.sh
Last active October 2, 2024 05:28
bash: sudo hack to work around the huge install script I use, where an installer does sudo -k halfway through :/
#!/usr/bin/env bash
# sudo enable-disable hack
#
# Copyright (c) 2013 "Cowboy" Ben Alman
# Licensed under the MIT license.
# http://benalman.com/about/license/
if [[ "$UID" == "0" ]]; then
echo 'Error: Do not run this script as root or using sudo.'
@cowboy
cowboy / get-script.js
Last active December 23, 2015 23:59
javascript: get last script by src filename
// For Remy
function getLastScriptBySrc(filename) {
var scripts = document.scripts;
var i = scripts.length - 1;
while (i--) {
if (scripts[i].src.slice(-filename.length) === filename) {
return scripts[i];
}
}
@cowboy
cowboy / exit.js
Created September 19, 2013 21:53
Attempting to work around Node.js colossal "fuck you" re. https://github.com/joyent/node/issues/3584
// The idea. This doesn't work, but basically comes
// from https://github.com/gruntjs/grunt/pull/708
var exitCode;
function exit(code) {
if (exitCode === undefined) {
exitcode = code || 0;
tryToExit();
}
}
@cowboy
cowboy / bump.js
Created September 18, 2013 18:18
bump
/*
* grunt
* http://gruntjs.com/
*
* Copyright (c) 2013 "Cowboy" Ben Alman
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
*/
'use strict';
@cowboy
cowboy / cleanup-grabs.php
Last active December 23, 2015 06:49
php: gyazo screengrab removal helper
<?php?>
<!doctype html>
<html>
<body>
<link href="https://rawgithub.com/necolas/normalize.css/master/normalize.css" rel="stylesheet">
<style>
body {
padding: 1em;
background-color: #ccc;
}
@cowboy
cowboy / questions.json
Last active December 23, 2015 00:09
grunt-init y/n question helper.
[
{
"name": "yes",
"message": "This question will default to yes (true).",
"default": true
},
{
"name": "no",
"message": "This question will default to no (false).",
"default": false
@cowboy
cowboy / muxing-logger.js
Created September 6, 2013 19:23
Muxing logger #2
var EventEmitter = require('events').EventEmitter;
var es = require('event-stream');
var util = require('util');
function Logger() {
Logger.super_.call(this);
}
util.inherits(Logger, EventEmitter);
@cowboy
cowboy / muxing-logger.js
Created September 6, 2013 18:58
Node.js: muxing logger
var es = require('event-stream');
var util = require('util');
function Logger() {
this.stream = es.through();
this._streamWrite = this.stream.write.bind(this.stream);
this._streamEnd = this.stream.end.bind(this.stream);
this.stream.write = this.stream.end = function() {};
}
@cowboy
cowboy / through-stream-order.js
Created August 27, 2013 00:40
Node.js - is there any way to guarantee the order here?
var stream = require('readable-stream');
var Transform = stream.Transform;
function Logger() {
Transform.call(this);
}
Logger.prototype = Object.create(Transform.prototype);
Logger.prototype._transform = function(chunk, encoding, done) {
done(null, chunk);
};
@cowboy
cowboy / dunno.js
Last active October 27, 2022 09:39
Node.js Transform stream piping, order, asynchronous, wtf
var stream = require('readable-stream');
var Transform = stream.Transform;
var util = require('util');
var _ = require('lodash');
var $ = require('chalk')
// Just serialize a object stream into lines of JSON
function Serializer() {
Transform.call(this, {objectMode: true});
}