Skip to content

Instantly share code, notes, and snippets.

View Amitesh's full-sized avatar

Amitesh Kumar Amitesh

View GitHub Profile
@Amitesh
Amitesh / devise setup.rb
Created January 27, 2012 07:56
Add Devise
- Add in Gem file
gem devise
- Install devise
$ rails generate devise:install
- Generate user model and routes
$ rails generate devise user
- Add extra fields
@Amitesh
Amitesh / gist:1723426
Created February 2, 2012 13:17
Tableless model with validation
# http://rails-bestpractices.com/posts/48-use-openstruct-when-advance-search
class Tableless
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(props = {})
props.each do |name, value|
send("#{name}=", value)
end
@Amitesh
Amitesh / gist:1723470
Created February 2, 2012 13:26
OpenStruct
<%= form_for OpenStruct.new(:message => ''), :url => ... do |f| %>
<%= f.text_field :message %>
<% end %>
# config/initializers/open_struct_extensions.rb
class OpenStruct
def respond_to?(symbol, include_private = false)
@Amitesh
Amitesh / rails_helper.rb
Created April 28, 2012 12:41
Accessing Helper modules in rails
Accessing Helper modules in rails
http://www.funonrails.com/2010/12/accessing-helper-modules-in-rails.html
1. Helper methods all the time for views
class ApplicationController < ActionController::Base
helper :all# include all helpers, all the time for views
end
@Amitesh
Amitesh / gist:2669286
Created May 12, 2012 21:46
Textext sample
$('#cities')
.textext({
plugins : 'autocomplete tags ajax prompt',
prompt : 'Enter a city or town',
ajax : {
url : DrumBeatGlobals.get_cities_url,
data : {country : 'US' },
dataType : 'json',
loading : { message : 'Loading...'}
},
@Amitesh
Amitesh / gist:2758752
Created May 20, 2012 16:54
Sample js class
/**
* Description
* Author: Amitesh Kumar ([email protected])
* Date: 20th May, 2012
*
*/
/**
* Module to display social info about a place
*/
@Amitesh
Amitesh / app.js
Created July 11, 2012 10:26
New App JS bootup scripts
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
/**
* Module for SampleWebApp Application
* @author : Amitesh Kumar
*
*/
( function( $ ){
@Amitesh
Amitesh / gist:3150072
Created July 20, 2012 10:33
Preety print json on UI
Device wise apps :
<pre>
<%= JSON.pretty_generate(JSON.parse(@info.to_json)) %>
</pre>
@Amitesh
Amitesh / gist:3264898
Created August 5, 2012 13:43
Check Database, table and columns character set in mysql
SELECT default_character_set_name FROM information_schema.SCHEMATA S
WHERE schema_name = "database_name";
show FULL columns from table_name;
For Schemas:
SELECT default_character_set_name FROM information_schema.SCHEMATA S
WHERE schema_name = "schemaname";
For Tables:
@Amitesh
Amitesh / convert.rake
Created August 9, 2012 10:05 — forked from mperham/convert.rake
Ruby script to update MySQL from Latin1 to UTF8 without data conversion
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
end
else