Having fun with Blender
Just some WIP. Having fun with Blender 😊
Just some WIP. Having fun with Blender 😊
Often, the command
$ sudo dpkg -i package_file.deb
fails with messages like dependency not satisfied.
There are two ways to fix this:
sudo dpkg -i package_file.deb && sudo apt-get -f installsudo dpkg -i --force-depends package_file.debObviously, the second one is better because it is shorter 😁
Playing around with Blender - rendering, modifiers and some basic texturing and materials.
Found these on HabraHabr today. Here are some tricks I found usefull.
Let us have class:
class Moo
private
def self.foo
puts 'foo'
end
end
Here, class method foo is not private:
Foo.foo
=> 'foo'
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
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.
Lately I was a few times asked a question "what do we need abstract classes for?"
And today I've got one more question, which inspired me to write this.
Let us have a task to write an application, which will perform some simple arithmetic operations on numbers, represented in a different numeric systems.
For example, our program should be able to add numbers in roman, arabic and hexadecimal systems. But later we should be able to add more operations, like division, multiplication and subtraction.
This is where an abstract class comes to help us!
Rather than write an interface Number, which will define the addition operator and then implementing it for each class like RomanNumber and HexadecimalNumber we will better use an abstract class, which will be able to add decimal numbers and will declare abstract method to convert number itself to decimal system.
Take a look:
public interface INumber {
public INumber add(INumber other);
}
public class RomanNumber implements INumber {
public RomanNumber add(INumber other) {
// when `other` is not a RomanNumber
// convert other to RomanNumber
// add `other` to `this`
}
}
public class HexadecimalNumber implements INumber {
public HexadecimalNumber add(INumber other) {
// convert other to HexadecimalNumber and add...
}
}
...and compare it to this:
public abstract class Number {
public abstract Integer toDecimal();
public abstract Number fromDecimal(Integer);
public Number add(Number other) {
returh fromDecimal(this.toDecimal() + other.toDecimal());
}
}
public class RomanNumber extends Number {
public Integer toDecimal() {
// convert `this` to Integer
}
public RomanNumber fromDecimal(Integer n) {
// convert `n` to RomanNumber
}
}
public class HexadecimalNumber extends Number {
public Integer toDecimal() {
// convert `this` to Integer
}
public HexadecimalNumber fromDecimal(Integer n) {
// convert `n` to HexadecimalNumber
}
}
This is how we can create an abstraction: we can add or perform any other arithmetic operations regardless on which numeric system we use!
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();
}
}First time I faced functional programming, I was impressed. Just a bit. That was back in 2012. The second time, I was studying real functional programming at the university. Today was the final test.
We were taught many interesting things about functional programming and lot of things about Haskell. But there were only two lectures and two practices on Erlang. And nothing was told about its distributed programming abilities.
I was a bit disappointed by this fact. So, I turned on my girlfriend's laptop, installed Erlang and created this short intro to distributed programming in Erlang.
This is a 3D model of a robot (called him Robo) which I made in Cinema4D some two and a half years ago.

First of all, set up the Heroku Toolbelt. It is required for all the communications with the server.
The first step of communication with the Heroku servers is logging in. Just run heroku login` and provide your credentials when asked.
Then, you need to create your application or go to the folder where it is located and tune it a bit. Tuning is divided into the following steps:
- tuning the
Gemfile to include the required gems
- fixing the
database.yml configurations
- setting the server to handle static assets correctly
But let's create out application on the Heroku servers first: heroku create [app_name]. If application name is not provided directly - it will be generated automatically.
Now, our application needs two gems to be included for the production gems' group:
group :production do
gem 'pg'
gem 'rails_12factor'
gem 'puma'
end
The third gem is used as a webserver instead of WebRick, which is default (puma is much, much faster!). The second one is required by Heroku. And the first one is used for PostgreSQL connectivity. If you do not wish to use database - skip it and a few next paragraphs.
Then, let's add the database support for our application. It's done simply, running
heroku addons:add heroku-postgresql:hobby-dev
Note: Heroku does not support sqlite since some times. This means you are forced to use either PostgreSQL or no database at all (yes, it's possible! Yet, it works for simple or static web applications only). You may want to change this if you would pay for your account. But this tutorial covers only free side of the Heroku deployment.
Now, there are two ways to set database connection options in Rails:
- set them directly at
config/database.yml file
- set the environment variable
DATABASE_URL
We will cover both cases. For the first one, you will need this section within your database.yml file:
production:
adapter: postgresql
encoding: unicode
pool: 5
url: URL_GOES_HERE
I will show how to get the <URL_GOES_HERE> value in a second. Just keep in mind to replace it with the correct value.
The second option, the environment variable, is set via the Heroku Toolbelt (did I tell you, it is used for almost every deploy operation you will perform?).
First you take the database URL from Heroku server:
heroku config | grep HEROKU_POSTGRESQL
Then, you copy the value you got (it starts with postgres://) and run the following:
heroku config:set DATABASE_URL=URL_GOES_HERE
Now let's set our application to serve static assets. It is handy, because it is the easiest way to send images, stylesheets and javascripts to clients. Go to the config/environments/production.rb and change both config.serve_static_assets and config.assets.compile to true.
But beware: if your app/assets files directory contains files of other extensions than Rails' Sprockets understands - Rails (and Heroku, particularly) will try to precompile them. And that may cause many troubles. You are recommended either to "teach" Sprockets to skip or precompile those files, or you should exclude them from project before deploying to Heroku.
And the last two steps separate us from our goal: first, you should push your project to Heroku' Git repository, it created for you with the application (You do not use Git yet?! How dare you?!..).
Now, if you use database, run migrations with heroku run rake db:migrate.
And, finally, see your application running in the browser: heroku open.
Note: if you are using some assets from the outer web (GoogleFonts, for example) and are seeing your website through the https protocol, you should replace all those assets' URL protocols with https too.
Ohhh... Today I've faced one great trouble: recently I reinstalled my Ubuntu, so I lost all my configurations. And when I tried to connect my Lenovo P780 to debug my Android application, I saw horrible error:
$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
???????????? no permissions
Hey! Where have my smartphone gone?!
Fooling around in the internet, I found two simple steps to fix this:
VendorID and ProductID for your device running lsusb two times (just find the difference line):This will give you two outputs:
$ # disconnected device
$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 064e:d213 Suyin Corp.
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ # connected device (via USB)
$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 064e:d213 Suyin Corp.
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 006: ID 0bb4:0c03 HTC (High Tech Computer Corp.)
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Note the row, which is present in the second output block and is absent in the first one:
Bus 003 Device 006: ID 0bb4:0c03 HTC (High Tech Computer Corp.)
For some reason, my phone is recognized as a HTC, but that does not bother me so much. We will need only two parts of that row:
0bb4:0c03
The 0bb4 is a VendorID and the 0c03 is the ProductID for my phone.
Sudo-edit the file /lib/udev/rules.d/69-libmtp.rules and point it to your device. Add a line like this (without any newlines):
ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0c03", SYMLINK+="libmtp-%k", MODE="0666", GROUP="audio", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
That should enable your system to see the device later.
/etc/udev/rules.d/51-android.rules (you may need to create it) and add one line there:SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct} =="0c03", MODE="0666", GROUP="plugdev"
adbJust restart ADB server and check its device list:
$ adb kill-server
$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
0123456789ABCDEF deviceI have a T-SQL trigger creation script, which runs OK:
CREATE TRIGGER data_modified ON Northwind.dbo.Customers FOR INSERT, UPDATE, DELETE
AS
declare @rows as int;
set @rows = @@ROWCOUNT;
IF @rows = 0
BEGIN
print 'no rows were affected';
return;
end
if exists(select * from inserted)
begin
if exists(select * from deleted)
begin
print 'updated ' + @rows + ' rows';
end
else
begin
print 'inserted ' + @rows + ' rows';
end
end
else
begin
print 'deleted ' + @rows + ' rows';
end
Yet, when I run some INSERT query, I got an error saying:
Msg 245, Level 16, State 1, Procedure data_modified, Line 21
Conversion failed when converting the varchar value 'inserted ' to data type int.
Mysterious, isn't it? Let's dig in, shall we?