digitaldisorder

  • Home
  • About
    • 0
      2 Nov 2011

      RVM on Debian/Ubuntu revised

      • Edit
      • Delete
      • Tags
      • Autopost

      Just a quick review of my old post.

      As some of my commenters pointed out it's now possible to manage OpenSSL and Readline libraries from inside RVM. This will solve some of the problems when Ruby and operating system need different versions of the libraries.

      The fast way to get everything going is just use:

      bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
      
      echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
      
      rvm pkg install readline
      rvm pkg install iconv
      rvm pkg install zlib
      rvm pkg install openssl
      
      rvm install 1.9.2 --with-readline-dir=$rvm_path/usr,--with-iconv-dir=$rvm_path/usr,--with-zlib-dir=$rvm_path/usr,--with-openssl-dir=$rvm_path/usr

      Et voila! You've got everything installed, without jumping between RVM documentation pages.

      • views
      • Tweet
      • Tweet
    • 0
      26 Oct 2011

      rspec + guard + spork

      • Edit
      • Delete
      • Tags
      • Autopost

      Every time i start a new project I'm searching for a good guide on how to setup rspec, guard and spork to play nice together.

      Setup gemfile by adding:

       

      gem "spork"
        gem "guard"
        gem "guard-rspec"
        gem "guard-spork"
        gem "rb-inotify" if linux?
        gem "libnotify" if linux?

       

      Method linux? is a little helper that i created so I don't annoy my mac loving friends it's just:

      def linux?
        RUBY_PLATFORM.downcase.include?("linux")
      end

      that I use everytime I'm including gem that was made specificaly for Linux. At the end we have to run:

      bundle install

       

      Setup sport

      spork --bootstrap

      Setup guard

      guard init spork
      guard init rspec

      Customize spec_helper.rb

      Last thing is to customize spec_helper for spork:

      require 'rubygems'
      require 'spork'
      
      Spork.prefork do
        ENV["RAILS_ENV"] ||= 'test'
        require File.expand_path("../../config/environment", __FILE__)
        require 'rspec/rails'
        require 'rspec/autorun'
      
        require 'factories'
      
        if RUBY_PLATFORM !~ /java/
          require 'simplecov'
          require 'simplecov-rcov'
          SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
          SimpleCov.start 'rails'
        end
      
        Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
      
        RSpec.configure do |config|
          config.mock_with :rspec
          config.infer_base_class_for_anonymous_controllers = false
        end
      end
      
      Spork.each_run do
        # This code will be run each time you run your specs.
      end
      • views
      • Tweet
      • Tweet
    • 0
      13 Oct 2011

      Extjs 4 and handler scope

      • Edit
      • Delete
      • Tags
      • Autopost

      One of those aaaaaaahhhhhh moments

      Extjs has a wonderful scope parameter that will let you specify the scope in which the function must be executed.

      I just stumbled at the following piece of code, in my news showing component that is supposed to open in new window a link to PDF file.

      {xtype: 'button', text: 'PDF', icon: '/images/pdf.png',
            handler: function() {
              var cmp = Ext.getCmp('newslist');
              var selModel = cmp.getSelectionModel();
              var record = selModel.getLastSelected();
              if (record) {
                open_new_window(record.getPDFUrl());
              }
            }
          }

      As you can see, to get the selected item I have to find the grid component, selection model and retrieve the record. In my component I'm already storing the record in the 'record' attribute. Using scopes I can easily retrieve it. Which can be refactored to simple:

      {xtype: 'button', text: 'PDF', icon: '/images/pdf.png', scope: this,
            handler: function() { 
              open_new_window(this.record.getPDFUrl()); 
            }
          },

      When scope is not defined this is referring to the handler function object.

      • views
      • Tweet
      • Tweet
    • 0
      28 Apr 2011

      Aaaaaargh and Posterous logout placement

      • Edit
      • Delete
      • Tags
      • Autopost

      Posterous UI is great. I like the themes. I like the UI for writing new posts. The only thing I don't like is the little widget that is appearing in the top right corner of the screen. The idea is great - to let you access basic administration functionalities but there is one little thing that is really annoying: 

      Posterous_ux_bug
      Whenever I move my mouse over the widget, over the little arrow I feel like I have to click on it and just 1jiffy before I click a menu appears. Probably the little delay is intentional or maybe it's because of my webbrowser still downloading the javascripts, I don't know. Of course my brain already sent the message to my hand to click on the little triangle, but triangle bacame already... Logout link. It's too late to stop my finger and 50% of the times I'm getting logout. I think this is the worst placement for logout button. Is it possible that you move it somewhere like under the new post button? Or on the right side of New Post button or somewhere else but please please please don't leave it there. 

      • views
      • Tweet
      • Tweet
    • 14
      28 Apr 2011

      Ruby and RVM problems on Debian Unstable/Sid

      • Edit
      • Delete
      • Tags
      • Autopost

      I decided to port all my Rails projects to use the rvm and rvmrc to have separate environment and avoid conflicts between gems. 

      My frustration only grew when I was trying to update Ruby on my debian squeeze.

      First shot:

      rvm install ruby-head

      Failed!

      
      
      compiling ossl_ssl.c
      ossl_ssl.c:110:1: error: ‘SSLv2_method’ undeclared here (not in a function)
      ossl_ssl.c:111:1: error: ‘SSLv2_server_method’ undeclared here (not in a function)
      ossl_ssl.c:112:1: error: ‘SSLv2_client_method’ undeclared here (not in a function)
      make[2]: *** [ossl_ssl.o] Error 1
      
      
      

      It's because debian removed support for SSLv2 which is deprecated because of security problems

      rvm install ruby-1.9.2

      Failed!

      
      
      PIC -I. -I.ext/include/i686-linux -I./include -I. -DRUBY_EXPORT   -o dmyversion.o -c dmyversion.c
      In file included from vm.c:26:0:
      vm_eval.c: In function ‘loop_i’:
      vm_eval.c:801:1: internal compiler error: in dfs_enumerate_from, at cfganal.c:1207
      Please submit a full bug report,
      with preprocessed source if appropriate.
      See <file:///usr/share/doc/gcc-4.5/README.Bugs> for instructions.
      make: *** [vm.o] Error 1
      
      
      

      Which means it's a bug in compiler itself! There is regression bug in gcc 4.5, there are some patches backported from 4.6 but I would have to patch gcc by hand.

      rvm install ruby-1.9.1

      
      
      ossl_ssl.c:1201:2: warning: passing argument 1 of ‘sk_value’ from incompatible pointer type
      /usr/include/openssl/stack.h:80:7: note: expected ‘const struct _STACK *’ but argument is of type ‘struct stack_st_X509 *’
      ossl_ssl.c: In function ‘ossl_ssl_get_cipher’:
      ossl_ssl.c:1223:12: warning: assignment discards qualifiers from pointer target type
      ossl_pkcs7.c:575:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
      ossl_pkcs7.c: In function ‘ossl_pkcs7_set_certificates’:
      ossl_pkcs7.c:613:5: warning: implicit declaration of function ‘pkcs7_get_certs_or_crls’
      ossl_pkcs7.c:613:11: warning: assignment makes pointer from integer without a cast
      ossl_pkcs7.c: In function ‘ossl_pkcs7_get_certificates’:
      ossl_pkcs7.c:623:5: warning: passing argument 1 of ‘ossl_x509_sk2ary’ makes pointer from integer without a cast
      ossl.h:117:7: note: expected ‘struct stack_st_X509 *’ but argument is of type ‘int’
      ossl_pkcs7.c: In function ‘ossl_pkcs7_set_crls’:
      ossl_pkcs7.c:653:10: warning: assignment makes pointer from integer without a cast
      ossl_pkcs7.c: In function ‘ossl_pkcs7_get_crls’:
      ossl_pkcs7.c:663:5: warning: passing argument 1 of ‘ossl_x509crl_sk2ary’ makes pointer from integer without a cast
      ossl.h:118:7: note: expected ‘struct stack_st_X509_CRL *’ but argument is of type ‘int’
      make[1]: *** [ossl_pkcs7.o] Error 1
      
      
      

      So finally I decided that the easiest way will be to remove the checks for SSLv2 in Ruby and created this patch:

      
      
      cat  /tmp/disable_ssl2.patch 
      diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
      index d8951fb..4254b76 100644
      --- a/ext/openssl/ossl_ssl.c
      +++ b/ext/openssl/ossl_ssl.c
      @@ -107,9 +107,11 @@ struct {
           OSSL_SSL_METHOD_ENTRY(TLSv1),
           OSSL_SSL_METHOD_ENTRY(TLSv1_server),
           OSSL_SSL_METHOD_ENTRY(TLSv1_client),
      -    OSSL_SSL_METHOD_ENTRY(SSLv2),
      +/*
      +OSSL_SSL_METHOD_ENTRY(SSLv2),
           OSSL_SSL_METHOD_ENTRY(SSLv2_server),
           OSSL_SSL_METHOD_ENTRY(SSLv2_client),
      +*/
           OSSL_SSL_METHOD_ENTRY(SSLv3),
           OSSL_SSL_METHOD_ENTRY(SSLv3_server),
           OSSL_SSL_METHOD_ENTRY(SSLv3_client),
      
      
      

      So now you can successfully compile ruby using:

         rvm install ruby-head --patch /tmp/disable_ssl2.patch   

      And finally success!!!!

      
      
      ruby --version
      ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-linux]
      
      
      

      It works also for ruby 1.9.2

      
      
      rvm install ruby-1.9.2 --patch /tmp/disable_ssl2.patch
      
      
      

       

      
      
      ruby --version 
      ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
      
      
      

      • views
      • Tweet
      • Tweet
    • 0
      17 Mar 2011

      Hard disk encryption on Linux and performance penalty

      • Edit
      • Delete
      • Tags
      • Autopost

      For a long time I was planning to encrypt my hard disk on my laptop (I'm running Linux Debian unstable). I was afraid of complicated bootup process, risk of loosing my data and of course performance penalty related to encryption of all IO operations. Finally when I lost my phone (it was later returned by some good Samaritan) I said to myself that I don't want anyone looking trough my files when something similar happens to my laptop.

      While I found some good step by step guides and performance tests of different encryption algorithms I didn't know what to expect from normal user point of view. I didn't like the idea of encrypting only one directory or maybe just my home directory so I went with full hdd encryption offered by dm-crypt (default options for algorithm). It could be also important to tell that my hard disk is Western Digital - WD5000BEKT - 500GB 7200RPM 2.5" with 16MB of cache, if you are using SSD your results can be different.

      Below you can find the CPU load of krcyptd (which is responsible for fs encryption) - it's no scientific study it's just my observation:

      • find -name *.jpg - cpu load: 4%
      • copy of 1GB file - cpu load: 17%
      • digikam scanning all my 70GB of photos - cpu load: 10-14% (digikam doing all the work takes 50-70%)
      • apt-get dist-upgrade - cpu load: 8-13% (dpkg uncompressing and running installation scripts 11%)
      • tar zxvf linux-2.6.38.tar.gz - 50-60% 
      • compiling linux kernel - 5% (and the rest is taken by cc) (*)

      What does it mean? It means that on not-so-modern system like mine (dual core T8300 @ 2.40Ghz) it takes virtually no processing power to secure your data, even for IO intensive tasks like copying files CPU will not be a problem. 

      * in some guides you can read that performance is acceptable if you are not compiling code. I think it's acceptable in every case and as you can see even when you are compiling big source trees. 

       

       

       

      • views
      • Tweet
      • Tweet
    • 0
      2 Feb 2011

      Simple debugging for android applications

      • Edit
      • Delete
      • Tags
      • Autopost

      If you are tired of switching perspectives from Java to Debug in Eclipse everytime you want to see the output from your emulator or real divce just use the old good.

       

      
      
      adb logcat
      
      
      

      you can chain it with grep and other commands to facilitate debugging of just one class...

      Probably obvious but it took me some time and frustration to discover, even if I was using it when installing Cyanogen.

      • views
      • Tweet
      • Tweet
    • 1
      16 Nov 2010

      Autotest infinite loop with Rails 3 and Cucumber.

      • Edit
      • Delete
      • Tags
      • Autopost

      Using Rails 3 I couldn't figure out how stop autotest to run in infinite loop making my laptop fans turn constantly.

      I found several posts on the web telling to add hooks to .autotest but all were missing some files or directories, finally I arrived to the magical combination that solved the problem:

      
      
      Autotest.add_hook :initialize do |at|
          %w{.svn .hg .git vendor rerun.txt tmp log}.each {|exception| at.add_exception(exception)}
      end
      
      
      

      No monitoring of tmp/log/vendor and source control directories.

      • views
      • Tweet
      • Tweet
    • 0
      3 Oct 2010

      No more --no-ri and --no-rdoc ...

      • Edit
      • Delete
      • Tags
      • Autopost

      Are you tired of adding --no-ri and --no-rdoc everytime you install a new gem?

      You can configure the default options used by gem in your .gemrc, just add those two lines:

      
      
      install: --no-rdoc --no-ri
      update: --no-rdoc --no-ri
      
      
      

      and don't worry anymore...

      • views
      • Tweet
      • Tweet
    • 1
      16 Sep 2010

      Problem with Cucumber and paperclip - '* file name must be set.'

      • Edit
      • Delete
      • Tags
      • Autopost

      If you have seen the error 'file name must be set' when running the standard Cucumber tests of models extended with Paperclip, it means that probably you have (as it happened in my case) similar class structure:

      
      
      class Document < ActiveRecord::Base
        has_many :attachments, :dependent => :destroy, :class_name => '::Attachment'
        accepts_nested_attributes_for :attachments, :allow_destroy => true
      end
      
      
      

      In my case Document has_many attachments and it's attachment that has paperclip file.

      It means also that we can but not have to embed file uploads in the Document form. In my case I could submit the document from web browser without any troubles but Cucumber tests were failing.

      It's because in the post request we had this parameters:

      
      
      "attachments_attributes"=>{"0"=>{"file"=>""}}}
      
      
      

      Which makes our webserver think that we are sending a file attachment, but because the value of 'file' is empty the validation fails.

      The solution is easy: we have to reject the nested attributes when the file is empty. This can be done by modifying our class in the following way:

      
      
      accepts_nested_attributes_for :attachments, :allow_destroy => true, :reject_if => lambda { |t| t['attachment_file'].nil?
      
      
      

      In this case we just create the document object without trying to create the attachment.

      • views
      • Tweet
      • Tweet
    « Previous 1 2 Next »
    • Search

    • Tags

      • rails
      • ruby
      • tdd
      • android
      • autotest
      • cucumber
      • debian
      • debug
      • encryption
      • facebook
      • gem
      • guard
      • linux
      • posterous
      • rspec
      • rvm
      • spork
      • testing
      • ubuntu
      • usability
      • ux
    • Archive

      • 2011 (7)
        • November (1)
        • October (2)
        • April (2)
        • March (1)
        • February (1)
      • 2010 (5)
        • November (1)
        • October (1)
        • September (2)
        • August (1)
    • Obox Design
  • digitaldisorder

    Nothing to see here, please move along...

    6914 Views
  • Get Updates

    Follow this Space »
    You're following this Space (Edit)
    You're a contributor here (Edit)
    This is your Space (Edit)
    Follow by email »
    Get the latest updates in your email box automatically.
    Loading...
    Subscribe via RSS