Clicky

How to adjust widget’ size in Qt

Mar 24, 2015

Have you ever thought on how this:

could be turned to this:

without manually setting per-pixel sizes?

It’s simple as 1-2! Just take a look at the top of the UI editor and you’ll find a set of buttons, dedicated to do this adjustment for you:

Yet, there is just one small tip: first you should select a containing widget, whose children will be rearranged.

Like this:

Note the selected parent widget for vertical_layout.

how did i came over from that to this

Mar 12, 2015
How did I came over from that to this…

reworked materials for my rifle

Mar 4, 2015
Reworked materials for my rifle

creating some gun from a rough primitive model

Mar 4, 2015
Creating some gun from a rough primitive model with some texture and sculpting. Yet, trying to get some pretty materials on this…

Trying sculpting in blender

Mar 4, 2015
Have had some free time and tried sculpting in Blender =) With some other nice stuff =)

Having fun with blender

Feb 23, 2015
Just some WIP. Having fun with blender =)

Installing deb package with dependencies

Feb 19, 2015

Oftenly,

sudo dpkg -i package_file.deb

fails with messages like dependency not satisfied.

To fix this, there are two ways:

  1. sudo dpkg -i package_file.deb && sudo apt-get -f install
  2. sudo dpkg -i --force-depends package_file.deb

Obviously, the second one is shorter =)

playing around with blender

Feb 17, 2015
Playing around with Blender

Abstract class vs Interface. Cd.

Feb 13, 2015

Just as a small addition to my previous article on abstract classes vs interfaces.

Wneh we declare an interface, we can’t tell how to create an object, implementing that interface. E. g., we can not define even a default constructor.

Thus, when we need to have at least one constructor of a defined signature, we must use abstract classes.

Check it out:

public interface IVector {
    public void Vector(); // something like a default constructror
}

public class Vector2d implements IVector {
    // THIS IS NOT A CONSTRUCTOR!
    @Override
    public void Vector() {
    }
}

and compare it to this:

public abstract class BaseVector {
    public abstract BaseVector() {
    }
}

public class Vector2d extends BaseVector {
    public Vector2d() {
        // now it DOES HAVE a default constructor
        super();
    }
}

Rails tips

Feb 9, 2015

Found these on HabraHabr today. Here are some tricks I found usefull.

Private methods are not actually private

Let us have class:

class Moo
  private

  def self.foo
    puts 'foo'
  end
end

Here, class method foo is not private:

Foo.foo
=> 'foo'

Instance with params

Oftenly there is a need to create a class instance and set it some params (or, maybe, call some methods on it). It's done usually like this:

moo = Moo.new
moo.foo = 'foo'
moo.bar

This can be shortened with the use of `tap` method:

moo = Moo.new.tap { |a| a.foo = 'foo'; a.bar }

Yet, it is more ruby-convenient and ruby-style to do it with the initialization block:

class Moo
  attr_accessor :foo

  def initialize(&block)
    yield self if block_given?
  end

  def bar
    puts "bar!"
  end
end

moo = Moo.new do |a|
  a.foo = 'foo'
  a.bar
end

puts moo.foo

Or even like this:

class Moo
  def initialize(&block)
    instance_eval &block if block_given?
  end

  def moo(val = nil)
    @moo = val unless val.nil?
    @moo
  end

  def bar
    puts "bar!"
  end
end

a = Moo.new do
  moo 'moo~!'
  bar
end

puts a.moo

Code-dependent migrations

When you have your migrations using your code, for example, like this:

class CreateDataVolumes < ActiveRecord::Migration
  def up
    Data::VOLUMES.times do |volume|
      create_table "data_#{volume}" do |t|
        # ...
      end
    end
  end
end

you then have a problem when updating your code. In our example, if you remove the constant Data::VOLUMES, you will have to either manually search for all the usages of this constant, or have a really intelliJent IDE ;)

Rather than using your existing code, stub it and copy-and-paste all migration-dependent code to the stubbing class:

class CreateDataVolumes < ActiveRecord::Migration
  class Data < AR::Base
    VOLUMES
  end

  def up
    Data::VOLUMES.times do |volume|
      # ...
    end
  end
end

Example with constant is rather stupid, whilst you may have some more critical code.