Skip to content

Instantly share code, notes, and snippets.

View Amitesh's full-sized avatar

Amitesh Kumar Amitesh

View GitHub Profile
@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 / 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 / slideshow.js
Created January 24, 2012 12:18 — forked from qawemlilo/slideshow.js
A simple slide show
/*
Author: Qawelesizwe Mlilo
Email: [email protected]
Dependency: Mootools
Notes: This code was used in a Joomla! project and can be easily modified to run without a library
*/
var slideShow = function (img, o) {
this.element = $(img);
@Amitesh
Amitesh / gist:1556382
Created January 3, 2012 19:08
print full error message in rails
@beta_invite.errors.full_messages.join(' ')
@Amitesh
Amitesh / gist:1478532
Created December 14, 2011 21:07
class mixin in ruby
require 'support/discussions' #require module
class Admin::DiscussionsController < ApplicationController
include Support::Discussions
def index
# Call class/static method
Admin::DiscussionsController.test()
#Call instance method
test2()
@Amitesh
Amitesh / .htaccess
Created December 9, 2011 12:53 — forked from aarongustafson/.htaccess
An example of how Costco could redirect mobile requests properly
# setup
RewriteEngine on
RewriteBase /
# product redirection based on iPhone and product request
# note: the user agent check is contrived, you should have
# a much more robust checker
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{QUERY_STRING} Prodid=(\d+)
RewriteRule ^Browse\/Product\.aspx http://m.costco.com/costco/product/productDirectDetail.do?itemId=%1 [R=301,L]
@Amitesh
Amitesh / backup-to-git.sh
Created December 9, 2011 12:53 — forked from aarongustafson/backup-to-git.sh
DB Backup to Git
#!/bin/bash
##
# MySQL DB dump to Git commit
#
# Dumps the specified mysql database to the given location and commits it and
# the previous database to the Git repository.
#
# It is assumed you have already setup the Git respository to only be the
# a checkout of the database backup location
@Amitesh
Amitesh / TinyMCE-config-HTML5.js
Created December 9, 2011 12:37 — forked from aarongustafson/TinyMCE-config-HTML5.js
Working on a TinyMCE config that supports HTML5
// General
button_tile_map : true,
editor_selector : 'lg_mceEditor',
mode:'textareas',
theme : 'advanced',
// Cleanup/Output
apply_source_formatting : true,
convert_fonts_to_spans : true,
convert_newlines_to_brs : false,
@Amitesh
Amitesh / word-wrap
Created November 26, 2011 20:24
Word wrap in Ruby
# we can change the <wbr> and <br> as per our requirement.
def wrap_long_string(text, max_width = 20)
if text.blank?
return text
end
sp = text.split(/\n/)
sp.collect!{|s|
s = (s.length < max_width) ? s : s.scan(/.{1,#{max_width}}/).join("<wbr>")
}
@Amitesh
Amitesh / gist:1394548
Created November 25, 2011 22:20
mysql 5.5.13 and ruby mysql gem updation
install mysql 5.5.13
Install 5.5.13 from doc for our IM server
after installation do
( to get ride of ruby issue )
gem pristine --all
not found shared libmysqlclient_r.so.16 file
sudo chown -R mysql table1
sudo chgrp -R mysql table1