Skip to content

Instantly share code, notes, and snippets.

View krawaller's full-sized avatar

David Waller krawaller

View GitHub Profile
@krawaller
krawaller / findglobals
Last active December 19, 2015 23:59
Version of Remy Sharps bookmarklet to check for globals, with the addition of ignoring global variables that are undefined and also alerting out a summary. If you want to add it to Chrome, there's a good guide here: http://crossbrowsertesting.com/faq/how-do-i-install-bookmarklet-google-chrome-mac-os
javascript:(function(){var e={},t,n={},r=(prompt("Ignore filter (comma sep)?","")||"").split(","),i=r.length,s=document.createElement("iframe"),o="";while(i--){n[r[i]]=1}for(i in window){if(window[i]!==undefined){e[i]={type:typeof window[i],val:window[i]}}}s.style.display="none";document.body.appendChild(s);s.src="about:blank";s=s.contentWindow||s.contentDocument;for(i in e){if(typeof s[i]!="undefined")delete e[i];else if(n[e[i].type])delete e[i]}t="addEventListener,document,location,navigator,window".split(",");i=t.length;while(--i){delete e[t[i]]}var u=[];for(i in e){u.push(i)}alert(u.length?"Found these globals: "+u.join(", ")+". See details in the console!":"No globals found!");console.dir(e)})()
var docCookies = {
getItem: function (sKey) {
if (!sKey || !this.hasItem(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
Drupal.verticalTabs = Drupal.verticalTabs || {};
Drupal.settings.verticalTabs = Drupal.settings.verticalTabs || {};
Drupal.behaviors.verticalTabs = function() {
if (!$('.vertical-tabs-list').size() && Drupal.settings.verticalTabs) {
var TABSETTING = "tabpos"+document.location.pathname.replace(/\//g,666);
var ul = $('<ul class="vertical-tabs-list"></ul>');
var panes = $('<div class="vertical-tabs-panes"></div>');
$.each(Drupal.settings.verticalTabs, function(k, v) {
var summary = '', cssClass = 'vertical-tabs-list-' + k;
@krawaller
krawaller / bbviewpubpattern.js
Created February 29, 2012 06:48
Backbone Sanitary View Publishing Pattern
/*
S A N I T A R Y V I E W P U B L I C A T I O N P A T T E R N
This pattern adresses three issues; memory leaks, involuntarily allowing unwanted event listeners to live
on, and the cumbersome process of publishing a view to the page. The first two issues are dealt with through
making sure that previously published views are removed properly, and not merely have their html
overwritten. And, as will see, the solution to fixing the removal process will also mean a streamlining
of the publication process!
We do this through the use of two mixin modules; one for our views, and one for our router.
@krawaller
krawaller / comparedbs.js
Created January 27, 2012 18:22
Compare performance of Titanium Mobile SQLite insert in different ways
// Compare classic insert, insert using Begin/Commit and Union insert described slightly down on this page: http://stackoverflow.com/questions/1609637/is-it-possible-to-insert-multiple-rows-at-a-time-in-an-sqlite-database
// Create some values
var values = [];
for(var i = 0; i < 500; i++){
values.push(i);
values.push(String.fromCharCode(65 + i % 25));
}
@krawaller
krawaller / ui.coffee
Created September 28, 2011 10:52
mathparser UI code
# ----------------------------- jquerified DOM references ---------------------------
ui = {}
ui[id] = $("##{id}") for id in ["input","output","response","history","current","savebtn","examples","clearhistorybtn","clearbtn"]
ui.currentstring = $ "#current .string"
ui.currentobjprint = $ "#current .objprint"
# -------------------------- variables/constans -----------------------------------
calc = (tool,a1,a2,toolarg)->
if tool is "relation"
throw "Only one relation allowed!" if a2.type is "relation"
type:"relation",objs:[a1,a2],val:toolarg
else if a2.type is "relation"
type: "relation",val:a2.val, objs:[calc(tool,a1,a2.objs[0]),a2.objs[1]]
else if a2.isblock
o tool,[a1,a2]
else if tool in ["sum","product"] and tool is a2.type
o tool, [a1].concat a2.objs
tests.addBatch "the calc function":
"is defined": -> assert.isFunction calc
"when relating":
topic: -> (arg)-> calc "relation", start, arg, "eq"
"a blob":
topic: (relate)-> relate blob
"we get a": type "relation"
"containing": objs [start, blob]
"with a value": val "eq"
"a relation": (relate)-> assert.throws -> relate relation
tests.addBatch "the implicit operation function":
"is defined": -> assert.isFunction iO
"returns product for": pairs "1x", "2y", "3z", "5(", "0x", ")(", "xy", "5\"", "x\"", "\"y","\"\"", "5|", "||", "!x"
"returns power for": pairs "x2", "y3", "z4", ")6", "\"2", "\"8", "|2", "x0", "!2"
"returns sum for": pairs "3-", "z-", ")-", "\"-"
"returns nothing for": wrongpairs "3+", "x*"
@krawaller
krawaller / twinexport.coffee
Created September 18, 2011 08:13
Exporting to Node and the browser
if typeof exports is "undefined"
exportTo = @parser = {}
else
exportTo = exports