Skip to content

Instantly share code, notes, and snippets.

@d48
d48 / loadJS.js
Created June 19, 2013 16:59
js loader
BLS.unitTests.loadJS = function(strJS, cb) {
var objHead = document.getElementsByTagName('head')[0]
, oEmbed = document.createElement('script')
;
oEmbed.type = 'text/javascript';
oEmbed.src = strJS;
oEmbed.async = false; // force to load in order
// listener for when file is done loading
@d48
d48 / require-params.js
Last active December 17, 2015 20:19
assign loaded dependencies to params in function callback
bls.utils().require( ['/path/to/handlebars.js', '/path/to/template.html'], function( hb, template1) {
// use handlebars via hb var
hb.compile(someTemplateVar, data);
// use template via template1 var
document.getElementById(templateHandle).innerHTML = template1;
} );
@d48
d48 / guard-watch.js
Created May 24, 2013 22:58
guard watch command for any css, js, html files within the subdirectory that gets updated
guard 'livereload' do
# watch any of these files in this directory and under
watch(%r{^.+\.(css|js|html)})
end
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/javascript");</script>
@d48
d48 / addEvent-removeEvent.js
Last active December 11, 2015 22:28
rewrite addEvent function signature to work with removeEvent using variable that points to function
function openHandler(widgetTypeId, userWidgetId, displayOrder, savePrefUrl) {
// some stuff
Utils.addEvent(btnSave, 'click', function () {
btnSaveClick(widgetTypeId, userWidgetId, displayOrder, savePrefUrl);
});
}
function btnSaveClick(typeId, widgetId, order, url) {
// definition
@d48
d48 / ie.shims.js
Created December 3, 2012 04:50 — forked from dhm116/ie.shims.js
IE7/8 Javascript method shims
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@d48
d48 / obj-method-public.js
Created December 3, 2012 04:10
to make javascript object method public
var hey = {};
(function() {
function woot() {
return 'hi';
}
function who() {
return 'me';
}
@d48
d48 / facebook-login.sh
Created August 28, 2012 17:21 — forked from hubgit/facebook-login.sh
Login to Github using cURL
#!/bin/bash
EMAIL='YOUR_EMAIL' # edit this
PASS='YOUR_PASSWORD' # edit this
COOKIES='cookies.txt'
USER_AGENT='Firefox/3.5'
curl -X POST 'https://github.com/login' --verbose --user-agent $USER_AGENT --data-urlencode "name=${EMAIL}" --data-urlencode "pass=${PASS}" --cookie $COOKIES --cookie-jar $COOKIES
curl -X GET 'https://github.com/dashboard/pulls' --verbose --user-agent $USER_AGENT --cookie $COOKIES --cookie-jar $COOKIES
@d48
d48 / prs-via-jquery.js
Created August 28, 2012 17:11
all my pull requests on github via jquery
// go to https://github.com/dashboard/pulls
$('.listing .js-navigation-open').each(
function(key, value) {
console.log('https://github.com' + $(value).attr('href'));
});
@d48
d48 / formatCurrency.js
Created June 28, 2012 22:22
no cents from format currency
formatCurrency: function(value, noCents) {
if (!isPrice.test(value)) {
return value;
}
noCents = noCents || false;
var precision = 2
, price = parseFloat( Math.abs(value) ).toFixed(precision)
, priceArray = String(price).split('.')