Skip to content

Instantly share code, notes, and snippets.

View svasva's full-sized avatar

Vitaly A. Sorokin svasva

View GitHub Profile
common =
checkEnter: (e) -> return (e.keyCode is 13 and not e.shiftKey)
stopEvent: (e) ->
e.preventDefault()
e.stopPropagation()
autoScoll: (selector) ->
Meteor.clearTimeout(scroller) if scroller?
scroller = Meteor.setTimeout (->
elm = @find(selector)
$(elm).scrollTop elm.scrollHeight), 100
Template.bikeParts.rendered = ->
$('.priceTag').popover
placement: 'left'
title: 'Buy a part'
html: true
content: -> Meteor.render(Template.buyPartPopover)
@svasva
svasva / common.coffee
Created February 14, 2013 10:38
Meteor - users online tracker
common =
keepalive: ->
(update = -> Meteor.call('keepalive') if Meteor.userId())()
Meteor.clearInterval(Meteor.keepalive) if Meteor.keepalive?
Meteor.keepalive = Meteor.setInterval(update, config.keepalive * 1000)
superagent = require 'superagent'
async = require 'async'
_ = require 'underscore'
getCurrency = (currency, cb) ->
path = 'http://currency-api.appspot.com' +
'/api/USD/' + currency + '.json' +
'?key=880ab1d06e0c4453208104d7a52e321dfba70748'
agent = superagent.agent()
agent.get(path).end (err, res) ->
cb JSON.parse(res.text)
Meteor.publishCounter = (params) ->
count = 0
init = true
id = Random.id()
pub = params.handle
collection = params.collection
handle = collection.find(params.filter, params.options).observeChanges
added: =>
count++
pub.changed(params.name, id, {count: count}) unless init
Meteor.publish 'bike', (id) ->
Meteor.publishWithRelations
handle: @
collection: Bikes
filter: id
mappings: [
key: 'userId'
options: { fields: config.users.publicFields }
collection: Meteor.users
,
@svasva
svasva / publish.js
Created February 22, 2013 10:07
Meteor publish-with-relations complex use
Meteor.publish('bike', function(id) {
return Meteor.publishWithRelations({
handle: this,
collection: Bikes,
filter: id,
mappings: [
{
key: 'userId',
options: { fields: config.users.publicFields },
collection: Meteor.users
server {
root /var/www/bikecheck-alpha/static;
server_name alpha.bikecheck.ru;
location @static_cacheable {
root /var/www/bikecheck-alpha/static_cacheable;
}
location / {
try_files $uri @static_cacheable @node;
}
<template name='loadingWrapper'>
{{#if loading}}
<i class="icon-refresh icon-spin"></i>
Loading...
{{else}}
<div class="span9">
{{renderPage}}
</div>
{{> sidebar }}
{{/if}}
Handlebars.registerHelper 'multiline', (string) ->
result = ''
for line in string.split("\n")
result += _.escape(line) + '<br/>'
return new Handlebars.SafeString(result)