Truncate string when it is too long

I have two strings:

short_string = "hello world"
long_string = "this is a very long long long .... string" # suppose more than 10000 chars

I want to change the default behavior of print to:

puts short_string
# => "hello world"
puts long_string
# => "this is a very long long....."

The long_string is only partially printed. I tried to change String#to_s, but it didn’t work. Does anyone know how to do it like this?

read more

String concatenation without ‘+’ operator

I was playing with python and I realized we don’t need to use ‘+’ operator to concatenate strings unless it is used directly.

For example:

string1 = 'Hello'   'World'  #1 works fine
string2 = 'Hello' + 'World'  #2 also works fine

string3 = 'Hello'
string4 = 'World'
string5 = string3   string4  #3 causes syntax error
string6 = string3 + string4  #4 works fine

Now I have two questions:

  1. Why statement 3 does not work while statement 1 does?
  2. Is there any technical difference such as calculation speed etc. between statement 1 and 2?

read more

Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not execute statement

What the reason of my mistake?
I have to entities. Their relation is many to many.


@Entity(name = "prepod")
public class Prepod {

    private Long id;

    List<Student> students = new ArrayList<Student>();

    public List<Student> getStudents() {
        return students;

    public void setStudents(List<Student> students) {
        this.students = students;

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    public Long getId() {
        return id;

    public void setId(Long i) {
        id = i;

read more