Showing posts with label /0. Show all posts
Showing posts with label /0. Show all posts

2011-09-23

Ruby, oh my increment...

Quote from ruby-doc.org:

9. Ruby has no pre/post increment/decrement operator. For instance, x++ or x-- will fail to parse. More importantly, ++x or --x will do nothing! In fact, they behave as multiple unary prefix operators: -x == ---x == -----x == ...... To increment a number, simply write x += 1. (An explanation for this language design by the author of Ruby can be found at http://www.ruby-talk.org/2710.)

And you are eager to know an explanation for that decision, and you click and you get:

The domain ruby-talk.org may be for sale. Click here for details.

I have been convinced as of now that Ruby is a really good programming language for university studies, but it is yet to become an applicable language in the industry. Will it ever reach that seriousness? It has been infant for a long time and haven't yet reached that level...

2011-08-02

Álmaid nője 1 perce halott / The woman of your dreams died a minute ago

English version follows


A mindenki.hu egy olyan szájt, ahol az emberek feltehetnek és megválaszolhatnak személyes preferenciákra vonatkozó kérdéseket, majd aztán megkereshetik hogy ki mennyire hasonlít hozzájuk vagy különbözik tőlük.

Volt ott egy kérdés: Lefeküdnél álmaid nőjével, úgy hogy már 1 perce halott?

  • A: persze, ha adódik egy alkalom, akkor nem szabad kihagyni.
  • B: ez undorító!!
  • C: lány vagyok
  • D: attól függ, hogyan halt meg

Az eredmények:

  • A: 2%
  • B: 52%
  • C: 33%
  • D: 11%

Ha ezek küzül az eredmények közül megnézzük a férfiakra vonatkozó részt:

  • A: 3%
  • D: 17%

Azaz a férfiak 20%-a [te mondod meg].


English version

The mindenki.hu is a site where people can raise and answer questions about personal preferences and then they can see who is similar and who is different to them.

There was a question: Would you "sleep" with the woman of your dreams if she were dead for 1 minute?

  • A: Of course. If an opportunity raises, it should not be missed.
  • B: This is disgusting.
  • C: I am a woman.
  • D: It depends on the way she died.

The results:

  • A: 2%
  • B: 52%
  • C: 33%
  • D: 11%

Taking the shocking results only on men:

  • A: 3%
  • D: 17%

So 20% of men are [you name it].

2011-05-04

The bad and ugly: Ruby strings

Ruby is a language like Java, everything is reference to object. An assignment does not produce copy of the value, but the copy of the reference. So if you have an a object, and you say b=a then you will have a b object reference pointing to the same place as a.

The naive approach of a string is that if I say a='x12345y'; b=a; b.sub!('234','---'); will result in an a which's value is 'x12345y' and a b which's value is 'x1---5y'.

The Java guys invented the immutable pattern which means that after a string is created it cannot be modified. The sensation of modification comes from the construction of new strings from old ones, like s = s.concat("TEST") where s.concat("TEST") creates a new string which's reference may or may not be stored back at s itself.

But Ruby has weird behavior:

original = '|123|123|123|123|'
s = original
s['123']='TEST'
print(s,"\n")
s = original
s.sub!('123','TEST')
print(s,"\n")
will output
|TEST|123|123|123|
|TEST|TEST|123|123|
You do not know enough - they say, There are immutable objects in ruby too!. I just have to call the freeze method and the object will be immutable. Let's try it.

original = '|123|123|123|123|'
original.freeze # <--- NEW GUY
s = original
s['123']='TEST'
print(s,"\n")
s = original
s.sub!('123','TEST')
print(s,"\n")
will output
stringtest.rb:4:in `[]=': can't modify frozen string (TypeError)
        from stringtest.rb:4

That is just plain wonderful. We are still on the same place: nowhere. What would be the solution? Nothing sane is available. You have to use s = String.new(original) instead of simple assignment. This is a terrible looking pain in the ass solution.

Who the hell knows where was my string declared at the first time? Who knows what will be broken if I change a string I got from somewhere? Who will find the real problem for an error message like File not found: 'TEST'?

2011-03-18

Courier New - rightwards double arrow


<span style='font-family: courier new; font-size: 1.5em; line-height: 80%;'>
|something|&larr;|&rarr;|&lArr;|&rArr;|something|<br />
||||||||||||||||||||||||||||||||||<br />
</span>

|something|←|→|⇐|⇒|something|
||||||||||||||||||||||||||||||||||

The above example demonstrates that the monospace Courier New font is not monospace. You can use this text for testing Notepad, Mozilla Firefox 3.*, PuTTY. The rightwards double arrow is wider than it should be. Under IE8, and Firefox 4.* both double arrows are wider than they should be. (All tested under Win7)

Here I divide by z[AUTOSAVED]

Follow up

Courier New - follow up

2010-05-26