Skip to content

Instantly share code, notes, and snippets.

View eyy's full-sized avatar

Etai Peretz eyy

  • Israel
View GitHub Profile
var arg = _.partial(_.includes, process.argv.slice(2))
@eyy
eyy / dust-helpers.js
Last active December 28, 2015 21:59
mongoose.findOne directly from dust.js
dust.helpers.mon = function(chunk, ctx, bodies, params) {
return chunk.map(function(chunk) {
var m = params.name;
if (!m || !models[m]) return chunk.write('No such model').end();
models[m].findOne().exec(function(err, doc) {
if (err) return chunk.write(err).end();
chunk.render(bodies.block, ctx.push(doc)).end();
});
});
@eyy
eyy / rivets-validate
Last active December 23, 2015 03:19
rivets jquery-validate binder (+ handle mongoose errors)
rivets.binders['on-valid'] = {
'function': true,
unbind: function(el) {
$(el).data('validator', null)
.unbind('validate');
},
routine: function(el, value) {
var handler = this.handler = this.eventHandler(value);
return $(el)
.on('submit', function() { return false; })
@eyy
eyy / hash.js
Created September 15, 2013 15:41
hash.js
(function() {
'use strict';
window.hash = {
add: function(p) {
if (-1 == window.location.hash.indexOf(p))
window.location.hash += p + ',';
},
remove: function(p) {
window.location.hash = window.location.hash.replace(p + ',', '');
@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;
};
@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": "etai@empeeric.com"
},
"dependencies": {
@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 / 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 / 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 / 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'