This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/," ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XML parsing does not support entity. is XHTML entity. If we parse the html or xml or html as xml then you get "Undefined entity" error in firefox error console. To make it working use unicode of (non-breakibg space character)   or simply put space (" " or  ). | |
for example : | |
<div> hello I am going to break. If you are going to use xml parser :( </div> | |
Corrected as : | |
<div>   hello I am going to break. If you are going to use xml parser :( </div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://mathiasbynens.be/demo/url-regex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://blog.wyeworks.com/2009/7/13/paperclip-file-rename | |
Paperclip.interpolates :default_image_type do |attachment, style| | |
attachment.instance.get_user_default_profile_image | |
end | |
Paperclip.interpolates :normalized_avatar_file_name do |attachment, style| | |
attachment.instance.normalized_avatar_file_name | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'zip/zip' | |
def unzip_file (file, destination) | |
Zip::ZipFile.open(file) { |zip_file| | |
zip_file.each { |f| | |
f_path=File.join(destination, f.name) | |
FileUtils.mkdir_p(File.dirname(f_path)) | |
zip_file.extract(f, f_path) unless File.exist?(f_path) | |
} |