Skip to content

Instantly share code, notes, and snippets.

@suras
suras / error_log
Created July 8, 2013 13:30
rails gem paperclip problem model.attachment_definitions problem
rails_admin paperclip error rails 4.0/ruby 2.0 paperclip- 3.4.2 rails_admin -0.5.0
model.attachment_definitions attachment definitions undefined in paperclip.rb
/home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22
:in `method_missing': undefined method `attachment_definitions' for #<Class:0xa332868> (NoMethodError)
from /home/surendar/www/cvBuilder/config/initializers/rails_admin.rb:40:in `block in <module:Fields>'
from /home/surendar/.rvm/gems/ruby-2.0.0-p0@ruby2/bundler/gems/rails_admin-fef978f2c5dc/lib/rails_adm
in/config/fields.rb:54:in `call'
@suras
suras / gist:6326679
Created August 24, 2013 07:35
Indexing email tire
include Tire::Model::Search
include Tire::Model::Callbacks
settings :analysis =>{
:analyzer => {
:uax_url_email => {
:filter => [
"standard",
@suras
suras / isbn13barcode
Last active December 25, 2015 15:08
ISBN13 barcode check digit
module IsbnCalculator
def self.isbn(num)
total = multiply_by(num, 1, 3)
mod_val = total % 10
mod_val = 10 - mod_val
final_val = mod_val == 10 ? 0 : mod_val
num.to_s + final_val.to_s
end
@suras
suras / agularjs reverse geocoding
Created December 31, 2013 13:27
angular.js getting location with html5 location api and reverse geocoding
// to get the current latitude and longitude from browser
// credits https://github.com/arunisrael/angularjs-geolocation
'use strict';
angular.module('geolocation',[]).constant('geolocation_msgs', {
'errors.location.unsupportedBrowser':'Browser does not support location services',
'errors.location.notFound':'Unable to determine your location',
});
angular.module('geolocation')
@suras
suras / gist:8387914
Created January 12, 2014 17:43
rspec with devise
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
@suras
suras / gist:8424198
Last active January 3, 2016 06:39
angular.js auto suggest
'use strict';
barterApp.directive('autosuggest', function($timeout, $http) {
return {
restrict: "E",
scope: {
modelupdate:"=",
suggestions:"=",
urlsend:"@"
},
@suras
suras / gist:8450720
Created January 16, 2014 06:39
barter.li autosuggest
'use strict';
barterApp.directive('autosuggest', function($timeout, $http) {
return {
restrict: "E",
scope: {
modelupdate:"=",
suggestions:"=",
urlsend:"@"
},
@suras
suras / gist:9089279
Last active August 29, 2015 13:56
barter.li api
get book information
get '/api/v1/book_info'
output: goodreads object
get book suggestions
get '/api/v1/book_suggestions'
output: array of book names
get nearby locations
@suras
suras / gist:9860400
Created March 29, 2014 18:42
rails has_and_belongs_to_many enabling touch updated_at when hasbtm association is created
# include this module in models where adding record of has_and_belongs_to_many asscociation
# changes the updated_at column of included model.
module HabtmTouchId
extend ActiveSupport::Concern
included do
after_initialize :create_touch_true_has_and_belongs_to_many
end
@suras
suras / gist:95e1a4c618d318efe228
Last active August 29, 2015 14:04
lovocal api
create user
POST api/v1/users
input params:
user{
mobile_number*:
}