Skip to content

Instantly share code, notes, and snippets.

Amitesh Kumar Amitesh

Block or report user

Report or block Amitesh

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
@Amitesh
Amitesh / gist:1022715
Created Jun 13, 2011
Get hash of a model object
View gist:1022715
# For Ruby on Rails
# It will give hash of given model object
model_obj.serializable_hash
# Another way to get hash of a model object
ActiveSupport::JSON.decode(model_obj.to_json)
For MultiJson issue use
https://github.com/intridea/multi_json
@Amitesh
Amitesh / gist:1024607
Created Jun 14, 2011
request forgery protection in Rails
View gist:1024607
# While using curl post call then disable request forgery protection
# For get method call, It skips the check
# Reference : http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
class XyzController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:update]
before_filter :authenticate_user!, :only => [:update, :index]
end
@Amitesh
Amitesh / gist:1037742
Created Jun 21, 2011
Resources/Likns to create Rails 3 Engine
View gist:1037742
https://github.com/elricstorm/baby_dove
https://github.com/drhenner/ror_ecommerce
http://ror-e.com/info/videos/5
http://edgeapi.rubyonrails.org/classes/Rails/Engine.html
https://github.com/krschacht/rails_3_engine_demo/tree/master/app
https://github.com/jrwest/authr3
https://github.com/mankind/Rails-3-engine-stub/wiki/How-to-building-a-rails-3-engine-and--set-up-test--with-rspec
https://github.com/technicalpickles/jeweler
http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/
https://gist.github.com/af7e572c2dc973add221#file_3_plugin.rdoc
@Amitesh
Amitesh / gist:1039620
Created Jun 22, 2011 — forked from arnabc/gitosis-repo-creation
Gitosis repo creation ( it assumes that you have a working gitosis repository in a central server and have the permission to create new repositories)
View gist:1039620
Add repo in local gitosis-admin/gitosis.conf
~$ mkdir your_repo_name
~$ cd your_repo_name
~$ git init
~$ git remote add origin git@YOUR_SERVER_HOSTNAME:your_repo_name.git
# do some work, git add and commit files
~$ git add .
~$ git commit -m 'Your Message'
@Amitesh
Amitesh / gist:1046269
Created Jun 25, 2011
Set Rails Engine/Gem public assets path, to server it from Engine/Gem itself
View gist:1046269
require "rails"
module MyEngine
class Engine < Rails::Engine
# We can add all of the public assets from our engine and make them
# available to use. This allows us to use javascripts, images, stylesheets
# etc.
initializer "static assets" do |app|
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
@Amitesh
Amitesh / gist:1046278
Created Jun 25, 2011
Set the simple-navigation file path of a Rails Engine app to auto load path of Rails 3 Main App
View gist:1046278
require "rails"
require 'simple-navigation'
module MyEngine
class Engine < Rails::Engine
#Give the absolute path of file
#config.autoload_paths << File.expand_path("../../../config/navigations", __FILE__)
SimpleNavigation.config_file_path = File.expand_path("../../../config/navigations", __FILE__)
@Amitesh
Amitesh / reset_mysql_password.sh
Created Jul 13, 2011
Reset Mysql root password
View reset_mysql_password.sh
Reset Mysql root password
$ sudo stop mysql
$ sudo start mysql
$ mysql -u root
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('a_real_pwd');
mysql> exit
bye
try : mysql -uroot -p
@Amitesh
Amitesh / gist:1080491
Created Jul 13, 2011
How to setup new gist repo
View gist:1080491
Global setup:
Set up git
git config --global user.name "Amitesh Kumar"
git config --global user.email amitesingh@gmail.com
Next steps:
mkdir TinyMCE-YouTube-Plugin
cd TinyMCE-YouTube-Plugin
git init
touch README
@Amitesh
Amitesh / gist:1092715
Created Jul 19, 2011
Add view helper function
View gist:1092715
# Include it in your class
include ActionView::Helpers::TextHelper
@Amitesh
Amitesh / gist:1113683
Created Jul 29, 2011
Open popup window in center of screen in javascript
View gist:1113683
var top = window.screen.height - 300;
top = top > 0 ? top/2 : 0;
var left = window.screen.width - 400;
left = left > 0 ? left/2 : 0;
var uploadWin = window.open(url,"Upload Chapter content","width=400,height=300" + ",top=" + top + ",left=" + left);
uploadWin.moveTo(left, top);
uploadWin.focus();
You can’t perform that action at this time.