Skip to content

Instantly share code, notes, and snippets.

Avatar

Jens Arps jensarps

View GitHub Profile
@jensarps
jensarps / detectIDB.js
Last active Apr 16, 2019
Script to detect buggy IndexedDB implementations
View detectIDB.js
(function (name, definition, global) {
if (typeof define === 'function') {
define(definition);
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = definition();
} else {
global[name] = definition();
}
})('detectIDB', function () {
@jensarps
jensarps / reflect.js
Created Jul 22, 2015
A reflection function to (recursively) print object members onto the console
View reflect.js
var _reflect = function reflect (it, recursive, level) {
level = ~~level;
var indent = (' >').repeat(level),
isObject = function (candidate) { return Object.prototype.toString.call(candidate) == '[object Object]'};
if (level > 1) {
console.log(indent + ' recursion too deep, stopping.');
return;
}
@jensarps
jensarps / closure-compiler-config-2.js
Last active Dec 20, 2015
Snippets from my post on creating dynamic/configurable builds with Grunt and Closure Compiler.
View closure-compiler-config-2.js
//configure closure compiler
var closureFiles = handlerClassNames.map(function (name) {
return 'src/' + name + '.js';
});
closureFiles.unshift('src/InputController.js');
closureFiles.push('build/bundle.js');
/* ... */
grunt.config.set('closure-compiler.bundle', {
closurePath: 'lib/closure',
jsOutputFile: 'build/input-controller.js',
@jensarps
jensarps / gplus-comments.html
Created Apr 24, 2013
Use this markup to add Google+ comments to your blog/whatever. Oh, and don't forget to put the width and url in there.
View gplus-comments.html
<div class="g-comments"
data-href="{put-your-url-here}"
data-width="{put-your-container-width-here}"
data-first_party_property="BLOGGER"
data-view_type="FILTERED_POSTMOD"
></div>
<script type="text/javascript">
(function() {
var gp = document.createElement('script'); gp.type = 'text/javascript'; gp.async = true;
View config.html
<script>
var dojoConfig = {
packages: [
{
name: 'storehouse',
location: '../storehouse'
}
]
};
</script>
View bindings.js
var SPEECH = 'speech';
var bindings = {
/* ... */
fullSpeed: {
device: SPEECH,
inputId: 'full speed'
},
stop: {
@jensarps
jensarps / puntMany.js
Created Feb 27, 2013
A putAll / putMany convenience method for IDBWrapper
View puntMany.js
/**
* Takes an array of data objects to store and calls IDBWrapper's batch() method
*
* @param {Array} dataArray An array of objects to be stored
* @param {Function} [onSuccess] Gets called if the operation was successful
* @param {onError} [onError] Gets called if an error occurred
*/
function putMany (dataArray, onSuccess, onError) {
var preparedData = dataArray.map(function(dataObject){
@jensarps
jensarps / example-1.js
Created Nov 13, 2012
Examples for IDBWrapper Tutorial, Part 2
View example-1.js
var onItem = function (item) {
console.log('got item:', item);
};
var onEnd = function (item) {
console.log('All done.');
};
customers.iterate(onItem, {
order: 'DESC',
onEnd: onEnd
@jensarps
jensarps / iterate-with-keyrange.js
Created Nov 13, 2012
Code for IDBWrapper Tutorial, Part 2
View iterate-with-keyrange.js
customers.iterate(onItem, {
index: 'lastname',
keyRange: myKeyRange,
order: 'ASC',
filterDuplicates: false,
writeAccess: false,
onEnd: onEndCallback,
onError: onErrorCallback
});
@jensarps
jensarps / connect.js
Created Aug 9, 2012
Mouse-Picking Collada Models with THREE.js
View connect.js
container.addEventListener('click', function (evt) {
// The user has clicked; let's note this event
// and the click's coordinates so that we can
// react to it in the render loop
clickInfo.userHasClicked = true;
clickInfo.x = evt.clientX;
clickInfo.y = evt.clientY;
}, false);
You can’t perform that action at this time.