Segmentation Fault while doing bundle install

I recently encountered this error of segmentation fault while doing bundle install in one of my rails application.

After a bit of googling I found out its an issue with ruby 1.9.3.

Here is the solution:

 

rvm pkg install iconv
 rvm pkg install openssl
 rvm reinstall 1.9.3 --with-openssl-dir=~/.rvm/usr --with-iconv-dir=~/.rvm/usr

 

, , , ,

Leave a Comment

Installing and setting up GIT

INSTALLING GIT
Installing from Source:
In short, on a Unix-based system, you can download the Git source code from the Git Download Page, and then run
something along the lines of :

$ make prefix=/usr all ;# as yourself
$ make prefix=/usr install ;# as root

You will need the expat, curl, zlib, and openssl libraries installed – though with the possible exception of expat, these will normally already be there.

Linux
If you are running Linux, you can likely install Git easily via your native package management system:

$ yum install git-core
$ apt-get install git-core

Mac 10.4:
In both Mac 10.4 and 10.5, you can install Git via MacPorts, if you have that installed. If not, you can install it from here.
Once MacPorts is installed, all you should have to do is:

$ sudo port install git-core

If you prefer to install from source, these articles may be helpful:
Article: Installing Git on Tiger
Article: Installing Git and git-svn on Tiger from source

Mac 10.5
With Leopard, you can also install via MacPorts, but here you have the additional option of using a nice installer, which you can download from here: Git OSX Installer
If you prefer to install it from source, these guides may be particularly helpful to you :
Article: Installing Git on OSX Leopard
Article: Installing Git on OS 10.5

SETUP AND INITIALIZATION
Git Config
The first thing you’re going to want to do is set up your name and email address for Git to use to sign your commits.

$ git config –global user.name “Rushabh hathi”
$ git config –global user.email “rushabhhathi@gmail.com”

That will set up a file in your home directory which may be used by any of your projects. By default that file is ~/.gitconfig
and the contents will look like this:
[user]
name = Rushabh Hathi
email = rushabhhathi@gmail.com

If you want to override those values for a specific project (to use a work email address, for example), you can run the git config command without the –global option while in that project. This will add a [user] section like the one shown above to the .git/config file in your project’s root directory.

, ,

Leave a Comment

Resizing the image without chaning its dimensions using paperclip

Hi,

In a recent application, the need of the hour was to reduce the file size of an image without changing its dimensions.

Now, this can be acheived by reducing the quality of the image.

ImageMagick library has a “convvert” command which does exactly the same..

for eg(on the terrminal) : convert image1.jpg -quality 10 image2.jpg

image1.jpg—>original image

image2.jpg—->final image

 

According to the paperclip wiki there is a :quality parameter which is allowed.

I tried that but for some reasons , I was not able to get it running.

I also tried using :convert_options but it did not work too.

 

Thus , I wrote my own processor and got the stuff working. Here is the model and processor code :

#######Model code###########

class Passet < ActiveRecord::Base
attr_accessible :caption, :markup, :media_passet, :pcontent_id
has_attached_file :media_passet,
:styles => {
: original => {
:geometry => “256×256<”,
:processors => [:qresize]
}
}
belongs_to :pcontent
end

 

###################Processor code########################

make a file called qresize.rb in #{Rails.root}/lib/papaerclip_processors

The path is mentioned because this path is loaded automatically….

module Paperclip
# handles compression of image by reducing its quality
class Qresize < Processor
def initialize file, options = {}, attachment = nil
super
@format = File.extname(@file.path)
@basename = File.basename(@file.path, @format)
end
def make
src = @file
dst = Tempfile.new([@basename, @format])
dst.binmode
begin
parameters = []
parameters << “:source”
parameters << “-quality 10″
parameters << “:dest”
parameters = parameters.flatten.compact.join(” “).strip.squeeze(” “)
success = Paperclip.run(“convert”, parameters, :source => “#{File.expand_path(src.path)}[0]“, :dest => File.expand_path(dst.path))
rescue PaperclipCommandLineError => e
raise PaperclipError, “There was an error during the Size Reduction  for #{@basename}” if @whiny
end
dst
end
end
end

 

This is a general code for image resizing and probably at this stage, we may not require to write a processor.

But the advantage of doing this is that we can extend this to do a lot more as and when requirement comes.

Also, we can handle our video and audio processing by this easily.

The other option is to pass a block(lambda or Proc) to :styles hash but I personally feel this is a much cleaner approach.

 

Hope it helps.

, , , ,

1 Comment

PreProcessing in Paperclip

Hi.

If at all you want to do any kind of prepreocessing on attachments using paperclip then here is a simple(not wen i did it for the first time…) way of getting a TempFile object and doing whatever you want.

Here I set the size of image (actually reduce the original size into half)

 

class Passet < ActiveRecord::Base
attr_accessible :caption, :markup, :media_passet, :pcontent_id
has_attached_file :media_passet,
:styles => {

: original => {
:geometry => Proc.new { |instance| instance.set_size },
:quality => 10
}
}

belongs_to :pcontent

def set_size

ori_img =Paperclip::Geometry.from_file(self.media_passet.queued_for_write[:original].path)

“#{ori_img.width/2}x#{ori_img.height/2}”

end
end

Here I reduce the dimensions if the image and reduce the quality too.

This way, I can save a 1.1MB image as 39.2KB image,

It it what I required,and I hope this will give you a hint about your own application.

 

Hope it helps.

PS: there are many other(mayb elegant solutions) which can be found on paperclip github page whose link I have posted above.

, , ,

Leave a Comment

Installing sun (oracle) jdk in precise pangolin..

Finally, after doing many things unsuccessfully,

this method works for me:

sudo rm /var/lib/dpkg/info/oracle-java7-installer* 
sudo apt-get purge oracle-java7-installer* 
sudo rm /etc/apt/sources.list.d/*java* 
 sudo apt-get update 
sudo add-apt-repository ppa:webupd8team/java 
 sudo apt-get update 
sudo apt-get install oracle-java7-installer

, , ,

1 Comment

RVM vs RBENV……

Just installed a new precise pangolin and thought of giving rbenv a try….

So collected this with a bit of googling….

rbenv is a new lightweight Ruby version management tool built by Sam Stephenson(of 37signals and Prototype.js fame).

The established leader in the Ruby version management scene is RVM but rbenv is an interesting alternative if you want or need something significantly lighter with fewer features. Think of it as a bit like Sinatra and Rails. It’s not about which is the best, it’s about which is better for you and your current requirements.

What’s  rbenv?

Compared to RVM, rbenv is light. For example, it doesn’t include any mechanism to install Ruby implementations like RVM does. Its sole job is to manage multiple Ruby “environments” and it allows you to quickly switch between Ruby implementations either on a local directory or default ‘system-wide’ basis.

With rbenv, you install Ruby implementations manually or, if you prefer a little help, you can try ruby-build, another project of Sam’s that provides RVM esque recipes for installing seven popular Ruby implementation and version combos.

rbenv primarily works by creating ‘shim’ files in ~/.rbenv/shims which call up the correct version of files for each Ruby implementation behind the scenes. This means ~/.rbenv/shims will be in your path and there’s no threat of incompatibilities between libraries or systems like Bundler and rbenv.

The key thing to be aware of, however, is that if you install a gem that includes ‘binaries’ (or any generally available command line scripts), you need to run rbenv rehash so that rbenv can create the necessary shim files.

INSTALL

Firstly, it’s worth noting that by default rbenv is incompatible with RVM because RVM overrides the gem command with a function. This means to get the full rbenv experience you’ll need to do a rvm implode to wipe away your RVM installation or, at the least, remove/comment out the RVM loader line in your .bash_profile and/or .bashrc.

The installation instructions for rbenv are likely to change fast due to its youth, so I suggest the README. However, rbenv has just been made into a homebrew package on OS X, so if you’re a homebrew user (and if you’re not, check out my screencast), try:

brew update brew install rbenv rbenv rehash

And then add this line to your ~/.bash_profile or equivalent:

eval "$(rbenv init -)"

When you open a new shell now, you can run commands like rbenv and rbenv version to see what’s going on. rbenv versions should return nothing since you won’t have any rbenv-enabled Ruby installations yet, so move on to the next step..

Installing Implementations for rbenv

If you have ruby-build installed, getting, say, Ruby 1.9.2-p290 installed is easy:

ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290

If you prefer to download tarballs and do your own Ruby installs, however, you just need to set the directory prefix at the ./configure stage in most cases. For example:

./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290

Once you’ve installed a new Ruby in this way, you need to run rbenv rehash in order for rbenv to create the ‘shim’ binaries necessary to make the correction version of Ruby available on the path at all times.

The RVM Splashback

In the interests of completeness, it’d be amiss to not mention the minor drama that kicked off on Twitter and Hacker News about rbenv’s release.

rbenv made its way on to Hacker News where, surprisingly, many people railed against RVM. This, coupled with a slightly antagonistic tone taken by rbenv’s README (which has now been taken away), led RVM’s maintainer Wayne E Seguin to vent some pressure on Twitter:

Sam quickly clarified his position:

Nonetheless, Wayne took a little time off, and a campaign to encourage donations to Wayne for his work on RVM was kicked off on Twitter (by Ryan Bates, I believe). The campaign went well, taking RVM’s donations from $7468 to $11370 (at time of writing), a jump of almost $4000 in a few days.

Part of the complaint made in rbenv’s README was about RVM’s “obnoxious” redefinition of the “cd” shell builtin. Essentially, RVM would create a new function which called “cd” but also took into account any .rvmrc files present in each directory so that it could change Ruby version automatically. While there was some validity to this concern, Ben Atkin took some time to write a blog post correcting some of the misinformation on this point.

In the end, however, all seems to be well, and Wayne is already making regular commits to the RVM project again just days later. Hopefully the outpouring of support from the Ruby community for RVM over the past couple of days has shown Wayne that RVM still has a significant user base, most of who aren’t going anywhere new anytime soon. If you want to help out, of course, you can still donate to the RVM Pledgie.

Conclusion

If you’re happy with RVM, there’s not much in rbenv to really leap to. It’s just a lighter and more modular way to achieve the basic functionality that RVM provides while missing out on a lot more (although you can use rbenv-gemset to get some basic gemset-like features).

If, however, you want something “lighter” than RVM, rbenv is certainly worth a look. Its approach feels cleaner and more transparent at a certain level, and if this is of utmost importance to you, you may prefer it.

I personally switched back to rvm coz I am getting openssl error which is tricky(ofcourse mybad!) and not able to get over it…

, , , ,

1 Comment

New In Precise Pangolin….

 


New in Ubuntu 12.04 LTS Precise Pangolin beta 2

Ubuntu 12.04 LTS beta 2 is released with major Unity changes. After this release final Ubuntu 12.04 LTS Precise Pangolin will be released, so this is the last testing version of Ubuntu 12.04 before final release. Also, now Gnome 3.4 is present in official repositories, so if you want to use cutting edge Gnome-Shell release than you can easily install that.

For more detailed look into Ubuntu 12.04 Precise Pangolin you can see Ubuntu 12.04 Precise Pangolin LTS beta 1 New Features

Major Changes in Ubuntu 12.04 Beta 2

Major changes are as following:

  • Unity files lens no longer relies on Zeitgeist, now it can show files that you never accessed.
  • Both 2D & 3D Unity launchers can now be configured for multi-monitor setup. You can display launcher on primary or multiple monitors.
  • HUD (searchable menu: can be accessed by tapping ALT key)  got new animation and now respects launcher behavior.
  • Now more default applications have quicklists.
  • Introduction of now system management application Landscape (helps you monitor, manage and update your entire Ubuntu infrastructure from a single interface)
  • Unity launcher progress bar support for Ubuntu Software Center.
  • Various improvements for Ambiance and Radiance themes.
  • Unity 2D is improved, it now looks almost same as Unity 3D. Also, HUD is now supported on Unity 2D.

Default Applications

Default Application that come pre-installed with Ubuntu 12.04 are all on top of GTK 3.3.20 with 3.2.0-20.33 Linux kernel based on the v3.2.12 upstream stable Linux kernel. Applications are following

  • Firefox 11
  • Nautilus 3.3.92
  • Thunderbird 11
  • Gedit 3.3.8
  • Rhythmbox 2.96
  • LibreOffice 3.5.1
  • Totem 3.0.1
  • Transmission 2.50
  • Empathy 3.3.92
  • Deja Dup Backup Tool 22.0
  • Shotwell 0.11.93
  • Gwibber 3.3.93
  • Ubuntu Software Center 5.1.13.2
  • System Settings (GNOME Control Center) 3.3.92

 

For more detailed look into Ubuntu 12.04 Precise Pangolin you can see Ubuntu 12.04 Precise Pangolin LTS beta 1 New Features

, , ,

8 Comments

Remove apache2 completely from your system

Recently, while playing around, I deleted my apache2 directory.

The only option to get things working back was to reinstall apache.

But it was not getting completely removed.

Thus, after trying many things I came across the following which did the trick !!

 

sudo apt-get remove –purge $(dpkg -l apache* | grep ii | awk ‘{print $2}’)

1 Comment

My visit to RED FORT

 

The Red Fort (Hindi: लाल क़िला, Urdu: لال قلعہ, usually transcribed into English as Lal Qil’ah or Lal Qila) is a 17th century fort complex constructed by the Mughal emperor Shah Jahan in the walled city of Old Delhi (in present day Delhi, India) that served as the residence of the Mughal Emperors. It also served as the capital of the Mughals until 1857, when Mughal emperor Bahadur Shah Zafar was exiled by the British Indian government. It was designated a UNESCO World Heritage Site in 2007.[1]

 

The above is an extract from Wikipedia page of Red fort. The last line is pretty important . After reading that , today I went to the great fort. I was excited and expected to be face to face with history. But to say the truth I was disappointed with what I saw. Let me share my experience with you. I have also clicked some pictures to support my argument.

First, when I reached the entrance, it was full of commotion. There were vendors selling butter milk and fresh vegetables right outside the world heritage site ! When you enter you the massive facade of the RED FORT. Then when you walk a bit, you see a board with words “TICKET COUNTER”. Now you wonder where the window is and finally you figure out that its in the basement but the board never points there !!

The ticket costs Rs.15/-. When you go inside, there is checking done for namesake!

Still, when I finally got in , I was feeling that I will see a great historical monument standing in front of me. Did I see that ? No…I saw a MARKET ! . I saw a market with lot of shops in what was called the “drum building” of red fort. They were selling all kinds of small replicas and effigies of gods and monuments. I felt terrible. How can there be a market inside a world heritage building. But, it was true.

After that I went to the famous “Di wan-e-aam”. I saw people clicking photographs there. Not a bad thing but nobody cared about where they were. And why would they? We did not knew. There was not much information about the place written any where. There were no information board and no literature was given to the tourists as they came.

We moved forward and there was “diwan-e-khas” and then mumtaz mahal and ofcourse the  ” nahr-i-bihist”. Then finally I saw an information board on “nahr-i-bihist” and it said that it provided air conditioning type effect to the whole fort. But no where could I find out how ? No information on the architecture !!

Then we went to the museum  made in Mumtaz mahal. It has some very old scriptures and paintings. It has scriptures of old holy quran and different farmans of Babar,Humayun ,Akbar and Shahjahan. It has objects and artifacts of Mughals and their weapons and dresses wore by them.These objects are 400-500years old and can fascinate you. But alas ! I did not understand anything because these objects only had captions. One needs to know urdu to read the farmans and be an expert hopologist to understand how those weapons work.

When I was coming back I saw dogs and rats in the main arena ! How can stray animals come in the area of a word heritage building? I was stunned as well as disappointed. Even the cleanliness was not as good as it should have been .

Overall for me it was a disappointing experience. I quietly went out and has a brilliant “RABDI FALUDA”. Much better than RED FORT !!!

Please note I would still prefer if you get a chance please visit the site as despite all these things which I personally felt terrible the grand ancient fort stands tall with a flag furling with the wind.

Here are some pictures:

 

, ,

Leave a Comment

Rails and attr_*

There is a small gotcha in rails attr_accessible method in ruby.

  • If there are no attr_accessible attributes on a model it’s open, any attribute can be written with .update_attributes() or a similar mass-assignment function.
  • If there is even one attr_accessible the model is closed except for those attributes defined to be attr_accessible.

So there is an implicit toggle involved in attr_accessible as well as the actual desired functionality of allowing an attribute to be mass-assigned

, , ,

Leave a Comment

Follow

Get every new post delivered to your Inbox.

Join 510 other followers