Skip to content

Instantly share code, notes, and snippets.

View Amitesh's full-sized avatar

Amitesh Kumar Amitesh

View GitHub Profile
@Amitesh
Amitesh / gist:1080491
Created July 13, 2011 15:12
How to setup new gist repo
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 July 19, 2011 15:17
Add view helper function
# Include it in your class
include ActionView::Helpers::TextHelper
@Amitesh
Amitesh / gist:1117971
Created August 1, 2011 11:28
Upload file from ruby on rails program with paperclip gem
# MyModel Model
class MyModel < ActiveRecord::Base
has_attached_file :my_image,
:styles => { :small_thumb => "50x50",
:medium_thumb => "100x100"
},
:default_url => "/images/missing/prints/:style.png"
end
@Amitesh
Amitesh / gist:1124605
Created August 4, 2011 06:37
Regex with problem
1) Following regex in ruby is throwing server start (compile) time error on Mac Book Pro while on Ubuntu it is working.
# Clean all new line character
string.gsub!(/(?<!\n)\n(?!\n)/, '')
Error :
undefined (?...) sequence: /(?<!\n)\n(?!\n)/ (SyntaxError)
Solution :
string.gsub!(/\r/,"")
string.gsub!(/\n/," ")
@Amitesh
Amitesh / gist:1134115
Created August 9, 2011 14:00
svn command
svn checkout https://server.example.com/srv/svn/agaric myworkingcopyfolder
svn status
svn update
svn add yournewfilehere
svn add yournewdirectoryincludingfiles/
svn commit -m "I made changes. Woohoo." files1 files2
Use 'add' for only new file.
http://www.linuxfromscratch.org/blfs/edguide/chapter03.html#ch03-add
@Amitesh
Amitesh / gist:1136323
Created August 10, 2011 07:45
Get next previous date
//using jquery date picker
function getPreviousDay(event){
event.preventDefault();
var currDate = $('#date_box').val();
currDate = $.datepicker.parseDate('mm/dd', currDate);
var d = currDate.getDate();
var m = currDate.getMonth();
var y = currDate.getFullYear();
@Amitesh
Amitesh / gist:1151083
Created August 17, 2011 08:21
Url validator
http://mathiasbynens.be/demo/url-regex
@Amitesh
Amitesh / gist:1158827
Created August 20, 2011 08:00
Install sphinx for Rails 3
Install sphinx for Rails 3
=================================
http://freelancing-god.github.com/ts/en/installing_sphinx.html
1) Download : http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz
2) ./configure (It will configure with mysql default)
3) make
4) sudo make install
5) goto (cd) rails project directory
6) bundle exec rake ts:index RAILS_ENV=staging
@Amitesh
Amitesh / gist:1160287
Created August 21, 2011 07:24
Word wrap in Ruby
# It works for pure text only. It will fail for html and url type of text.
# http://henrik.nyh.se/2007/03/ruby-wordwrap-method
def wrap_long_string(text,max_width = 20)
(text.length < max_width) ?
text :
text.scan(/.{1,#{max_width}}/).join("<wbr>")
end
@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,