Mostrando postagens com marcador en-US. Mostrar todas as postagens
Mostrando postagens com marcador en-US. Mostrar todas as postagens

quarta-feira, 31 de agosto de 2011

Foreman

0



I've watched the RailsCasts #281, and Ryan Bates is talking about the Foreman gem. At the first time I did not mind for the project, this is interesting, but I don't see how it's can be useful for me. Then I go back to the project when I'm working. I open my iTerm, an tab for mongod, and tab for spork, and a tab for  guard, and another to run the generators.
After I open all this tabs, Foreman gem cames to my mind. Well, I gave to Foreman a opportunity, and I loved it.

If you think this scenario is the same of you, take a look at Foreman, and give to it a chance.
You can add the gem to your Gemfile or install it by your own hand. To work foreman only needs a file called Procfile. in this manifest file, you name your process and tell to foreman what command they should use, and above a simple Procfile for the scenario:



Very simple file, I've a process called mond, wich executes "sudo mongod" and starts the mongodb database, You'll see in the console, something like that "mongod.1 | started with pid XXX", every log from mongod will appear in the console.

To start all this process type "foreman start", Now I've only one tab running all my development processes.

Read more

segunda-feira, 10 de janeiro de 2011

JPA 2.0 Criteria Sucks

2

I sometimes need to use the Criteria in JPA, I don't know why, but the create query method not accept order with asc and desc in the same query, the Criteria support it, but damn, it's very hard, I don't know who think this code

ParameterExpression age = qb.parameter(Integer.class);
Predicate condition = qb.gt(p.get(Person_.age), age);
c.where(condition);
TypedQuery q = em.createQuery(c); 
List result = q.setParameter(age, 20).getResultList();

is better than this one

String jpql = "select p from Person p where p.age > :age";
Query query = em.createQuery(jpql).setParameter("age", 20);
List result = query.getResultList();

I don't need to map my class into another object called metamodel, one change in a model results into two changes, the model and the metamodel. Go to hell with de metamodel, we don't want, and don't need it, I write my queries using JPQL and don't want to use the Criteria API. Why they don't use the hibernate style? The code below isn't better?

List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.like("name", "Fritz%") )
    .add( Restrictions.between("weight", minWeight, maxWeight) )
    .list();

Yes, I copy this codes from IBM and Hibernate:).

Read more

domingo, 9 de janeiro de 2011

RSpec+Mongo+DatabaseCleaner

0

Em portugues

Some times ago, I wrote about RSpec and MongoDB I was used the DatabaseCleaner 0.5.2, the version 0.6.0 was released some times ago, and I not tested it before, the changes are simple, the main change is the orm options need to be before the stategy option, see below the spec_helper.rb:


RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.orm = :mongoid
    DatabaseCleaner.strategy = :truncation    
    DatabaseCleaner.clean_with(:truncation)
  end  
  config.before(:each) do  
    DatabaseCleaner.start
  end
  config.after(:each) do  
    DatabaseCleaner.clean
  end
end

Also changed the before option, now it's initialize the Cleaner, and the after option, clean the database

Read more

quarta-feira, 15 de dezembro de 2010

Days of week in ruby

0

Em português

I don't know why, nobody need it, I searched at the web, and I'm not found a solution for this, by the way, I implement my own solution.

You can see some explain about the method here (in Pt-Br): http://www.arlindo-correia.com/140101.html
But, I converted the javascript code at http://www.profcardy.com/calculadoras/aplicativos.php?calc=4 to ruby

the result is this monkey patch

class Time
  DAYS_OF_WEEK = [
    :saturday, :sunday, :monday, :tuesday, :wednesday, :thursday, :friday
  ]
  def day_of_week
    day = self.day
    month = self.month
    year = self.year
    if month == 1
      month = 13
      year -= 1
    end
    if month == 2
      month = 14
      year -= 1
    end
    phase1 = ((month + 1)*3)/5
    phase2 = (year/4)
    phase3 = (year/100)
    phase4 = (year/400)
    phase5 = day + (month*2)+phase1+year+phase2-phase3+phase4+2
    phase6 = phase5/7
    result = phase5-(phase6*7)
    DAYS_OF_WEEK[result]
  end
end

and some result by irb (I've used the rails console)
irb(main):001:0> t = Time.now
=> Wed Dec 15 22:05:00 -0200 2010
irb(main):002:0> t.day_of_week
=> :wednesday
irb(main):003:0> t.prev_month.day_of_week
=> :monday

If somebody know another way to do it, I'm listening

Read more

 
Design by ThemeShift | Bloggerized by Lasantha - Free Blogger Templates | Best Web Hosting