Skip to content

Instantly share code, notes, and snippets.

View sanjayginde's full-sized avatar

Sanjay Ginde sanjayginde

View GitHub Profile
@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 ]
@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 / 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 / file_size_validation.jqtools.js
Last active December 11, 2015 17:29
JavaScript file size validation for HTML 5, using jQuery Tools validation and Parsley validation. (Additionally, extended modernizer for HTML5 File API.). The 'data-filemaxsize' attribute should be set in megabytes.
/**
* File size validation using jQuery Tools Validation (http://jquerytools.org/documentation/validator/index.html)
*/
if (Modernizr.fileapi) {
$.tools.validator.fn('input[type="file"][data-filemaxsize]', function($file_input, value) {
var files = $file_input.get(0).files,
max_megabytes = parseInt($file_input.data('filemaxsize')),
max_bytes = max_megabytes * BYTES_PER_MEGABYTE;
if (files.length > 0 && files[0].size > max_bytes) {
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@sanjayginde
sanjayginde / jquery.rails.async-confirm-dialog.js
Last active December 13, 2015 17:38
Implementation of custom, async confirmation dialog with Rails UJS
;(function($, document) {
$(document).delegate('a[data-confirm]', 'confirm', function(event) {
event.preventDefault();
var $link = $(this);
// Placeholder for custom confirmation popup, etc
my_custom_dialog_widget.confirm({
message: $link.attr('data-confirm'),
title: "Are you sure?",
@sanjayginde
sanjayginde / empty.html.haml
Last active December 18, 2015 14:49
Example to 'disable' layouts in a Rails controller test. Uses an 'empty' layout, which can allow for testing that the the title tag and javascript is properly added...
-# Empty layout used as layout replacement for testing...
!!! 5
!= html5_haml_tag(:lang => 'en') do
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
%title=h ((title=yield(:title)).blank?) ? "Contently" : "#{title} : Contently".html_safe
%body
=yield
=yield :javascript
=yield :jstemplates
@sanjayginde
sanjayginde / read-more.css.sass
Created February 20, 2014 19:44
Read more/less
.expandable
.read-more, .read-less
// link styles go here (if needed)...
.long-content
display: none

Keybase proof

I hereby claim:

  • I am sanjayginde on github.
  • I am sanjayginde (https://keybase.io/sanjayginde) on keybase.
  • I have a public key whose fingerprint is 20C7 5D65 4559 F7B2 26F7 173E 2C75 9150 3F79 4AF9

To claim this, I am signing this object:

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
function base64_decode(input){
var output = new Array();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
var orig_input = input;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
if (orig_input != input)