Skip to content

Instantly share code, notes, and snippets.

View Pent's full-sized avatar
🧲
magnetizing

Pent

🧲
magnetizing
View GitHub Profile
Template.someModal.rendered = function() {
$(this.find('#modal')).hide().fadeIn();
};
@Pent
Pent / client.js
Last active September 30, 2016 12:18
Reactive publication/subscription using Meteor
Deps.autorun(function() {
Meteor.subscribe('messages', Session.get('query'));
})
@Pent
Pent / gist:5700692
Last active December 18, 2015 00:59
Meteor IRC ping/pong function to prevent ping timeouts, client refers to the node-irc instance
client.addListener('PING', function() {
Fiber(function() {
client.send('PONG');
}).run();
});
@Pent
Pent / gist:5690489
Last active December 17, 2015 23:39
Use reactive data in find query
Client----
Deps.autorun(function() {
Meteor.subscribe('messages', Session.get('room'));
});
Server----
Meteor.publish('messages', function(room) {
return Messages.find({room_id: room});
});
@Pent
Pent / gist:5667475
Last active December 17, 2015 20:28
Include an NPM with meteor
1. Place files in /meteor-project-root/packages/x/ replace x with package name
2. meteor add x
------- x.js --------
X = Npm.require('x');
------- package.js --------
Package.describe({
summary: "Meteor smart package for x node.js package"
});
@Pent
Pent / gist:5650336
Last active December 17, 2015 17:59
Fade in the element when a new object is added to collection in Meteor
client.js ------
Template.message.rendered = function() {
$(this.find('div')).hide().fadeIn();
};
@Pent
Pent / gist:5650187
Created May 25, 2013 18:27
when new record is added to collection, do something (in this case: scroll the page)
Meteor.subscribe('messages', function() {
return Messages.find().observe({
added: function() {
scrollToBottom();
}
});
});
@Pent
Pent / gist:5650108
Created May 25, 2013 18:05
geolocation in meteor
client.js ------
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
Session.set('lat', position.coords.latitude);
Session.set('lon', position.coords.longitude);
}, function(error) {
}, { enableHighAccuracy: true });
}
Template.userLayout.location = function () {
@Pent
Pent / gist:5649329
Created May 25, 2013 14:49
lastfm api access through meteor
var response = Meteor.http.get('http://ws.audioscrobbler.com/2.0/?method=tasteometer.compare&type1=user&type2=user&value1='+query[0]+'&value2='+query[1]+'&api_key='+config.lastfmClientId+'&format=json');
if (response.statusCode === 200) {
var data = response.data;
if(data.comparison) {
return " score: "+ data.comparison.result.score;
}
}
@Pent
Pent / gist:5637550
Created May 23, 2013 16:52
modified deploy script
#!/bin/bash
# IP or URL of the server you want to deploy to
export APP_HOST=IP_ADDRESS_HERE
export APP_ROOT=root
export APP_NAME=YOUR_APP_NAME
export APP_PORT=3000
export ROOT_URL=http://$APP_HOST:$APP_PORT
export APP_DIR=/srv/www/$APP_HOST/$APP_NAME
export MONGO_URL=mongodb://localhost:27017/$APP_NAME
export SSH_HOST="$APP_ROOT@$APP_HOST"