Кад смо били клинци, било је много лакше — цимаш родитеље на сваких пола сата да ти купе сличице, идеш на количину и имаш гомилу људи за мењање. Сада мораш да их купујеш сâм од својих пара, а и друштво за мењање је јако сужено. Да ли формалност замени игру онда када порастемо, или смо порасли када заменимо игру формалностима не знам, али у овом животном добу, са овим знањем програмирања нисам могао да одолим искушењу да израчунам колико ме дупликата очекује на колико купљених сличица
Албум за светско првенство има 639 сличица, а мене је занимало колико треба да купим да бих могао да га попуним, тј. колико дупликата могу да очекујем. Написао сам овај кратак програм у Пајтону баш за то:
#!/usr/bin/env python
from random import uniform
duplikati = 0
for it in range(1,10000):
popunjene = ()
for kupljene in range(1,300):
broj = int(uniform(1, 640))
if broj in popunjene:
duplikati += 1
else:
popunjene += (broj,)
print duplikati/1000.0
Овај програм враћа број дупликата за купљених 300 сличица ако албум има укупно 639 сличица. Број дупликата је 60, што се уклапа са бројем мојих дупликата (62), што ће опет рећи да су сличице прилично униформне (лепа вест за оне који скупљају овај албум)
Ево и листинга колико дупликата можете да очекујете на колико купљених сличица:
| Купљених сличица |
Очекивано дупликата |
| 100 |
7 |
| 200 |
28 |
| 300 |
60 |
| 400 |
102 |
| 500 |
152 |
| 600 |
210 |
| 639 |
234 |
| 700 |
273 |
Ово практично значи да је довољно да купите 639 сличица (тачно колико треба) и да добијена 234 дупликата замените за оне које Вам фале и попунили сте албум
Ето, ово је још један пример како штребери успеју да упропасте све жеље, ишчекивања, наде, размене и тапке, ма све оно лепо у скупљању сличица и убаце математику тамо где јој није место
code, python
Ok, I know this must be funny for most of you, but there are still some desktop Java applications that require updates, e.g. patching (some of us aren’t using web technologies, you know). So, when you have to patch some client application out there, size of your patch matters. If you, on the other hand, have large number of warnings in your source code (let me say, for example 40.000), you can’t just go around your classes and furiously removing warnings since it will create big patch. In that situations, you have three options:
- See no warnings, hear no warnings, speak no warnings – for mediocre, but it actually works;)
- When you commit something, make sure no warnings are commited – e.g. at least clear warnings from classes that will end up in patch anyway – this Eclipse plugin can help
- Be a man! Have balls and clear as much warnings as you can before you get fired!
OK, we’re interested in third solution. If you’re already going to clear as much warnings as possible, it would make sense to first clear warnings from those classes that have them most (remember patch problem). So, if you have 100 classes with 1 warning and 1 class with 100 warnings, you should choose to clear 100 warnings from one class. In ideal world, you wouldn’t mind, but in reality you will not manage to clear all the warnings (unless you really badly want to be fired). So, without further ado, I present you small Eclipse plugin that will show you count of warnings in workspace grouped by Java resource. Created in under 2 hours and then 2 more hours to put it on GitHub (well, what do you want – first time creating GitHub account) and there you have it:
http://stalker314314.github.com/groupwarnings/
You can download plugin directly here and just copy it to plugins/ directory of your Eclipse 3.5+ installation. If you’re lazy enough not to click on my super duper extra site I created on GitHub, then you can see screenshot here (actually, blog post will look much cooler if I put picture here, so I had to make up reason).

Enjoy!
code, eclipse, java, plugin, warning, warnings
There are a lot of examples with canvas tag these days. As if world as a whole is preparing for imminent arrival of HTML5;) I’m not going to talk about canvas element – if you are a designer or developer and you still didn’t heard for it, then you will…soon. Anyway, there were nice post I found on DZone which summarizes some great examples of canvas usage, you can find it here (examples are at the bottom, if you’re not interested in theory). Another great summary post emerged few days after with a lot of cool examples (some of those examples are useless to open in anything other then Chrome, even if you turn TraceMonkey in Firefox). What caught my attention was something I saw a lot earlier with a experiment done a long ago (“long ago” is funny term when speaking in technology context). It’s example of waving image, imitating water reflection. You can see original here. At the end of that page, you can read that that guy won’t add fading effect. This is where I jump in.

I took that code thinking that it will be easy. Long story short, with a complete rewrite, I managed to add fade out opacity. It turned harder then I thought it will be. Principle is the same – draw start image once and then refresh lower part every 25ms to make animation effect. In every frame, we go top down and for every row, new value of offset is calculated based on sin function. Frequency is set so one complete sine period is always shown.
Interesting thing is, I also managed to slow down complete animation by factor of 5-10x. Why is that? Original example uses drawImage() function and draws row-by-row. Because I use alpha channel, I had to resolve to putImageData() function (is this can be done with drawImage()?) and use it for every pixel! Basically, if image is 250×50, original example have 50 drawings (for every row) and I have 12,500 pixel putting in image data. Needless to say, bigger images will hardly be of any value for this effect with this approach.
Once again, you can see it for yourself and look at the code here.
canvas, code, example, html, javascript