Skip to content

Instantly share code, notes, and snippets.

@ludder
ludder / getParentByTagName.js
Created November 9, 2012 11:36
getParentByTagName - Get parent node for given tagname
/**
* Get parent node for given tagname
* @param {Object} node DOM node
* @param {String} tagname HTML tagName
* @return {Object} Parent node
*/
function getParentByTagName(node, tagname) {
var parent;
if (node === null || tagname === '') return;
parent = node.parentNode;
@ludder
ludder / slideDown.js
Created December 6, 2012 17:25
Vanilla JavaScript slideUp and slideDown functions
/*
Element to slide gets the following CSS:
max-height: 0;
opacity: 0;
overflow: hidden;
transition: max-height 0.4s ease 0s;
*/
/**
* Like jQuery's slideDown function - uses CSS3 transitions
@ludder
ludder / ios-hacks.js
Created December 6, 2012 17:27
iOS hacks
/*! A fix for the iOS orientationchange zoom bug.
Script by @scottjehl, rebound by @wilto.
MIT / GPLv2 License.
Source: https://github.com/scottjehl/iOS-Orientationchange-Fix
Explanation: http://adactio.com/journal/4470/
*/
// No code, check source above
@ludder
ludder / classList.js
Created December 6, 2012 17:28
Backwards compatible classList functions
/**
* Check element has a certain classname
* We cannot use classList yet because of browser support
* @param {Object} ele DOM element
* @param {String} cls Classname
* @return {Boolean} True is classname is found
*/
function hasClass(ele,cls) {
if (ele === null || cls === '') return false;
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
/*
Returns true if element has next sibling (of type element)
*/
function hasNextSibling(node) {
var bln = false;
while( (node = node.nextSibling) !== null ) {
if (node.nodeType !== 1) {
continue;
}
bln = true;
@ludder
ludder / Running Grunt or Codeception on Git pre-commit hook
Last active December 27, 2015 12:29
Running Grunt or Codeception on Git pre-commit hook
echo "Start Git pre commit hook"
#!/bin/sh
# stash unstaged changes, run release task, stage release updates and restore stashed files
NAME=$(git branch | grep '*' | sed 's/* //')
# don't run on rebase
if [ $NAME != '(no branch)' ]
then
@ludder
ludder / grep-search
Last active December 28, 2015 19:49
Simple grep command looking for string in files in (sub)directories
@ludder
ludder / grunt-git-hooks
Created May 20, 2014 07:45
Copy git hooks to hooks folder with Grunt
grunt.registerTask('default', function () {
var fs = require('fs');
// my precommit hook is inside the repo as /hooks/pre-commit
// copy the hook file to the correct place in the .git directory
grunt.file.copy('hooks/pre-commit', '.git/hooks/pre-commit');
// chmod the file to readable and executable by all
fs.chmodSync('.git/hooks/pre-commit', '755');
});
@ludder
ludder / pre-commit
Created February 13, 2015 14:50
Update package.json version number on git commit
#!/bin/sh
#
npm version patch
git add package.json
exit 0
@ludder
ludder / .bashrc
Created November 1, 2016 14:55
Open ios simulator from command line in OSX
# Add to .bashrc
alias ios='open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'