Text

I found a cool way to access a module like an array:

    module Fruits
      @fruits = ["Banana", "Apple", "Melon"]

      def self::[](index)
        return @fruits[index]
      end

      def self.list_fruits
        @fruits.each { |name| print name; puts "\n" }
        puts "Those fruits are inside!"
      end
    end


self::[] enables you to treat the whole module like an array. You could then say Fruits[0] and it would show the element at the index 0, which is “Banana”. Very handy!

Hint: Instead of using self::[] you could also use self.[]. However the former is cleaner to read in my opinion.

Text

Nicely done!

thoughtbot:

I needed an open? method. First try:

def open? opens_at < Time.now < closes_at end 

However, Ruby doesn’t support that kind of expression. Second try:

def open? (opens_at < Time.now) && (Time.now < closes_at) end 

It’s noisy and lacks expression. Third time’s a charm:

def open? Time.now.between? opens_at, closes_at end 

Ship it.

(via michaelhenriksen)

Source: thoughtbot

"All authority of any kind, especially in the field of thought and understanding, is the most destructive, evil thing. Leaders destroy the followers and followers destroy the leaders. You have to be your own teacher and your own disciple. You have to question everything that man has accepted as valuable, as necessary."

- Jiddu Krishnamurti

Text

Today I wanted to simulate an external IP request with RSpec (2.8.0) and Rails (3.1). Unfortunately Google didn’t reveal much upon a search. So I came up with this solution:

ActionDispatch::Request.any_instance.stub(:remote_ip).and_return("192.168.0.1")


The ActionDispatch module holds the Request class which contains information about the HTTP request, like the request body, authorization etc. It also contains a method for obtaining the associated ip address obtained by the remote ip middleware.

As I haven’t had access to the request object, I used any_instance to tell RSpec that literally any derived instance from that class should get a stubbed version of the remote_ip-method and then return a predefined ip address when that method is called.

Update

I also figured out that you can achieve that behavior by simply specifying another parameter when making a request via RSpec:

xhr :post, PATH, DATA, "REMOTE_ADDR" => "192.168.0.1"

"However, it’s still a lot of work to convince people that writing tests that are often longer than their implementation code can actually lower the total time spent on a project and increase overall efficiency."

- From the book “Ruby Best Practices” by Gregory Brown

Text

I became very interested in fractals recently - you can find them everywhere (especially in nature). Here is a nice Python script I found, which generates a mandelbrot - don’t worry, it takes some time to generate the image. But it’s definitely worth waiting!

_                                      =   (
                                        255,
                                      lambda
                               V       ,B,c
                             :c   and Y(V*V+B,B,  c
                               -1)if(abs(V)<6)else
               (              2+c-4*abs(V)**-0.4)/i
                 )  ;v,      x=1500,1000;C=range(v*x
                  );import  struct;P=struct.pack;M,\
            j  ='<QIIHHHH',open('M.bmp','wb').write
for X in j('BM'+P(M,v*x*3+26,26,12,v,x,1,24))or C:
            i  ,Y=_;j(P('BBB',*(lambda T:(T*80+T**9
                  *i-950*T  **99,T*70-880*T**18+701*
                 T  **9     ,T*i**(1-T**45*2)))(sum(
               [              Y(0,(A%3/3.+X%v+(X/v+
                               A/3/3.-x/2)/1j)*2.5
                             /x   -2.7,i)**2 for  \
                               A       in C
                                      [:9]])
                                        /9)
                                       )   )
 

Wunderlist: Think you’re a power user? With Wunderlist, you are!

christianreber:

With Wunderlist for desktop 1.2.4, all of you are power users. We’re making your workflow even easier with today’s incredible update.

So, what’s new?

  • Feature: Smart date - Add dates to tasks using text, right from the input field
  • Feature: Add tasks to the top of a list by using ALT +…
Source: wunderlist

Text

wunderlist:

Wow. This is amazing. It’s only been a year since we founded 6Wunderkinder and guess what? We’ve hit our first one million users within 275 days. The icing on the cake? We’ve hit this number sooner than companies like Evernote, Twitter and Foursquare did. We couldn’t be happier. We knew at the very beginning that Wunderkit – a revolutionary, truly original take on productivity – would take at least a year of development, but we wanted to get something out right away.

(via mrvnyh)

Source: wunderlist

"The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt."

- Bertrand Russell

Text

lecloud:

During the last weeks, I have been interviewing possible engineer candidates. One of my questions is about the knowledge of readme driven development. Interestingly, not one candidate had ever heard anything about readme driven development, but nearly 90% could precisely explain what test-driven development means. 

This small statistic surprised me and opened my eyes to the fact that our implementation of readme driven development at 6Wunderkinder must be something new in the IT industry. So I dedicate this (longer) blog post for a further insight into how readme driven development may be done under real-life conditions.

Read More

Source: lecloud