Skip to content

Instantly share code, notes, and snippets.

View Amitesh's full-sized avatar

Amitesh Kumar Amitesh

View GitHub Profile
@Amitesh
Amitesh / gist:1311731
Created October 25, 2011 07:36
Nested Model and It's step to make it happen in rails 3
How to setup netsed model in Rails 3
========================================
CREATE TABLE `books` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`description` text,
`imported_from` varchar(255) DEFAULT NULL,
@Amitesh
Amitesh / gist:1389891
Created November 23, 2011 20:57
Problem with Kaminari pagination on Rails Active Record joins
Error Type : 1. Use "includes" instead of "joins" with kaminari pagination.
example :
books = Book.joins( :other_category ).where(['books.published_on is not null and other_categories.name like ?', "%#{category_name}%"]).order('books.title').page( page ).per( per )
it makes sql for counting the record as :
SELECT COUNT(*) FROM `books` WHERE ( books.id IN (SELECT DISTINCT other_categories.book_id FROM other_categories WHERE other_categories.name LIKE '%Fiction%')) LIMIT 10 OFFSET 20
This sql failed to return the count dues to limit and offset.
@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
@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 / 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 / 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 / .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 / 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 / gist:1556382
Created January 3, 2012 19:08
print full error message in rails
@beta_invite.errors.full_messages.join(' ')
@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);