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 / gist:55584
Created January 31, 2009 16:20
Date & DateTime form helpers for Merb 1.x
module Merb::Helpers::Form
def date_field(*args)
if bound?(*args)
current_form_context.bound_date_field(*args)
else
current_form_context.unbound_date_field(*args)
end
end
def datetime_field(*args)
# Pretty prompt
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
<script type="text/javascript">
//<![CDATA[
var get_disqus_num_replies = function() {
var links = document.getElementsByTagName('a');
var query = '?';
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
}
}
@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 / gist:722297
Created November 30, 2010 20:03
My JavaScript Lint configuration (TextMate)
#
# Configuration File for JavaScript Lint 0.2.6
# Developed by Matthias Miller (http://www.JavaScriptLint.com)
#
# This configuration file can be used to lint a collection of scripts, or to enable
# or disable warnings for scripts that are linted via the command line.
#
#### NOTE TO TEXTMATE BUNDLE USERS:
#### Feel free to experiment with enabling/disabling individual warnings to
@benvinegar
benvinegar / gist:726057
Created December 2, 2010 21:03
Example custom template tag for jQuery Templates plugin ($.tmpl)
// Relevant jQuery Template source:
// https://github.com/jquery/jquery-tmpl/blob/master/jquery.tmpl.js#L206
// Example usage: {{pretty_datetime some.date.obj}}
$.extend(jQuery.tmpl.tag, {
"pretty_datetime": {
open: "if($notnull_1){_.push(pretty_datetime($1a));}"
}
});
@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'));
@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: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 / 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');
});
})();