Skip to content

Instantly share code, notes, and snippets.

View Prinzhorn's full-sized avatar
🌚
Existing

Alexander Prinzhorn Prinzhorn

🌚
Existing
View GitHub Profile
@Prinzhorn
Prinzhorn / rethinkdb-express.js
Last active August 29, 2015 14:20
RethinkDB with Express
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 August 29, 2015 14:18
Open the GitHub repository for the current GitHub page

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])}()
@Prinzhorn
Prinzhorn / README.md
Last active August 29, 2015 14:06 — forked from weiglemc/.block
@Prinzhorn
Prinzhorn / index.js
Created August 13, 2014 06:48
Functions for checking if an int is equal to another int. So intuitive!
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 November 5, 2016 08:46
Conditional rendering handler for Epoxy.js

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.

@Prinzhorn
Prinzhorn / README.md
Created February 25, 2014 09:19
Code quality.

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.

@Prinzhorn
Prinzhorn / index.js
Created January 6, 2014 14:43
tap handler
var targetElement = e.currentTarget;
if(document.activeElement !== targetElement) {
if(document.activeElement) {
document.activeElement.blur();
}
targetElement.focus();
}
$(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,
@Prinzhorn
Prinzhorn / upload.js
Created November 13, 2013 09:11
FileAPI upload
//Not working:
FileAPI.upload({
url: '/upload',
files: {
image: FileAPI.Image(file).resize(800, 800, 'min')
}
});
//Working fine:
FileAPI.upload({
@Prinzhorn
Prinzhorn / index.js
Created November 11, 2013 18:23
Only animate skrollr when scrolling down
skrollr.init({
beforerender: function(data) {
return data.curTop > data.lastTop;
}
});