petak, 19. kolovoza 2011.

Ruby on Rails 3, scaffold_controller not works, solution with Niftygenerators

As I tried to use scaffold_controller on Ruby On Rails 3, to create controller and view, and generated code was not working, I tried niftygenerators and they work.
This is how you can use them:
Edit you Gemfile (in root of your project) and add

gem "nifty-generators", :group => :development

after that, you can run
bundle install
to install gem

After that, you can do
rails g nifty:scaffold ModelName
and after that we must create layout:
rails g nifty:layout
That will successfully create controller and view from your ActiveRecord.

srijeda, 17. kolovoza 2011.

Ruby on Rails: stack level too deep

If you install your Ruby on Rails on Debian or Ubuntu, and dont use apt-get to install it, you may stumble upon a problem with stack level too deep


rake
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:28: warning: already initialized constant DEFAULT_RAKEFILES
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils
rake aborted!
stack level too deep


You can resolve this by typing bundle exec in front of rake like this:


bundle exec rake db:migrate



utorak, 16. kolovoza 2011.

Linux: size of directory

If you need to see what is the size of every sub directory you can use this:

du -m --max-depth=1 |sort -n -k1

nedjelja, 31. srpnja 2011.

Best internet prepaid data plan if you go to Croatia (2011)

If you are planning vacation in Croatia, you will probably need some internet access. Maybe city where you are going have some free internet hotspots, but you never know, until you get there. So other solution is prepaid internet stick with some data plan. Best data plan is Bonbon internet data SIM (you can use daily package) where you can get 300 mb for 3 kn (about 0.45 Euro). Problem with this package is that you still cannot buy it in store, and you can only buy it if you order it by mail ( https://www.bonbon.com.hr/ponuda/internet_sim ). Second best solution is from T-mobile and Simpa internet. You can buy Simpa internet start paket (SIM only) for 20 kn (about 3 Euros). If you register you will get 500 mb of data. If you also need USB modem, you can buy bundle for 198 kn ( 30 Euros). When you spend first 500 mb, you can buy extra packages, depending what you need.http://www.visitingcroatia.info/internet_tarrifs.asp

petak, 15. srpnja 2011.

Wordpress jQuery hell

If you were caught in javascript hell, here is a quick fix for you(found here):

you need to add <?php wp_enqueue_script("jquery"); ?> before <?php wp_head(); ?> so it would look like this:



<?php wp_enqueue_script("jquery"); ?>

<?php wp_head(); ?>


also, you may need to rewrite some javascript functions, just like this:


var $j = jQuery.noConflict();

$j(function(){

    $j("#sidebar li a").hover(function(){
     $j(this).stop().animate({
      paddingLeft: "20px&"
     }, 400);
    }, function() {
     $j(this).stop().animate({
      paddingLeft: 0
     }, 400);
    });

});

nedjelja, 10. srpnja 2011.

Intuitive way to insert data into mysql

So instead of standard:

INSERT INTO sometable
     ( field1, field2, field3 )
VALUES
     ( 'value1', 'value2', 'value3' )

you can do this:

INSERT INTO sometable
   SET field1 = 'value1',
       field2 = 'value2',
       field3 = 'value3'

Securing your mysql queries from $_POST or $_GET injections

Easiest way is to do this:


foreach ($_POST as $k=>$v) {
    $_POST[$k] = mysql_real_escape_string($v);
}