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 / AvgRingBuffer.js
Created April 9, 2013 09:20
AvgRingBuffer
var AvgRingBuffer = function(length) {
var _this = this;
var index = 0;
var data = [];
//Push a value to the oldest spot.
_this.push = function(value) {
data[index] = value;
index = (index + 1) % length;
};
@Prinzhorn
Prinzhorn / index.js
Created April 4, 2013 21:04
When preventing touch events from their default action, you can't click links or form elements. By checking if the move distance was small (i.e. it was just a tap) we can trigger a click on this element.
//Check if it was more like a tap.
var distanceY = initialTouchY - currentTouchY;
var distanceX = initialTouchX - currentTouchX;
var distance2 = distanceX * distanceX + distanceY * distanceY;
//Why use Math.sqrt when you can just compare the square number ;-).
if(distance2 < 49) {
//It was a tap, grab the element and click it.
var elementToClick = document.elementFromPoint(initialTouchX, initialTouchY);
elementToClick.click();
@Prinzhorn
Prinzhorn / message.md
Last active December 12, 2015 03:28
nodejitsu

The nodejitsu website doesn't say anything about databases. It took me some Googling (e.g. "site:nodejitsu.com mongodb") to find out that you in fact offer database hosting. I mean, I knew the nodejitsu website for quite some time and never knew about it and thus never evaluated for my use case. The same goes for which cloud host is used. I was implying that nodejitsu runs in it's own cloud (maybe Rackspace hosted, or Joyent, because it appears in nodejitsu context). But I now found out that you can choose where to run it (e.g. aws EU Ireland, which is what I want).

Long story short, you guys should really take a look at other PAAS and put the damn USPs on your homepage

  • You are THE node.js experts (you specialized in that. No rails, php, java or whatever)
  • It's not just application hosting but anything I need (list everything you offer, e.g. mongodb, redis, mysql, rabbitmq, whatever)
  • Free to get started with limited DB (e.g. "Free to get started for small apps with 100mb of free MongoDB")
  • Choos
  • You could have mentioned relative-mode, as this would make the keyframes independent from where the header starts and how high it is. With relative mode you can resize the header and add a top margin without needing to adjust the keyframes (0 and 500).
  • In the last paragraph (mobile) you're including the IE plugin without mentioning what it does (and you say it's the mobile version).
    • The IE plugin adds support for rgb and hsl colors and patches querySelector to at least support ID selectors (for data-anchor-target)

But the relative mode stuff would make a great follow up I guess.

@Prinzhorn
Prinzhorn / gist:4132330
Created November 22, 2012 17:39
fake scrolling using real scrolling

On iOS and Android as well JavaScript is throttled/stopped while scrolling. That's one use-case of iScroll because it doesn't use native scrolling.

Let alone the other use-cases, is it possible to prevent native scrolling (preventDefault) but then use touchmove/start/end and window.scroll to basically use the native scrollbar but no the native scrolling. In short: looks like you are scrolling (and you are), but JS still works.

Just wondering if you ever experimented with this. It's nothing I want for iScroll, just curious.

@Prinzhorn
Prinzhorn / omnomnomnom.md
Created September 20, 2012 17:12
to nom

to nom

Definition

to eat or drink something and enjoying to do so.

Examples

@Prinzhorn
Prinzhorn / bacon.md
Created September 19, 2012 08:24
Requirements for a MV* framework for small projects

I just want this a bit cleaner than using plain jQuery.

  • Dynamic view updates like Knockout/o_O
  • With the template syntax of Angular JS (this data-bind="text: bacon" is ridiculous)
  • Models with remote connection. E.g. I want to have a User object with CRUD connection to the server (Angular seems to have this with $resource, but documentation is outdated and I can't get it to work)

I don't need routing. I just want to have clean underlying data connected to the server which updates the view.

Maybe someone can recommend one or maybe two frameworks which solve this. One for the object stuff and another which can handle these objects and updates the view.

@Prinzhorn
Prinzhorn / example.js
Created May 24, 2012 16:06
Sort an array and keep track of all permutations in second array
//Sorts arr and syncs assArr simultaneously
var associatedSort = (function() {
var comparator = function(a, b) {
if(a[0] < b[0]) {
return -1;
}
if(a[0] > b[0]) {
return 1;
}
@Prinzhorn
Prinzhorn / LICENSE.txt
Created May 7, 2012 15:55 — forked from 140bytes/LICENSE.txt
compress hex color string
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Alexander Prinzhorn (@Prinzhorn) https://github.com/Prinzhorn
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@Prinzhorn
Prinzhorn / wooot.js
Created April 2, 2012 16:35
Revising JavaScript's switch case
//This is part of a easing function I wrote
function(p, a) {
switch(true) {
case (p <= .5083):
a = 3; break;
case (p <= .8489):
a = 9; break;
case (p <= .96208):
a = 27; break;
case (p <= .99981):