Posts

Update #2: Ostern, *Feier*-Tage und das Frankfurter Ordnungsamt

Donnerstag, 14. April 2011, 08:58 Uhr | roberto@vasquez-angel.de |

Es gibt eine Petition an den hessischen Landtag, das Tanzverbot (ich berichtete hier) aufzuheben und die entpsrechenden Paragraphen aus dem Gesetz zu streichen:

Open Petition: Aufhebung des Tanzverbots an Feiertagen in Hessen

Update: Ostern, *Feier*-Tage und das Frankfurter Ordnungsamt

Donnerstag, 14. April 2011, 08:30 Uhr | roberto@vasquez-angel.de |

Die Frankfurter Rundschau hat einen weitern Bericht zum Thema gebracht.

Besonders brisant finde ich die Tatsache, dass diese Aktion mit der christlichen Kirche abgesprochen ist. Zitat aus der FR:

Stein, einstmals Vize des Evangelischen Regionalverbandes, hat sein Eingreifen nach eigenen Worten “mit den beiden großen christlichen Kirchen abgesprochen”. Tatsächlich begrüßen die evangelische Pröpstin Gabriele Scherle und der katholische Stadtdekan Stefan Scholz in einer gemeinsamen Erklärung „die entschiedene Haltung“ Steins.

Das muss man sich mal auf der Zunge zergehen lassen! Ich finde das verhalten unseres Ordnungsdezernenten Volker Stein, vor dem Anspruch Frankfurts eine internationale, kultur-offene Großstadt zu sein, völlig inakzeptabel!

Exclude a page from all search robots

Mittwoch, 13. April 2011, 21:57 Uhr | roberto@vasquez-angel.de |

To exclude a website from all search robots (google, etc.), you have to create a robots.txt file at its root:

User-agent: *
Disallow: /

Facebook: How to auto-post from your blog

Mittwoch, 13. April 2011, 15:07 Uhr | roberto@vasquez-angel.de |

Interesting: ehow.com

Maquetta: HTML5 UI Framework

Mittwoch, 13. April 2011, 09:19 Uhr | roberto@vasquez-angel.de |

The Maquetta HTML5 Framework looks promising.

Remote Desktop: Using a custom resolution

Mittwoch, 13. April 2011, 08:31 Uhr | roberto@vasquez-angel.de |

When connecting to a remote machine via RDP you may specify a resolution on the command line like this:

$> mstsc.exe -v:<remote_host> /w:1280 /h:1024

Ostern, *Feier*-Tage und das Frankfurter Ordnungsamt

Mittwoch, 13. April 2011, 07:57 Uhr | roberto@vasquez-angel.de |

Das Frankfurter Orndnungsamt nimmt Ostern dieses Jahr wirklich ernst!

Nach einem Bericht der Frankfurter Rundschau FR Online: “Kein Spaß: Tanzverbot für Osterhasen” wurden einige frankfurter Clubbesitzer (u.a. Mattias Morgenstern, Besitzer des “Tanzhaus West” und Rudi Link, Geschäftsführer vom “Sinkkasten”) vom Ordnungsamt angeschrieben und auf ein hessisches Gesetz (von 1952) hingewiesen, dass Tanzveranstaltungen:

  • ab Gründonnerstag um 04:00, bis Samstagnacht um 24:00 Uhr, und
  • ab Ostersonntag um 04:00 Uhr bis Ostermontag um 12:00 Uhr

verbietet. Das Ordnungsamt hätte die Clubs angeschrieben, bei denen es bekannt wäre, dass sie Veranstaltungen Ostern angesagt hätten.

Den Clubbesitzern droht ein Bußgeld in nicht genannter Höhe, sollten sie kontrolliert werden und gegen das Gesetz verstoßen.

In diesen Sinne: Schöne Feier-Tage!

Forex Trading: Using trend indicators

Dienstag, 12. April 2011, 18:39 Uhr | roberto@vasquez-angel.de |

Here is a german youtube video, about the usage of trend lines.

Der Forex Millionaer - Die Technische Analyse

Rails3, Oracle and german umlauts

Dienstag, 12. April 2011, 14:24 Uhr | roberto@vasquez-angel.de |

I’m developing an oracle based rails application with an oracle db using:

  • rails (3.0.3)
  • ruby-oci8 (2.0.4)
  • activerecord-oracle_enhanced-adapter (1.3.2)

German umlauts don’t work out-of-the box (for me) and when I start the console, I get following warning:

$> rails c
Warning: NLS_LANG is not set. fallback to US-ASCII.
Loading development environment (Rails 3.0.3)
irb(main):001:0> exit

I suppose that these two things go together.

The official oracle NLS_LANG faq: oracle.com: NLS_LANG FAQ

Solution

Connect to oracle db with sqlplus and issue following command to get the needed NLS_LANG settings:

  SELECT USERENV('LANGUAGE') FROM DUAL; 
    => GERMAN_GERMANY.WE8ISO8859P1

The trick is to set the NLS_LANG environment variable before any gems are loaded. This would be in Rails.root/config/boot.rb:

# Set up oracle parameters
ENV['NLS_LANG'] = 'GERMAN_GERMANY.WE8ISO8859P1'

Voila!

API for Ruby, Ruby on Rails and Rspec

Dienstag, 12. April 2011, 13:44 Uhr | roberto@vasquez-angel.de |

API Dock is a commentable API reference documentation for:

  • Ruby
  • Ruby on Rails
  • Rspec

Learning MQL4

Dienstag, 12. April 2011, 12:53 Uhr | roberto@vasquez-angel.de |

I decided to learn MetaQuotes Language 4 so I can program the MetaTrader.

My understanding is, that you can use all trading operation from inside a script.

What I’m not sure about, is if…

  • you can load orders from a file?
  • you need to write an “Expert Advisor” to do that

First international "Hello World" day

Dienstag, 12. April 2011, 12:05 Uhr | roberto@vasquez-angel.de |

Yesterday, we celebrated the first international “Hello World” day ever!

This day is dedicated to all people, that have ever written or have shown a “Hello World” to others

What is “Hello World”?

Wikipedia says: >A “Hello world” program is a computer program that prints out “Hello world” on a display device. It is typically one of the simplest programs possible in most programming languages. Therefore, by tradition, it is often the first program taught in a beginning class on a particular language. It is also used to illustrate the most basic syntax of a programming language.

Most of these programs are very simple, especially those that rely on a command-line interpreter (shell) to perform the actual output. However, they can be surprisingly complex, especially when writing the program for graphical user interface.

When programming an embedded system, the text may be sent to a liquid crystal display. In a device that does not display text, a simple program to produce a signal, such as turning on an LED, may be substituted for “Hello world” as the introductory program.

My first week as a blogger

Montag, 11. April 2011, 22:31 Uhr | roberto@vasquez-angel.de |

I’d never thought it would be that much, but I’ve written over 20 posts in 7 days!

Git: How to set the commit editor

Montag, 11. April 2011, 22:22 Uhr | roberto@vasquez-angel.de |
$> git config --global core.editor "nano"

Using factory girl in your rails projects

Montag, 11. April 2011, 21:23 Uhr | roberto@vasquez-angel.de |

Install Factory Girl:

$> gem install factory_girl_rails

Add factory girl to your Rails.root/Gemfile:

group :test do
  gem "factory_girl_rails"
end

Install your bundle:

$> bundle install

If you use rspec2, put your factories in Rails.root/spec/factories.rb:

Factory.define :admin do |admin|
  admin.email    "admin@example.com"
  admin.password "foobar"
end

Rails3: Autoloading /lib with all subdirs

Montag, 11. April 2011, 20:59 Uhr | roberto@vasquez-angel.de |

Edit your Rails.root/config/application.rb:

module YourApplication
  class Application < Rails::Application
    .
    .
    .
    config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    .
    .
    .
  end
eend

rspec: using rspec in your rails projects

Montag, 11. April 2011, 20:47 Uhr | roberto@vasquez-angel.de |

Install the rspec gem:

$> gem install rspec-rails

Add rspec to your Rails.root/Gemfile:

group :test, :development do
  gem "rspec-rails"
end

Install your bundle:

$> bundle install

Generate the basic rspec files:

$> rails g rspec:install

Git: How to start a new rails project and put it on GitHub

Montag, 11. April 2011, 20:30 Uhr | roberto@vasquez-angel.de |

Create a new Rails project:

$> rails new <project_name>

Put your rails project under local version control:

$> cd 
$> git init .
</pre>

Edit the .gitignore file:
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
doc/api
doc/app
*.swp
*~
.project
webrat.log
Commit:
$> git add .
$> git commit -am "Initial commit"
Go to [GitHub](http://www.github.com) and create a new project Add your github master: $> git remote add origin git@github.com:/.git $> git push -u origin master That's it! After that, a regular commit looks like that:
$> git add .
$> git commit -am "Your commit message"
Pushing to GitHub:
$> git push

Rspec2: Testing the flash in your controller tests

Montag, 11. April 2011, 08:59 Uhr | roberto@vasquez-angel.de |
it "should set a flash error message" do
  get :read, :id => @unpublished_post.id
  flash[:notice].should == "This post is not yet published."
end

FactoryGirl: Getting the attributes from a factory

Montag, 11. April 2011, 08:42 Uhr | roberto@vasquez-angel.de |

I keep forgetting how to get the attributes of a factory.

From the official documentation:

# Returns a hash of attributes that can be used to build a User instance:
attrs = Factory.attributes_for(:user)

Devise: Testing a custom sessions controller

Sonntag, 10. April 2011, 13:17 Uhr | roberto@vasquez-angel.de |

Assume you have a custom devise sessions controller for your customer login at Rails.root/app/controllers/customers/sessions_controller.rb:

class Customers::SessionsController < Devise::SessionsController
end

To test it with rspec, you’ll have to add a before(:each) to the test:

before(:each) do
  setup_controller_for_warden
  request.env["devise.mapping"] = Devise.mappings[:customer]
end

You’re test should look like this:

require 'spec_helper'

describe Customers::SessionsController do
  render_views

  before(:each) do
    setup_controller_for_warden
    request.env["devise.mapping"] = Devise.mappings[:customer]
  end

  context "as a visitor" do
    describe "GET 'sign_in'" do
      it "should have an email field" do
        get :new
        response.should have_selector("input[name='customer[email]']")
      end
      
      it "should have a password field" do
        get :new
        response.should have_selector("input[name='customer[password]']")
      end
    end
  end
end

Devise: Customize controller and views

Sonntag, 10. April 2011, 12:38 Uhr | roberto@vasquez-angel.de |

Devise uses built-in controllers and views by default. If you want to customize them, you have to add them to your rails application.

Assume you have a customer login.

Customizing the controller

Create a new controller at Rails.root/app/controllers/customers/sessions_controller.rb:

class Customers::SessionsController < Devise::SessionsController
end

Customize your Rails.root/config.routes.rb to use the controller:

devise_for :customers, :controllers => { :sessions => "customers/sessions" }

Customizing the views

First you’ll have to add support for scoped views. Uncomment following lines in your Rails.root/config/initializers/devise.rb:

Devise.setup do |config|
  config.scoped_views = true
end

Then generate the views:

rails generate devise:views customers

Foosball: The snake shot

Sonntag, 10. April 2011, 11:21 Uhr | roberto@vasquez-angel.de |

A very good tutorial about the snake shot can be found at foosmanchu

Using special chars in rails files

Samstag, 09. April 2011, 16:12 Uhr | roberto@vasquez-angel.de |

Put

# encoding: utf-8

in the first line in files using special chars like german umlauts to avoid errors.

Using the pdf_toolkit gem on Windows

Donnerstag, 07. April 2011, 14:10 Uhr | roberto@vasquez-angel.de |

When trying to user the pdf_toolkit gem on windows, I got following error:

     Errno::ENOENT:
       No such file or directory - /dev/null

When you look at the gems source (lib/pdf/toolkit.rb) at line 175, you’ll see this:

STDERR.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')

This does not work on my machine. So I created my first monkey patch in new file at Rails.root/lib/pdf_toolkit_patch.rb:

module PDF
  class Toolkit
    class <<self
      private
        def call_program(*args,&block)

          old_stream = nil
          options = args.last.is_a?(Hash) ? args.pop : {}
          options[:mode] ||= 'r' if block_given?
          unless options[:silence_stderr] == false
            old_stream = STDERR.dup
            #STDERR.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
            STDERR.reopen(RUBY_PLATFORM =~ /i386-mingw32/ ? 'NUL:' : '/dev/null')
            STDERR.sync = true
          end
          if options[:mode]
            command = (args.map {|arg| %{"#{arg.gsub('"','\\"')}"}}).join(" ")
            retval = IO.popen(command,options[:mode],&block)
            retval
            # block_given? ? $?.success? : retval
          else
            system(*args)
          end
        ensure
          STDERR.reopen(old_stream) if old_stream
        end
    end
  end
end

Then I added following line to the file, where I use the pdf-toolkit:

require 'pdf_toolkit_patch'

That’s it! My first ruby monkeypatch!