Skip to content

Instantly share code, notes, and snippets.

View benvinegar's full-sized avatar
🤷‍♀️
What's happening?

Ben Vinegar benvinegar

🤷‍♀️
What's happening?
View GitHub Profile
@benvinegar
benvinegar / readSourceMap.js
Last active February 24, 2017 21:18
Verify your source map mappings locally
/* npm install -g source-map */
var fs = require('fs');
var sourceMap = require('source-map');
var rawSourceMap = fs.readFileSync('./app.js.map').toString();
var smc = new sourceMap.SourceMapConsumer(rawSourceMap);
// output original filename, line, column, token for input {line, column}
// in built/minified file (e.g. app.min.js)
@benvinegar
benvinegar / jsx-to-single-quotes.js
Created October 30, 2015 21:32
jscodeshift transform for converting double quotes to single quotes – *except* in JSX (HTML) attributes
module.exports = function(fileInfo, api) {
var j = api.jscodeshift;
var out = j(fileInfo.source)
.find(j.Literal)
.forEach(function (path) {
// Only consider literals that start/end w/ double quotes
if (!/^".*"$/.test(path.value.raw)) {
return;
}
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="https://cdn3.vox-cdn.com/javascripts/vendor/jquery-1.11.2.min.js"><\/script>');</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script type="text/javascript">window._ || document.write('<script src="https://cdn0.vox-cdn.com/javascripts/vendor/underscore-1.5.2.min.vd22f881.js"><\/script>');</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script type="text/javascript">window.Backbone || document.write('<script src="https://cdn3.vox-cdn.com/javascripts/vendor/backbone-1.0.0.min.v3541019.js"><\/script>');</script>
$('img').attr('src', 'http://i2.kym-cdn.com/photos/images/facebook/000/001/582/picard-facepalm.jpg');
@benvinegar
benvinegar / textnode-innerhtml.js
Last active August 29, 2015 14:06
Proof-of-concept ESLint rule for detecting common XSS pattern
/**
* Proof of concept ESLint rule for warning about potential
* XSS vulnerabilities caused by mixing innerHTML/text node
* property access.
*
* More here: http://benv.ca/2012/10/2/you-are-probably-misusing-DOM-text-methods/
*/
'use strict';
var WARNING_MSG =
~ » curl -s -D - https://github.com -o /dev/null ben@Sinclair-2
HTTP/1.1 200 OK
Server: GitHub.com
Date: Sat, 29 Jun 2013 00:52:59 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Status: 200 OK
Cache-Control: private, max-age=0, must-revalidate
Strict-Transport-Security: max-age=2592000
X-Frame-Options: deny
@benvinegar
benvinegar / gist:3361951
Created August 15, 2012 17:54
List of websites that force anonymous visitors to sign in to view content indexed by Google
List of websites that force anonymous visitors to sign in to view content indexed by Google:
quora.com
estocksdaily.com
travelzoo.com
@benvinegar
benvinegar / gist:3208798
Created July 30, 2012 18:12
Chained defer
// Execute fn for each element in arr, releasing to the UI
// thread (via underscore's _.defer) between each execution
_.chainedDefer = (function () {
function next(arr, fn, scope) {
if (!arr.length)
return;
fn.call(scope, arr.shift());
@benvinegar
benvinegar / gist:3140509
Created July 19, 2012 03:11
Make all your slides' <code> samples editable
// no document ready check - put this at the end of <body>
;(function() {
var pre = Array.prototype.slice.call(document.getElementsByTagName('code'));
pre.forEach(function (p) {
p.setAttribute('contenteditable', 'true');
});
})();
@benvinegar
benvinegar / gist:2474195
Created April 23, 2012 22:05
Superfast JavaScript forEach function
function forEach(arr, fn) {
var impl = fn.toString();
var m = impl.match(/function \((\w+),?\s*(\w+)?\) { (.*) }/);
var arg0 = m[1];
var arg1 = m[2];
var body = m[3];
var program = [];
program.push('var ' + arg0 + ';');
if (arg1)
program.push('var ' + arg1 + ';');