Skip to content

Instantly share code, notes, and snippets.

/**
* This method is used to scroll a bit closer to the top of the window. As long as the top
* hasn't been reached the method will call itself at the next animation frame.
*/
_animationLoop: function() {
var self = this;
// Perform a step of the animation to go to the top of the window
window.scrollTo(0, this._easeOutCubic(this._iteration, this._scrollPosition, -this._scrollPosition, this._maxIterations));
// Increase the iteration counter
@tbusser
tbusser / iterate.js
Last active January 29, 2016 08:57
Iterate over object properties
/**
* Iterates over the properties of an object and calls a callback function when the
* key belongs to the object itself and not to its prototype chain.
*
* The iterate method will iterate over all properties but can be stopped by
* returning true from the callback method.
*
* @param {Object} source The object whose properties should be iterated over
* @param {Function} callback The function to be called for each property defined
* on the source object itself and not its prototype
@tbusser
tbusser / transitionend.js
Last active August 29, 2015 14:07
Determine the name of the `transtitionend` event
var NO_TRANSITIONS = 'no-transitions';
/**
* This method tries to determine the name of the transitionend event, it
* could be the user's browser is using a prefixed version
*/
function getTransitionEndEventName () {
// 1: The variable we use to keep track of the current key when
// iterating over the transitions object
// 2: An element we can use to test if a CSS property if known to the
// browser
@tbusser
tbusser / easeoutcubic.js
Last active August 29, 2015 14:07
JavaScript method, sans jQuery, for a cubic ease-out function
/*
* Robert Penner's algorithm for an cubic ease out function
* @param {Number} currentIteration The current iteration of the animation, on each subsequent
* call this should be increased by 1
* @param {Number} startValue The start value, this should be a constant throughout the
* animation.
* @param {Number} changeInValue The difference between the start value and the desired end value
* @param {Number} totalIterations The number of iterations over which we want to go from start
* to end
* @return {Number} The value for the current step in the animation
@tbusser
tbusser / .jshintrc.js
Last active August 29, 2015 14:07
My preferred settings for JSHint
{
// Enforcing options
"bitwise" : true, // Warn when using bitwise operators, most of the time it is a typo
"camelcase" : true, // Force all variable names to use either camelCase style or UPPER_CASE with underscores.
"curly" : true, // Always put curly braces around blocks in loops and conditionals
"eqeqeq" : true, // Always compare using === and !==
"forin" : true, // Force the use of hasOwnProperty() checks when iterating object properties
"freeze" : true, // Prohibit overwriting prototypes of native objects like Array
"immed" : true, // Prohibits the use of immediate function invocations without wrapping them in parentheses
"indent" : 4, // Tab width for the code
@tbusser
tbusser / .jscs.json
Last active August 29, 2015 14:07
My preferred settings for jscs
{
"requireCurlyBraces" : [
"catch",
"do",
"else",
"for",
"if",
"try",
"while"
],
@tbusser
tbusser / docpad.coffee
Created November 4, 2014 10:52
DocPad config for faster regeneration and Grunt integration for static builds
# DocPad Configuration File
# http://docpad.org/docs/config
# Define the DocPad Configuration
docpadConfig = {
events:
generateAfter: (opts, next) ->
if 'static' in @docpad.getEnvironments()
@docpad.log('info', 'generateAfter: starting grunt task generateAfter')
@tbusser
tbusser / tabs-vs-spaces.md
Created November 11, 2014 10:17
Tabs vs spaces

It is my opinion that tabs are better than spaces, especially when working in a team. Why you aks? When using tabs everyone has the ability to indent the code according to their own preference. If your teams decides on using spaces you also need to agree on how many spaces to use for an indent. Do you pick 2 spaces, 4 spaces or something else? Odds are, someone is not going to be happy with the team's decision.

Using tabs gives everyone the freedom to indent the code to their own liking. Most editors have an option to specify how many columns a tab should indent. This allows each team member to pick the setting they're most comfortable with.

To prevent (Git) diff nightmares just follow these simple steps:

  • Always follow the convention used in the project you're working on. If it is a legacy code base and uses 5 spaces for indenting code, use 5 spaces in the code you add or modify;
  • Have your editor (or Git pre-commit hook) strip all trailing whitespace from your files. Trailing whitespace serves no purpo
@tbusser
tbusser / set-prefixed-property.js
Created February 3, 2015 13:19
Set prefixed property
var vendors = ['webkit', 'moz', 'ms'];
/**
* This method sets a CSS property. It will set the standard property as
* well as vender prefixed versions of the property.
*
* @param {HTMLElement} element The element whose property to set
* @param {string} property The unprefixed name of the property
* @param {string} value The value to assign to the property
*/
function setPrefixedProperty(element, property, value) {
@tbusser
tbusser / pad-string.js
Created March 6, 2015 11:48
Pad string
/**
* Pads a string so it will reach the requested number of characters. The
* padding will be added to the left of the original string.
*
* @param {string} value The original string, unpadded.
* @param {Number} length The desired length for the value string. Please
* note that this value should be equal to or exceed
* the unpadded length of the value parameter or
* else the result will be a clipped string.
* @param {string} padChar The character to use to pad the string. When no