Skip to content

Instantly share code, notes, and snippets.

Madhusudhan Srinivasa madhums

Block or report user

Report or block madhums

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@madhums
madhums / blockcomment.rb
Created Nov 15, 2010
block comments in ruby
View blockcomment.rb
=begin
notice there is no space at the beginning of =begin
code or
#comment
.
.
.
=end
=begin
@madhums
madhums / omniauth_user_models_demo.rb
Created Nov 16, 2010
omniauth and user models (this is just for demo)
View omniauth_user_models_demo.rb
#app/models/user.rb
class User < ActiveRecord::Base
has_many :authorizations, :dependent => :destroy
end
#app/models/authorization.rb
class Authorization < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, :scope => :provider
View authorizations_controller.rb
#app/controllers/authorizations_controller.rb
class AuthorizationsController < ApplicationController
before_filter :require_user, :only => [:destroy]
def create
omniauth = request.env['rack.auth'] #this is where you get all the data from your provider through omniauth
@auth = Authorization.find_from_hash(omniauth)
if current_user
flash[:notice] = "Successfully added #{omniauth['provider']} authentication"
current_user.authorizations.create(:provider => omniauth['provider'], :uid => omniauth['uid']) #Add an auth to existing user
View user.rb
#/app/models/user.rb
class User < ActiveRecord::Base
has_many :authorizations, :dependent => :destroy
def self.create_from_hash(hash)
create(:username => hash['user_info']['name'])
end
end
@madhums
madhums / authorization.rb
Created Nov 16, 2010
authorization model
View authorization.rb
#/app/models/authorization.rb
class Authorization < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, :scope => :provider
def self.find_from_hash(hash)
find_by_provider_and_uid(hash['provider'], hash['uid'])
end
@madhums
madhums / sticky-header.js
Created Mar 26, 2011
Ever seen a sticky header that sticks to the top of window when scrolled?
View sticky-header.js
var msie6 = $.browser == 'msie' && $.browser.version < 7;
if (!msie6) {
// 'bar' is the id of the box which needs to be fixed
var top = $('#bar').offset().top - parseFloat($('#bar').css('margin-top').replace(/auto/, 0));
$(window).scroll(function (event) {
var y = $(this).scrollTop();
if (y >= top) {
// if so, add the fixed class
$('#bar').addClass('fixed');
@madhums
madhums / change-default-text.js
Created Mar 28, 2011
Changing the default text value on focus with jQuery
View change-default-text.js
$('.default-value').each(function() { // '.default-value' is the class for your fields having default values
var default_value = this.value;
$(this).css('color', '#999'); // this could be in the style sheet instead
$(this).focus(function() {
if(this.value == default_value) {
this.value = '';
$(this).css('color', '#333');
}
});
$(this).blur(function() {
@madhums
madhums / environment.rb
Created Mar 28, 2011
Upload images to paperclip with remote uri's
View environment.rb
require 'open-uri'
@madhums
madhums / browseimage.html.erb
Created Mar 28, 2011
Using flickr image search api in rubyonrails
View browseimage.html.erb
<form id="imagesearch" action="/modelname/imagesearch" method="post" >
Search for an image
<input type="text" name="query" class="floatleft" />
<input type="submit" name="submit" value="submit"/>
</form>
<center>
<div id="imageresults"></div>
</center>
@madhums
madhums / searchd
Created Apr 1, 2011
running searchd manually
View searchd
searchd --pidfile --config config/development.sphinx.conf
You can’t perform that action at this time.