Skip to content

Instantly share code, notes, and snippets.

View gabrielhpugliese's full-sized avatar

Gabriel H Pugliese gabrielhpugliese

View GitHub Profile
@gabrielhpugliese
gabrielhpugliese / gist:3973258
Created October 29, 2012 12:27
Auto Graph App
jQuery(document).ready(function(){
var $head = jQuery('head');
var img_src = jQuery('img').attr('src');
if (img_src.indexOf('http://') == -1 && img_src.indexOf('https://') == -1)
img_src = window.location.protocol + '//' + window.location.hostname + jQuery('img').attr('src');
var ogp_tags = {'title': $head.find('title').text().trim(),
'url': window.location.href,
'description': '[%description%]' ? '[%description%]' : jQuery('.lead').html(),
'image': '[%image%]' ? '[%image%]' : img_src,
'type': '[%type%]' ? '[%type%]' : 'website'};
@gabrielhpugliese
gabrielhpugliese / gist:4039758
Created November 8, 2012 16:09
facebook comments
function getElementsByClassName(classname, node) {
if(!node) node = document.getElementsByTagName("body")[0];
var a = [];
var re = new RegExp('\\b' + classname + '\\b');
var els = node.getElementsByTagName("*");
for(var i=0,j=els.length; i<j; i++)
if(re.test(els[i].className))a.push(els[i]);
return a;
}
@gabrielhpugliese
gabrielhpugliese / client.js
Created December 2, 2012 14:17
meteor login with facebook
/* Imagine you want to develop a facebook canvas app.
This snippet will do all the auth dance without requiring the user to click on login.
But if the user is not logged in facebook, it will ask for the user to login.
Tip: Open the browser console to see debug messages.
Followed instructions of Facebook: https://developers.facebook.com/docs/howtos/login/getting-started/
It's is possible to improve this code with more error handling.
*/
if (Meteor.is_client) {
@gabrielhpugliese
gabrielhpugliese / application.js
Created February 12, 2013 18:47
Subscription is not working like it was.
if (Meteor.isClient) {
Meteor.startup(function(){
Session.set('MediasLoading', true);
Meteor.autosubscribe(function(){
Meteor.subscribe('Medias', function(){
Session.set('MediasLoading', false);
});
});
});
}
get_data = function(user_id, path, fql) {
var token = Meteor.users.findOne(user_id).services.facebook.accessToken,
fb_url = 'https://graph.facebook.com',
response;
if (path) {
response = Meteor.http.get(fb_url + path + '?access_token=' + encodeURIComponent(token));
} else {
response = Meteor.http.get(fb_url + '/fql?q=' + fql + '&access_token=' + encodeURIComponent(token));
}
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '436933159676108', // App ID from the App Dashboard
// channelUrl : '//localhost:3000/channel.html', // Channel File for x-domain communication
channelUrl : 'https://www.friendtrumps.com/channel.html', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true, // parse XFBML tags on this page?
frictionlessRequests : true,
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ true));
window.fbAsyncInit = function() {
// init the FB JS SDK
@gabrielhpugliese
gabrielhpugliese / applications.js
Created March 13, 2013 23:29
Reset Session context in hot code push
if (Meteor._reload) {
Meteor._reload.onMigrate('session', function() {
return [true, {
keys : []
}];
});
(function() {
var migrationData = Meteor._reload.migrationData('session');
if (migrationData && migrationData.keys) {
KEEPALIVE_INTERVAL = 5*1000;
Meteor.setInterval(function(){
Meteor.call('keepalive');
}, KEEPALIVE_INTERVAL);
from flask import Flask
from views import *
app = Flask(__name__)
app.register_blueprint(views_bp)
views_bp.add_url_rule('/',
view_func=MainView.as_view('main'))