Skip to content

Instantly share code, notes, and snippets.

View sanjayginde's full-sized avatar

Sanjay Ginde sanjayginde

View GitHub Profile
@sanjayginde
sanjayginde / ajax_flashable.rb
Last active December 9, 2015 22:28
Example of using the flash hash in Rails, with AJAX and a global jQuery listener.
# Add Flash messages to response
#
# Reference: http://stackoverflow.com/a/10167659/224139
# Location: app/controllers/concerns
module Concerns::AjaxFlashable
extend ActiveSupport::Concern
included do
after_filter :flash_to_headers
end
@sanjayginde
sanjayginde / Attachment_from_remote_url_with_Paperclip.md
Last active May 17, 2016 14:25 — forked from jgv/gist:1502777
Support setting a Paperclip attachment from a remote URL with a generic mixin for Rails

See also: http://almosteffortless.com/2008/12/11/easy-upload-via-url-with-paperclip/

Forked from: https://gist.github.com/1502777

The goal was a more generic solution to the one in gist this is forked from. It does not require the addition of any more db columns, as I choose not to store the remote URL.

Currently missing, is validation of the remote URL and error handling. Probably makes sense to just work with ActiveRecord::Errors

Currently, the file upload takes precedence over the the remote url, if a user supplies both. I'm thinking that should probably be an option flag on can_attach_remote_url.

@sanjayginde
sanjayginde / fixBrewLionPostgres.sh
Created January 13, 2012 16:00
Fixes up the brew Postgres installation on Mac OSX Lion (from http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/)
BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`
sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive
for i in `ls $BREW_POSTGRES_DIR`
do
if [ -f $LION_POSTGRES_DIR/$i ]