Tuesday, January 23, 2024

How to get negative number from size() in LinkedList in Java? ;-)

Yep, didn't wrote long time ;-)

Today will be "translation" of my post in Polish, but it is so fun that I decided to go with it ;-)

In short I wanted to break LinkedList in Java ;-)

I wanted to move LinkedList to state in which even when it was used in proper way it would stop to work for some stuff, or would return stupid answers. 

We will exploit "problem" in design of List in Java, its size is kept in int and may be up to Integer.MAX_VALUE. In case of implementations based on arrays this is quiet valid assumption. To be honest in case of computers used when Java Collections were created this was good assumption, but we are living 25 years into future so our computers are now 5-6k times faster, and have 5-8k times memory (In 1998 I had still 4 or 8 MB of RAM and was planning to upgrade to 64 MB of RAM, now I have in laptop which is 5 years old 32 GB of RAM ;-)).

So, idea is to have piece of code like:

var list = new LinkedList<Integer>();
doMagic(list);
System.out.println(list.size()); // return negative number!!!

Where doMagic looks like:

static void doMagic(LinkedList<Integer> l) {
for (var i=0L; i<Integer.MAX_VALUE+1000L; i++) {
l.add(Integer.valueOf(0));
}
}
So as we can see we are simply adding more than Integer.MAX_VALUE objects to our LinkedList.
By some time I wasn't able to run it on my machine because I was each time setting max heap size under 32 GB... and this would take 96-120 GB or so ;-) 
But it seems that you are able to setup Xmx to number bigger than your memory (at least on macOS) and after setting it to 150 GB I got 
-2147482649 from calling list.size(), and when I tried to execute:
var count = 0L;
for (var n:list) {
count++;
}

And I got also IndexOfOutBoundException with index 0 ;-) (it is because when iterator is created there is rangeCheck for 0, and when 0 is greater or equal to 0, it is still bigger than size of -2147482649 ;-)


Similar postsbeta
How many i 1+1 in Java? ;-)
Recursion is evil ;-)
Google Buzz - let's mark some comments as not spam ;-) or how to unhide "hidden" comments ;-)
Calculation of SSD life time in EEE PC
Portable code smells list ;-)

Sunday, March 31, 2019

DST may not be so stupid as it looks...

European Commission decided that Europe as a whole will end with moving clocks twice a year.
It seems reasonable, but...
If whole Europe will stay in given time offsets and will decide to use Summer Time, this means that when in Poland in Kraków on beginning of year we will have sunrise about 8:30, in Spain in Vigo it will be about 10:00....
Now for Kraków in Poland thanks to moving clocks it is about 7:30 and in Vigo about 9:00....

OK, so maybe Europe should move to Winter Time, so "standard time without DST".
It would mean that in Kraków in the middle of July sun would rise at 3:30....

DST/moving clocks lets now to keep the same time zone in many countries in EU, question is if it will be true after we will resign from it? ;-)


Similar postsbeta
I hate 6 o'clock....
Correlation between traffic and time spent at work ;-)
Really first snow ;-)
Why people are so afraid of terrorists?
CallLoger ;-) Invigilate yourself ;-)

Sunday, March 24, 2019

Coding without IDE

I'm observing strange phenomena.
More and more developers when asked to write code on whiteboard or on computer without IDE with code assist is almost unable to do so.

I'm not saying that this is bad thing. It is strange for me, but I'm not able to say if it is bad.
In normal circumstances they have access to IDE which will help, so in theory they are able to use memory and brain power to code on higher level instead of remembering APIs.

My own way to train algorithms is to write code on whiteboard, and latter rewriting it to online judge system (which usually doesn't have code assist) and checking how it works, and if code does not compile it means that I made mistake and need to work on this.
But I'm not exactly sure if it is good way ;-)

From other side, if dev is able to write code on whiteboard he or she is usually better....

My working theory is that better short term memory and higher IQ means that someone may be better at programming, and problems with writing code on whiteboard are showing that given person may have some problems in those areas.


Similar postsbeta
Blindfold programming
Whiteboard
Power of doodling ;-)
Calculation of SSD life time in EEE PC
Programmers love to over complicate...

Sunday, January 27, 2019

Bloggerid cannot post images....

Title is for catching Google searches ;-)
But it also describes current behavior of Bloggeroid.

From last week it stoped to publish images. Main, and only cause is fact that Google disabled Picasa API which was used by Bloggeroid.

As far as I can say from looking into Google Photos API it cannot be used as alternative, because it doesn't let embed images in pages.
Or at least I didn't find any info how to do it.

As I can see increase of number of problems with publishing went up 18 times.
But now stabilised at 3.5 times more than before disabling Picasa API.

I'm not sure if I should do anything. I may disable app in Google Play Store, or remove possibility to publish images, or find some other solution.
From users perspective last one would be the best, but because I'm not posting too much pictures to any of my blogs (mostly because I prefer to blog from computer ;-)) user number 1 isn't pushing too much...

So for now I will not do anything.

In general this shows two problems:
1) Bloggeroid is a mean to publish posts to Blogger, so it is fully depend on another product, any disruption in this product means problems for app,
2) in case of free apps, or apps which were sold for price in given moment authors don't have too many incentives to keep apps running.

Lessons from it (for me):
1) do not build products depending on other products,
2) if you are using mobile app use app from owner of service,
3) abo is better than one time price.


Similar postsbeta
AWS vs Azure vs Google Cloud
Bloggeroid 1.0 :-)
Know country behind apps on your phone....
CallLoger ;-) Invigilate yourself ;-)
It's alive... still ;-)

Monday, December 10, 2018

I hate 6 o'clock....

I never had New Year resolutions, but in 2019 I will try to wake up at 9 ;-)
Mainly because of this that by last 2 months or so I need to wake up at 6....


I hate this...
But it can be wven worse sometimes I need to wake up at 5:30, and at 6:11 I'm already on streets of San Francisco ;-)



So I promise myself, when I will be back in Poland I will try to wake up at 9 or latter, as often, as it is possible ;-)

One plus of waking up so early is that I'm in office before 7 (when I wake up at 5:30), or 7:20 when I wake up at 6:00.
Thanks to this I have about an hour of time without any interruptions.

But usually I prefer to have this in the evening ;-)


Similar postsbeta
It seems that meditation helps ;-)
Correlation between traffic and time spent at work ;-)
DST may not be so stupid as it looks...
Yeah! :-) Will see Sam Harris and Yuval Noah Harari :-)
2016...

Monday, November 26, 2018

Me in SF Moma...

Today I was in SF MOMA (San Francisco Museum of Modern Art)...
I'm living nearby so I though that this may be good idea to visit ;-)

And I'm proud to say that I don't understand anything ;-)

But I really liked Sol LeWitt creations, but I was trying to find probably too much in those.
I spend about 10 minutes in room with his Wall Drawing 273 and I still didn't grasp rules...
Because for me some of his works seems like some kind of puzzle ;-)


I saw Mark Rothko art and I don't get it ;-)
But thats cool that it is presented and some people are able to read it :-)

Here things I liked the most :-)












Similar postsbeta
Alexa... What to do with her?
Python yet another hero of SF book Seveneves
Yeah! :-) Will see Sam Harris and Yuval Noah Harari :-)
2016...
Happy Darwin's Day!

Friday, August 10, 2018

Wind down is cool :-)

On my phones I have already Android 9, and Digital Wellbeing installed.


And I really like Well down feature.
You can see its effects on picture below:


Between 23:00, and 7:00 my screen display everything in grayscale :-)

Assumption behind this is that in such case screen is not so interesting, so you are not drawn so much to it when you should prepare to sleep, or sleep.
Additionally it make most of apps simply ugly, and it is a hope that you will avoid those apps ;-)

As far as now I like it :-)


Similar postsbeta
Roomba friendly furniture...
RE
It seems that meditation helps ;-)
Bloggeroid 1.0 :-)
Correlation between traffic and time spent at work ;-)