Skip to content

Instantly share code, notes, and snippets.

View eyy's full-sized avatar

Etai Peretz eyy

  • Israel
View GitHub Profile
@eyy
eyy / navigation.js
Created July 3, 2013 11:04
mongoose recursive schema
schema.statics.findRecursive = function(cb) {
this.find({ show: true, menu: true })
.select('order parent url title')
.sort({ parent: -1, order: 1 })
.lean()
.exec(function(err, items) {
if (err) cb(err);
var o = {},
arr = [];
@eyy
eyy / common.js
Created July 3, 2013 15:49
slice an array to small ones
exports.eachSlice = function(object, size){
var index = - size,
slices = [];
while ((index += size) < object.length) {
slices.push(object.slice(index, index + size));
}
return slices;
};
@eyy
eyy / nano-router.js
Last active December 19, 2015 07:49
Nano-router
// nano-router
// callback will be called whenever hash is changed
var router = function(cb, t) {
var w = $(window).on('hashchange', function() {
var params = location.hash.split('/').slice(1);
cb.apply(null, params);
});
if (t) w.trigger('hashchange');
};
@eyy
eyy / bower.json
Last active December 19, 2015 07:49
scrll -- animated scroll to an element
{
"name": "scrll",
"version": "0.5.0",
"authors": [
"eyy <[email protected]>"
],
"dependencies": {
"jquery" : "*"
},
"description": "animated scroll to an element",
@eyy
eyy / jquery.fitter.js
Last active December 19, 2015 08:39
fit element contents to its width
// fit element contents to its width
(function($) {
$.fn.fitter = function() {
this.each(function() {
var el = $(this).css({
//'overflow-x': 'hidden',
'white-space': 'nowrap'
}),
fitter = el.wrapInner('<fitter />').children('fitter').css({
display: 'inline-block'
@eyy
eyy / form-json.js
Created July 4, 2013 13:16
get form data as an object, and send form as ajax
/*
$('form').serializeObject() get form data as an object
$('form').formJSON(callback) send form as ajax
example:
$('form[data-json]').formJSON(function(res) {
$('h3.message').text(res.message);
});
*/
@eyy
eyy / watchers.xml
Created July 4, 2013 16:42
WebStorm dust file watcher
<?xml version="1.0" encoding="UTF-8"?>
<TaskOptions>
<TaskOptions>
<option name="arguments" value="C:\projects\Sentr\server\compile_templates.js" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" value="" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="tl" />
<option name="immediateSync" value="true" />
<option name="name" value="dust templates" />
@eyy
eyy / jquery.animate-class.js
Created July 16, 2013 12:17
jQuery animate using CSS animations
// add class, remove it at animation end. also callback
$.fn.animateClass = function(cls, cb) {
if (typeof cb === 'string') {
var endClass = cb;
cb = function() { $(this).addClass(endClass); };
}
return $(this).one('webkitAnimationEnd', function() {
$(this).removeClass(cls);
if (cb) cb.call(this);
@eyy
eyy / mail.js
Last active December 20, 2015 04:39
send mail with express and sendgrid
/**package
{
"name": "mailson",
"description": "Mailing for kids",
"version": "0.1.0",
"author": {
"name": "Etay Perez",
"email": "[email protected]"
},
"dependencies": {
@eyy
eyy / dust-helpers.js
Created September 11, 2013 18:34
dust.js helper: first item
dust.helpers.first = function(chunk, context, bodies) {
if (context.stack.index == 0)
return chunk.render(bodies.block, context);
else if (bodies['else'])
return chunk.render(bodies['else'], context);
else
return chunk;
};