Skip to content

Instantly share code, notes, and snippets.

View eyy's full-sized avatar

Etai Peretz eyy

  • Israel
View GitHub Profile
@eyy
eyy / rout-example.html
Last active August 29, 2015 14:25
Rout.js – DOM Router
<style>
route {
display: block;
background: yellow;
}
route[path] {
display: none;
}
</style>
@eyy
eyy / click-all-images.js
Created June 10, 2015 23:09
click on all images
[].map.call(document.querySelectorAll('img'), function(el) { el.click() })
@eyy
eyy / dot.js
Created June 2, 2015 11:07
dot path; dot({ prop: { inner: 1 } }, 'prop.inner') == 1
// dot path; dot({ prop: { inner: 1 } }, 'prop.inner') == 1
function dot (o, path) {
if (!path)
return o
var p = path.split('.')
while (p.length > 0) {
o = o[p.shift()]
if (o == undefined)
break
@eyy
eyy / package.json
Created May 14, 2015 21:00
webpack react hi
{
"scripts": {
"dev": "webpack-dev-server --inline --hot"
}
}
@eyy
eyy / app.js
Last active April 3, 2021 18:57
Auto reload everything: stylus, browser-sync, express, nodemon
var app = express()
// browser sync
if (app.get('env') === 'development') {
var bs = require('browser-sync')({
logSnippet: false,
files: ['pub/*.html', 'pub/css/*.css', 'views']
})
app.use(require('connect-browser-sync')(bs))
}
@eyy
eyy / updateArray.js
Created March 8, 2015 12:48
update array
function updateArray (arr, newArr) {
if (!arr.index)
arr.index = arr.reduce(function(seed, item) {
seed[item.id] = item
return seed
}, {})
newArr.forEach(function(item) {
if (arr.index[item.id])
return _.assign(arr.index[item.id], item)
@eyy
eyy / text-mixin.styl
Created December 30, 2014 22:11
stylus text mixin: font-size, color, line-height etc. w/o trouble or order
alignment = left center right justify start end
text()
sized = false
for arg in arguments
if arg is a 'color'
color arg
else if arg is a 'unit'
if sized
line-height arg
else
@eyy
eyy / bookmarklet-next-image.js
Last active August 29, 2015 13:55
Bookmarklet: Jump to next image (J)
javascript:(function() { var i = 0; function nextImg() { var imgs = document.querySelectorAll('img'), el; while (i < imgs.length) { el = imgs[i]; i++; if (el.getBoundingClientRect().top > 0) { return el.scrollIntoView(); } } i = 0; } document.addEventListener('keypress', function(e) { var key = String.fromCharCode(e.keyCode || e.which); if (key == 'j') nextImg(); }); nextImg(); })();
@eyy
eyy / mobile-nav.js
Created January 19, 2014 16:20
mobile navigation
/*
Mobile navigation
*/
var nav = $('nav');
nav.on('click touchstart', function(e) {
if (!$(e.target).is('.active'))
return;
e.preventDefault();
e.stopPropagation();
@eyy
eyy / easy-parallax.js
Created January 9, 2014 21:45
easy parallax
// based on http://codepen.io/zitrusfrisch/pen/bJwhk
function easyParallax() {
var scrollPos = w.scrollTop();
$('#banner').css({
'background-position' : '50% ' + (-scrollPos/4)+"px"
});
$('#bannertext').css({
'margin-top': (scrollPos/4)+"px",
'opacity': 1-(scrollPos/250)
});