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 ;-)

Sunday, July 29, 2018

Yeah! :-) Will see Sam Harris and Yuval Noah Harari :-)

Yeah!
Assuming everything will go well I will go to event "Sam Harris & Yuval Noah Harari - Understanding The Present" in San Francisco in Masonic :-)

I love Yuval Noah Harari books - "Sapiens" and "Homo Deus", I love Sam Harris podcast (to be honest I didn't read any of his books, I started Free Will, and listened to Waking Up).
And this event is near premier of newest book of Yuval Noah Harari :-)

So it should be interesting ;-)


Similar postsbeta
Me in SF Moma...
"Sapiens" is really interesting
I hate 6 o'clock....
When you should stop read a book?
Python yet another hero of SF book Seveneves

Sunday, July 15, 2018

Programmers love to over complicate...

Did you notice that programming use to be easier?
10 or 20 years ago you were spending more time writing code than now?

It is true for me.

10 years ago I was coding at work in Java and JavaScript. We were using MyEclipse and SVN without branches.

My day was something like this:
- update sources from SVN on trunk,
- look for info about stories,
- code:
  - write code,
  - run code,
  - update sources from SVN on trunk,
  - commit code if it was ready in given part,
- update sources from SVN on trunk,
- commit code (still if it was ready)

This was easy.
We had in each moment almost the most current source version on our machines.
We didn't have any CI tooling, but each time you updated and tried to build, and something was failing you were sharing with this and was trying to fix problem.
Without special monitors showing CI results.

Each week we had manual weekly build (written in ANT!), and QAs were testing this version.

It was working.
It was fast.
It was stable.


How it looks usually now?

You are coding with Java and JavaScript + ReactJS + Webpack + Gradle/Maven + Nexus + whatever else + GIT/HG with tons of branches.

Your day looks something like this:
- update from master (or current release master),
- resolve conflicts,
- commit,
- test on your branch (but it may take too much time),
- push to your branch,
- wait for tests,
- in case of failing investigate,
- look for info about stories,
- code,
   - write code,
   - wait till it compile,
   - run code and some tests,
   - commit code
   - push code,
   - wait for tests,
   - look why some UI tests are failing,
   - run those tests again,
   - and again,
- create pull request,
- notice that in the meantime somebody else commited to master code he or she was cooking by last 5 days on own branch,
- merge,
- commit,
- squash commits (because somebody will complain that you have multiple commits),
- push,
- LINT or PMD or Sonar complaining,
- yeah, not in your code, but you needed to change some legacy code in class with 6 kLOCs....,
- hack Lint/PMD/Sonar,
- commit,
- wait for tests,
- CI is slow,
- create ticket for restarting CI,
- you need to stop because you have one of Scrum meetings,
- CI works again!!!!,
- tests are failing,
- again UX tests

I may little exaggerate, but from my perspective it too often looks like this (in many companies).

It seems that developers want to make things more complicated.
Or maybe it works in this way that some people have good ideas and intentions,  but those latter are half baked, or introduced only because...

In several companies I saw problem with Maven.
Maven was in HQ and in other sites it was too slow.
So it was always decision, big managerial action "we are doing our own Maven repo which will sync-up with master in HQ!".
This was done.
After some short time people started to realize that they don't see most recent SNAPSHOTs, but after tinkering with /etc/hosts and making repo name resolving to IP of this Maven repo in HQ everything was starting to work.
From this time, in 1st or 2nd day each of newly employed was instructed to do changes in /etc/hosts....

Why? Because everyone is able to read on StackOverflow or something similar about setuping copies of Maven, but configuration is not so trivial....

(I'm still amazed that in one of companies they were extensively using ActiveMQ, and tried even to configure backups... but after trying they realized that it was much more complicated to configure and maintain so they simply killed backup ActiveMQ server without even changing apps configuration....)

Similar postsbeta
Which language is fastest? ;-)
Google Buzz - let's mark some comments as not spam ;-) or how to unhide "hidden" comments ;-)
How to get negative number from size() in LinkedList in Java? ;-)
What sux in G1?
Calculation of SSD life time in EEE PC

Monday, July 9, 2018

When you should stop read a book?

I like to read, and from more than year I try to spend daily at least 45 minutes reading some popular science or similar book.

But sometimes I don't like the book.

And I'm looking for some "formula" to decide if I should stop to read or not.

I already spend this time, and I'm not able to recoup it, still I may try to rescue rest of time I would spent reading....

So maybe something like:

expected_value = value_till_now/time_spent

This will let me estimate how much I may gain.
Interesting fact, because at the beginning I have some "value" already at least from this that reading on its own improves vocabulary and so on, at the beginning expected_value is almost infinite ;-)

Now is problem of this what should be expected_value.
I would propose something radical, expected value should be at least equal to average value from previously read books.
Let even be nicer for book, lets say it should be at least half of value of average book.

So formula to make decision should be:

stop_reading = value_till_now/time_spent < 0.5*average_value_of_book

It seems also that using this formula will cause that reading more books will means stoping earlier with bad books ;-)

And thanks to this I avoided in last year or so reading books like:
The Singularity Is Near by Ray Kurzweil - topic was interesting, but at least Polish translation of this book was so badly written that I didn't wanted to read it,
Getting Things Done by David Allen - how many times the same may be written? Or maybe this was again Polish translation,
The 4-Hour Workweek by Tim Ferriss - I admire Tim Ferriss for creating really good idea of making business - let others do it - it brillant idea, and books created in such way like Tools of Titans, and Mentors Tribe are quiet interesting, this one is simply boring.
Capital in the Twenty-First Century by Thomas Piketty - main idea of book is worth noting, but it isn't easy read, and one simply don't have way to verify data provided, so instead of reading this one book I would prefer reading some summary of it (from this what I heard the same is true about Marx's Capital ;-))

Similar postsbeta
Python yet another hero of SF book Seveneves
How to detect clickbaits?
Recursion is evil ;-)
It's alive... still ;-)
How to get negative number from size() in LinkedList in Java? ;-)

Sunday, July 1, 2018

Blindfold programming

Some time ago I read this article, and started to play with idea of Blindfold programming.

What this whole Blindfold Programming is about?

It is about trying to write code in your head, without any screen, keyboard, paper or whiteboard. Only in head.

Why?

To exercise :-)
Not used ability usually stops to work...

And in my case I noticed several years ago what becoming more senior in software engineering in my case means writing less code... but still coding is very important part of this job, so it is important to practice :-)

Additionally it seems that it helps with chunking. and naturally leads to dividing problem to smaller subproblems.

This part is important, because human brain doesn't have too much space in short memory. One is able to keep in the same time ~4 things in memory and focus.

So from some time I'm going to LeetCode easy problems and I'm trying to write whole solution in my head. Sometimes I'm touching also medium problems in the same way.

Next, sometimes I'm writing code on whiteboard or with pencile on my iPad Pro, but usually I simply put whole code from my head to LeetCode editor and I'm checking if my solution works ;-)

And after several months of doing it I think I can see some improvements ;-)




Similar postsbeta
Coding without IDE
Whiteboard
Coursera courses - worth of doing?
My way to (parital) vegetarianism
Programmers love to over complicate...

Saturday, June 23, 2018

Decluttering of phone :-)

Last Friday or Thursday I looked on my phone and realized that I have too many apps on start screen.
At time it looked somehow like this:


Icons and Folders were set in slightly different way (once o week I'm reorganizing some apps, like WhatsApp, Chrome, Inbox to make it more difficult to start those "on autopilot"), but number was exactly the same.

Now I have still a lot of icons, but number is smaller:


Still I have place to improvement, but I'm moving in right direction ;-)


Similar postsbeta
Biggest problem with WhatsApp, Telegram, Allo, Duo and so on
OpenOffice.org2GoogleDocs 0.9 :-)
Avoiding null's -> becoming better programmer ;-)
My way to (parital) vegetarianism
Know country behind apps on your phone....

Sunday, March 25, 2018

My Clipboard says that I'm a programmer ;-)

Interesting...
Several days ago I started to use CopyQ (so Clipboard Manager which lets you return to things earlier in clipboard - works on Linux, macOS/OSX and as I heard also on Windows).

And now I counted how many pieces of code I have in latest 100 positions...

And it seems that it was 40 :-)

So 40% of all things in my clipboard are fragments of code ;-)

Someone may say that this means that I must copy/paste a lot of code ;-)
But no, this was my code :-)

Some of those were tests for DCEVM which I first were putting in other test classes, and latter moved to new one (it was easier to copy them than use move), pieces of code of DCEVM, and some programming tasks I was moving to other project (to have list of solutions for people checking first stage of our interview process)).

So, I must say it - I'm a programmer ;-)

Similar postsbeta
Using Pythonista to Journaling ;-)
Coding without IDE
Coding time means often waiting/reading time ;-)
It seems that meditation helps ;-)
Avoiding null's -> becoming better programmer ;-)

Sunday, January 14, 2018

Biggest problem with WhatsApp, Telegram, Allo, Duo and so on

To be honest I was trying not to use any of "new wave" communicators as long as it was possible.

Main reason why I don't like those is the fact that your account is assigned to phone number.
This is strange, and not cool.

First of all you may use those only on mobile devices which has SIM card and phone number...
So if your tablet don't have such you will not use it...
Second if you change your phone number you have next set of problems...
Especially if you are on trip, and change SIM card to local operator to have Internet in your phone.....

So I still prefer Hangouts over those. I may use Hangouts on phone, tablet and PC without any difficult hassle...

I wonder when those will "invent" accounts instead of phone numbers......


Similar postsbeta
Mobile generation..
Decluttering of phone :-)
What sux in G1?
Know country behind apps on your phone....
Yep, tablet may replace computer in most of cases...

Sunday, December 31, 2017

Using Pythonista to Journaling ;-)

I'm using my iPad Pro to journaling.
Each day I'm trying to write what I done, what I'm happy for, what I learn and so on...

I like also book The Martian ;-)
And each entry of Mark Watney in The Martian starts from date (in Sols).
It would not work for me, but number of days from my birthday? ;-)

So I wrote small Python script which I run on Pythonista.

import time
import clipboard
import webbrowser
import console
import util

#if you want to use it put below your birthdate :-)
birthday=time.strptime("1900-01-11 7:45","%Y-%m-%d %H:%M")
now=time.time()
time_from_birth=now-time.mktime(birthday)
days_from_birth=round(time_from_birth/60/60/24,5)


today=time.strftime("%d-%m-%Y")
clipboard.set(today+"\nDay:"+str(days_from_birth))

print("Done")

util.startBundle("pro.writer")

Which is using next script (util.py):

from objc_util import *
from ctypes import *
import sys


def startBundle(bundleId):
libobjc=CDLL('/usr/lib/libobjc.dylib')
LSApplicationWorkspace=ObjCClass('LSApplicationWorkspace')
workspace=LSApplicationWorkspace.defaultWorkspace()
workspace.openApplicationWithBundleID(bundleId)

So first script is calculating number of days from my birthday.
For now it is 14531.84021 days ;-)

Next this with some additional text is copied to clipboard.

Next using method startBundle from util module it starts iA Writer :-)

My only job is to do CMD-V (on keyboard of my iPad Pro) and start to write about my day :-)

This startBundle may start any of program on iPad, only thing which we need to know is an id of application (here is instruction how to get this ID for known program).

I would really love to be able to instruct iA Writer to create new file and paste my text at beginning of it... but as for now I'm not able to do so ;-)


Similar postsbeta
Android vs iOS
OOo2GD 1.5.1 Birthday Edition ;-)
Worflow - my biggest disapotiment of iOS
Watchdog....
How to detect clickbaits?

Monday, December 18, 2017

Know country behind apps on your phone....

Smartphone knows a lot about its owner.
Knows where this person is.
Knows with whom this person talk.
Can listen. Can make photos.

So, it is better if you know who can know this stuff about you.

I may be little paranoid, but lets be honest, I don't trust companies from countries like Russia or China...

If I need to choose being tracked by NSA or CIA, or by FSB, I will always choose NSA and CIA.
Of course if I can I would like to be sure that any of those track me ;-)

So I looked on apps on my phone.
Among 94 my results looks like this (yep, I counted Google as country ;-))

Countrycount
Google47
USA13
Poland10
UK5
China4
my own4
Netherlands2
Serbia2
Australia1
Czech Republic1
Germany1
Japan1
South Korea1
unknown1
was Google1

Happily nothing from Russia ;-)
Sadly some apps from China.
One is Kasa from TP-Link, second is Motoconnect from Motorola. So I hope that I may trust those.
CamScanner is little bit tricky. I'm not scanning top secret documents, but this makes me little bit worried.
Wifi Analyzer too...
I have one app which I don't know from where it is. This is Barcode scanner, don't know why but name of developer sounds like China. Happily this is open source.

But looking on this list I know almost for sure that I will not install Telegram. Sorry...
Will rather go in direction of WhatsApp... but I'm not happy with that.

To be honest I spend near one hour checking from where is given developer.
And in most cases I was checking both info on Google Play, and for whom domain is registered.


Similar postsbeta
CallLoger ;-) Invigilate yourself ;-)
Bloggerid cannot post images....
It's alive... still ;-)
Borders, immigrants and so on
Vacation in progress ;-)

Sunday, November 26, 2017

Coursers courses debugging ;-)

I really like Coursera, and set of courses about deep learning (from deeplearning.ai), but I must make note to myself:
"DO NOT attend new (fresh) courses before those will not stabilize"

Why?
Today I finished 4th (as for now last, 5th will be available "soon") course in deeplearning.ai path.
It was quiet interesting, about convolutional neural networks.
But almost in each of assignments some bugs were present.

In last set of assignments those were biggest (things like this that first task is described as second, and second as first, or this that to do second task (described as first) you need to break your code, and in first task (described as second) despite this that during creation of functions you are using TensorFlow, latter example code is trying to pass there numpy objects....

I need simply wait some time, till those courses will not be debugged :-)


Similar postsbeta
Coursera courses - worth of doing?
Yep, tablet may replace computer in most of cases...
How to detect clickbaits?
RE
Coding time means often waiting/reading time ;-)

Monday, November 6, 2017

Worflow - my biggest disapotiment of iOS

Long befor having anything with iOS I heard about Worflow.
Wonderful app which was able to automate a lot of stuff on iOS.

I was looking for something similar to this what I imagnied on Android, and each of those tools was disapointing...

So finally when I got iPad Pro, I installed Workflow.

It was nice, shiny.... and completly useless...*

It seems that Workflow is build for people who need to automate some trivial stuff, and are complety OK with whole hassle with clicking, opening windows and so on.

This is really powerfull tool.
It is very usefull tool.
But not for me, and users like me.

Problem is not in Workflow but in my needs. I needed something what would help me automate some things where the best solution would be to write app, or in very untypical cases (like copying files from iCloud to Google Drive).
In some of those cases I already have apps created to do a job.
So automation given to me by this powerfull tool is in my cases not needed.

And because of this tool which looked for me so promising, is one of rarest started apps on my iPad...
To be honest I’m running it from time to time to check if maybe somehow I will be able to use it... but as for now answer was always „no” ;-)

* - very important addition here - it was useless for me.


Similar postsbeta
Yep, tablet may replace computer in most of cases...
Android vs iOS
My road to automation ;-)
Throw out 1 thing each day
OOo2GD 1.5.1 Birthday Edition ;-)

Saturday, November 4, 2017

Keyboard + tablet = not great idea ;-)


Now I'm sure of something what I found out years ago, but wasn't sure.

Years ago I had one of first quiet good tablets with Android.
It was EEE Pad Transformer from Asus.

I used it a lot, but when I was buying it I didn't bought keyboard.
Latter I bought it, and in the blink I stopped to use it...
It was too complicated to remove keyboard, so I wasn't removing keyboard and wasn't using tablet.

So when I was buying iPad Pro with keyboard I was little bit afraid.
But it was working.

So I decided that it may be good idea to buy keyboard for my Pixel C.

So being in US I bought some used keyboard for Pixel C.

And again, it caused that I started to treat Pixel C differently....
Maybe not using it less, but less enthusiastically ;-)

So I put Pixel C again to its cover, it works better.
I still may use keyboard sometimes, but ratter not ;-)

So why with iPad Pro keyboard wasn't so problematic?
I think 2 things, first this keyboard is really easy to work with, its part of cover, so I may use it as cover or as keyboard.
Second thing is that from this what I can say I'm using iPad Pro more like some kind of computer, so much more often in landscape than portrait mode. So keyboard makes perfect sense for it :-)


Similar postsbeta
Yep, tablet may replace computer in most of cases...
Android vs iOS
2016...
2+ years without a car
Blindfold programming

Sunday, October 8, 2017

Pixelbook

A lot of people over internet ask why Google created Pixelbook.
And says on the same breath that it for sure cannot compete with MacBook or even PC.

I think that it was never intention.

It should compete with iPad Pro.

And because it have true web browser, and ability to run Android apps it may be even better than iPad Pro...

Only problem is, that nobody will buy it :-(

posted from Bloggeroid




Similar postsbeta
Yep, tablet may replace computer in most of cases...
Mobile generation..
Keyboard + tablet = not great idea ;-)
Whiteboard
Amazon Prime Video suxx