Skip to content

Instantly share code, notes, and snippets.

@shavit
shavit / post-receive
Created October 20, 2014 20:30
Git deployment for Ruby on Rails applications in production
#!/bin/sh
APP_PATH=/var/www/app
# Production environment
export RAILS_ENV="production"
exit_with_error(){
echo "---> An Error Has Occurred!"
}
#
# If you are working with the foreman gem and .env files, you are probably need to load
# the environment varialbes from the .env file.
#
# Load the environment variables from the .env file in development.
open('.env', 'r').readlines.each {|l| kv = l.split('='); ENV[kv[0]] = kv[1];}
@shavit
shavit / facebook_apps_controller.rb
Created March 15, 2013 16:32
Facebook page and canvas apps with Rails 4, can lead to a blank white page. In Rails 4, the X-Frame-Options are sets by default, and you should override them, to allow iframes in Rails.
class FacebookClubsController < ApplicationController
layout "facebook_canvas"
after_filter :allow_iframe
def index
end
private
@shavit
shavit / facebook.coffee
Created February 28, 2013 11:01
Facebook JavaScript SDK in CoffeeScript
#
# You should add the Facebook App ID and the channel url (optional), in the #fb-root element, as a data- attribute:
# <div id="fb-root" data-app-id="<%= ENV['FACEBOOK_APP_ID'] %>" data-channel-url="<%= url_no_scheme('/channel.html') %>"></div>
#
window.fbAsyncInit = ->
FB.init
appId: document.getElementById("fb-root").getAttribute("data-app-id")
channelUrl: document.getElementById("fb-root").getAttribute("data-channel-url")
status: true,
cookie: true,
@shavit
shavit / export_table_to_csv.coffee
Created July 4, 2012 20:44
Export HTML table to CSV using javascript.
$("#btnExportHTMLToCSV").click((event) ->
$table = $("#tableToExport")
if !$table
return false
headers = []
csv = ""
$table.find("thead th").each(() ->
$th = $(this)
text = $th.text()
header = '"'+text+'"'