Skip to content

Instantly share code, notes, and snippets.

Alexander Prinzhorn Prinzhorn

Block or report user

Report or block Prinzhorn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Prinzhorn
Prinzhorn / rethinkdb-express.js
Last active Aug 29, 2015
RethinkDB with Express
View rethinkdb-express.js
var express = require('express');
var r = require('rethinkdb');
var app = express();
r.connect(config.rethinkdb, function(err, conn) {
if(err) {
return handleError(res, err);
}
@Prinzhorn
Prinzhorn / README.md
Last active Aug 29, 2015
Open the GitHub repository for the current GitHub page
View README.md

There are so many projects hosted on GitHub pages which do not have a prominent link to the repo on the page. I always (╯°□°)╯︵ ┻━┻ when this happens because I have to manually enter the stupid URL.

Here's a Bookmarklet

javascript:!function(){var o=location.href.match(/(\w+).github.io\/(\w+)/);o&&(window.location="https://github.com/"+o[1]+"/"+o[2])}()
View README.md
@Prinzhorn
Prinzhorn / index.js
Created Aug 13, 2014
Functions for checking if an int is equal to another int. So intuitive!
View index.js
for(var i = 0; i < 4294967296; i++) {
global['is' + i] = (function(i) {
return function(n) {
return !(i - n);
};
}(i));
}
console.log(is5(5));//true
console.log(is5(9));//false
@Prinzhorn
Prinzhorn / README.md
Last active Nov 5, 2016
Conditional rendering handler for Epoxy.js
View README.md

Similar to the toggle handler, but it will detach the element from the DOM instead of just hiding it. Much like knockout's if binding.

Usage

<div data-bind="if: someCondition"></div>

where someCondition can of course also be a computed property, so this gives you all flexibility you need.

View README.md

This is an excerpt from a 465 lines js file. This is not satirical. This is actual code from a large codebase (>100k js) of an application that is used in production at multiple customers.

If you're giving a talk or lecture about code quality, feel free to use this as the first slide to make your audience giggle for a second. And then look at their faces when you tell them it's actual code.

View index.js
var targetElement = e.currentTarget;
if(document.activeElement !== targetElement) {
if(document.activeElement) {
document.activeElement.blur();
}
targetElement.focus();
}
View animation.js
$(document).ready(function () {
var a = $.scrollorama({
blocks: ".scrollblock"
});
a.onBlockChange(function () {
var b = a.blockIndex;
$("#console").css("display", "block").text("onBlockChange | blockIndex:" + b + " | current block: " + a.settings.blocks.eq(b).attr("id"))
});
a.animate("#reality .bg", {
delay: 300,
View upload.js
//Not working:
FileAPI.upload({
url: '/upload',
files: {
image: FileAPI.Image(file).resize(800, 800, 'min')
}
});
//Working fine:
FileAPI.upload({
@Prinzhorn
Prinzhorn / index.js
Created Nov 11, 2013
Only animate skrollr when scrolling down
View index.js
skrollr.init({
beforerender: function(data) {
return data.curTop > data.lastTop;
}
});
You can’t perform that action at this time.