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 / 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;
}
@benvinegar
benvinegar / breakpoint.js
Created August 8, 2010 23:16
Set JavaScript debugger breakpoints from the console
/**
* Utility lib for setting/unsetting JavaScript breakpoints
*
* Usage:
* breakpoint.set('globalMethodName');
* breakpoint.unset('globalMethodName');
*
* breakpoint.set('namespacedMethodName', namespaceObject);
* breakpoint.unset('namespacedMethodName', namespaceObject);
*/
@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)
~ » 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 + ';');
@benvinegar
benvinegar / subdomain.js
Created March 8, 2011 06:31
Subdomain tunneling with jQuery and document.domain
/**
* Replace $.ajax on your subdomain with a copy taken
* from your base domain. All jQuery AJAX actions go
* through $.ajax (i.e. $.get, $.post), so it's all good.
*/
(function() {
var iframe,
onload,
queue = [],
@benvinegar
benvinegar / gist:727646
Created December 3, 2010 22:21
A helpful list of jQuery shortcuts + patterns
//--------------------------------------------------
// Get binary value of checkbox checked/not-checked
//--------------------------------------------------
// Seen often:
$('selector').attr('checked') ? 1 : 0;
// Alternatively:
Number($('selector').is(':checked'));