Skip to content

Instantly share code, notes, and snippets.

View pieterbeulque's full-sized avatar

Pieter Beulque pieterbeulque

View GitHub Profile
@pieterbeulque
pieterbeulque / keyboard-navigation.js
Created December 22, 2012 12:19
Keyboard navigation with jQuery
var keyboardNavigation = function (e) {
// Disables the keyboard navigation in textfields
if ($(e.target).is('input, textarea')) return false;
switch (e.which) {
// Your keyboard navigation switch-cases
}
}
$(document).ready(function () {
@pieterbeulque
pieterbeulque / main.js
Created August 12, 2013 16:49
Adding a class to an element when it touches the top of the viewport
$(document).ready(function () {
var $el = $('element'),
offset = $el.offset().top,
class = 'your-class';
$(window).on('scroll', function () {
if ($('body').scrollTop() >= offset) {
$el.addClass(class);
} else {
$el.removeClass(class);
@pieterbeulque
pieterbeulque / testwifi.sh
Created March 25, 2014 14:43
Reboot on network drop
ping -c4 192.168.1.1 > /dev/null
if [$? != 0]
then
sudo /sbin/shutdown -r now
fi
@pieterbeulque
pieterbeulque / _mobile-navigation.scss
Last active August 29, 2015 14:07
Site container
// @todo
$mobile-navigation-width: 280px;
$mobile-navigation-levels: 1;
.mod-mobile-navigation {
position: fixed;
top: 0;
right: 0;
bottom: 0;

Setting up a new Mac for development

Let's get you going as fast as possible.

First of all, download xCode from the App Store and install everything (including Command Line Tools).

Brew, brew, baby

Install Homebrew:

@pieterbeulque
pieterbeulque / magic.md
Created March 13, 2015 13:58
Changing SCSS transform: to @include transform

When working with Autoprefixer, you get used to writing prefixless SCSS.

If you discover you've been working in a Compass / Bourbon project without Autoprefixer and you can't add it, do this magical find and replace:

Find: ^(\s+)transform:(.+); Replace: $1@include transform($2);

This will update all transform: transform1, transform2; to @include transform(transform1, transform2);, keeping your indentation intact.

@pieterbeulque
pieterbeulque / smoothie.js
Created April 2, 2015 14:40
Smooth scroll
$(document.body).on('click', 'a[href^="#"]:not(a[href="#"])', function (e) {
var $target = $($(this).attr('href'));
if ($target.length > 0) {
e.preventDefault();
$('html, body').animate({
scrollTop: $target.offset().top
}, 440);
}
});
@pieterbeulque
pieterbeulque / validate.js
Created July 29, 2015 12:51
Validating stuff in JS
window.validate = window.validate || {};
window.validate.date = function (raw) {
var date, parsed;
date = raw.split(/[\D]+/);
if (date.length !== 3 || date[0].length > 2 || date[1].length > 2 || (date[2].length !== 2 && date[2].length !== 4)) {
return false;
}
@pieterbeulque
pieterbeulque / dootdoot.md
Created July 30, 2015 12:43
Deploying older Lalala setups

When deploying an older Lalala website (Rails 2 / Ruby 1.9.*):

  • Make sure you're running Ruby 1.9.3 (neccessary for development on OS X 10.9+ anyway)
  • Add gem 'platform-api', '~>0.2.0' to your Gemfile. There's a version 0.3.0 that breaks the deploy rake task.
  • $ bundle update to update to the latest Lalala & the correct platform-api version
  • Make sure you're not using the Heroku gem ($ gem uninstall heroku)
function onTransitionEnd (callback, $element) {
if ('ontransitionend' in window || 'onwebkittransitionend' in window ) {
$element.on('transitionend', callback);
} else {
callback();
}
}
onTransitionEnd(() => { console.log('hey'); }, $(document.body));