Skip to content

Instantly share code, notes, and snippets.

View diatmpravin's full-sized avatar

Pravin Mishra diatmpravin

View GitHub Profile
def facebook
if facebook.nil?
FbGraph::User.new('me', :access_token => self.fbauth.token).fetch
else
return facebook
end
end
@diatmpravin
diatmpravin / gist:4503766
Created January 10, 2013 16:59
active-admin-sample-form-index-show for nested form
ActiveAdmin.register Bar do
# controller.load_and_authorize_resource
controller do
load_and_authorize_resource :except => [:update, :index, :show, :edit]
def scoped_collection
end_of_association_chain.accessible_by(current_ability)
end
end
@diatmpravin
diatmpravin / gist:4596654
Created January 22, 2013 17:54
multi-table-ex
class User < ActiveRecord::Base
attr_accessible :fname, :lname
has_many :parents, :dependent => :destroy
def self.export_to_csv(filename, model, options = {})
csv_options = {}
csv_options[:col_sep] = options[:separator] || ','
header = User.header(model,options = {})
data = User.data(model)
@diatmpravin
diatmpravin / gist:4654474
Created January 28, 2013 10:31
rspec code
require 'spec_helper'
describe Import do
TEST_FILENAME = 'test/fixtures/csv/2XU.txt'
ERROR_FILENAME = 'test/fixtures/csv/2XU_errors.txt'
before :all do
HEADER_ROWS = 2
VARIATION_THEMES = %w(Size Color SizeColor)
@diatmpravin
diatmpravin / any_of
Last active December 18, 2015 07:09
Add `#any_of` query method to active_record
1.9.3-p392 :060 > Address.all
Address Load (0.4ms) SELECT "addresses".* FROM "addresses"
+----+---------+--------+---------+---------+----------+-------+--------+-------------------------+-------------------------+
| id | user_id | extra | city | country | postcode | state | street | created_at | updated_at |
+----+---------+--------+---------+---------+----------+-------+--------+-------------------------+-------------------------+
| 1 | 1 | ankit | asansol | india | 71475 | w.b. | 100 | 2013-06-09 09:22:04 UTC | 2013-06-09 09:22:04 UTC |
| 2 | 1 | sanyam | asansol | india | 71476 | w.b. | 101 | 2013-06-09 09:22:05 UTC | 2013-06-09 09:22:05 UTC |
| 3 | 2 | abhay | asansol | india | 71476 | w.b. | 102 | 2013-06-09 09:22:05 UTC | 2013-06-09 09:22:05 UTC |
| 4 | 3 | abhay | bettiah | india | 71476 | w.b. | 102 | 2013-06-09 09:22:05 UTC | 2013-06-09 09:22:05 UTC |
+----+---------+--------+---------+---------+---
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'arel'
gem 'mysql2'
GEMFILE
system 'bundle'
end
@diatmpravin
diatmpravin / ar-has_many_throught
Created February 2, 2014 06:33
AR bug with circular destroy: I am able to replicate this issue for later release including 4.0.0 for has_many relationship. It's fine for earlier release.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'arel'
gem 'mysql2'
GEMFILE
system 'bundle'
end
@diatmpravin
diatmpravin / ar-has_one_throught
Last active August 29, 2015 13:55
AR bug with circular destroy: I am able to replicate this issue for later release including 4.0.0 for has_one relationship. It's fine for earlier release.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'arel'
gem 'mysql2'
GEMFILE
system 'bundle'
end
@diatmpravin
diatmpravin / go_mongodb_sample_app
Created March 11, 2014 12:04
Go+Martini+mgo(mongodb driver) Sample Application
package main
import (
"fmt"
"github.com/codegangsta/martini" // loading in the Martini package
"github.com/martini-contrib/render"
"labix.org/v2/mgo" // loading in the mgo MongoBD driver package
"labix.org/v2/mgo/bson" // loading in the bson package
"net/http"
)
@diatmpravin
diatmpravin / task.go
Created March 12, 2014 18:34
Revel Sample Controller
package controllers
import (
"github.com/revel/revel"
"ToGo/app/models"
"ToGo/app/routes"
"github.com/jinzhu/gorm"
type Task struct {
ModelController